Dear R-sig-geo:

I am not sure whether the following is the intended behaviour of sp::over() in this situation. When a point falls on the mutual corner of three square polygons over() returns NA. One of these polygons contains a hole in which the other two are embedded.

The following toy example uses SpatialPolygons derived from a raster created with raster::rasterToPolygons(..., dissolve=TRUE) as this is the process I am using to create the polygons, and the result I am getting may be an artefact of this.

## Create example raster
library(raster)
rasCells <- matrix(c(1, 1, 2, 2, 1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1), 4, 4)
ras <- raster(rasCells)
## Convert to SpatialPolygons
rasPoly <- rasterToPolygons(ras, dissolve=TRUE)

## Spatial overlay
## over() returns NA
pt <- cbind(0.5, 0.5)
over(SpatialPoints(pt), rasPoly)

## The offending point falls at the mutual corner of three polygons
plot(ras)
points(pt)

I recognize that there are other ways around this. Using raster::extract() is equivalent, and I can jitter the point, for example. But wondering what the intended behaviour of over() is, here.

Thanks--as always--to the creators of these fine tools,
Paul

--
Paul Galpern
Natural Resources Institute
70 Dysart Road
University of Manitoba
Winnipeg, Manitoba, Canada R3T 2M6
http://borealscape.ca

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to