gis:raster-sample
gis:raster-sample RasterDataset sample-location
Reports the value of the given raster over the given location. The location may be any of the following:
- A list of length 2, which is taken to represent a point in netlogo space (
[xcor ycor]
) of the sort reported by location-of Vertex. The raster dataset is sampled at the point of that location. - A list of length 4, which is taken to represent an envelope in GIS space, of the sort reported by envelope-of. The raster dataset is sampled over the area of that envelope.
- A patch, in which case the raster dataset is sampled over the area of the patch.
- A turtle, in which case the raster dataset is sampled at the location of that turtle.
- A Vertex, in which case the raster dataset is sampled at the location of that Vertex.
If the requested location is outside the area covered by the raster dataset, this primitive reports the special value representing “not a number”, which is printed by NetLogo as “NaN”. Using the special “not a number” value as an argument to primitives that expect a number may cause an error, but you can test the value reported by this primitive to filter out “not a number” values. A value that is not a number will be neither less than nor greater than a number value, so you can detect “not a number” values using the following:
let value gis:raster-sample dataset turtle 0
; set color to blue if value is a number, red if value is "not a number"
ifelse (value <= 0) or (value >= 0)
[ set color blue ]
[ set color red ]
If the requested location is a point, the sample is always computed using the method set by set-sampling-method. If the requested location is an area (i.e., an envelope or patch), the sample is computed by taking the average of all raster cells covered by the requested area.
Take me to the full GIS Extension Dictionary