[R-sig-Geo] Expected behaviour of over() at polygon corners (sp package)
Paul Galpern
pgalpern at gmail.com
Thu Mar 21 15:00:15 CET 2013
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
More information about the R-sig-Geo
mailing list