[R-sig-Geo] Confused by overlay(x = "SpatialPixelsDataFrame", y = "SpatialPoints")

David Wahlund david.wahlund at gmail.com
Wed Jan 14 14:41:08 CET 2009


Hi,
trying to extract by mask using sp package.
Was surprised that I couldn't find 'overlay(x =
"SpatialPixelsDataFrame", y = "SpatialPolygon")' to extract pixels
within a polygon.
So instead I'm using
ascPoints <- SpatialPoints(coordinates(asc))
ascPointsHR <- ascPoints[!is.na(overlay(ascPoints,hr))]

Now when I try to use overlay using 'ascPointsHR' on 'asc' I get a
strange return. sp docs says it 'returns grid values x at spatial
point locations
y' which I interpret as me getting the raster values. Instead I seem
to be getting the index values of the pixels or something. The raster
is float, as seen from the summary below. But the return from
overlay() is ordered integer.

Am I missing something?

Thank you
David Wahlund

> summary(asc)
Object of class SpatialPixelsDataFrame
Coordinates:
      min     max
x 1592482 1622382
y 7121568 7144668
Is projected: NA
proj4string : [NA]
Number of points: 1105104
Grid attributes:
  cellcentre.offset cellsize cells.dim
x           1592494       25      1196
y           7121580       25       924
Data attributes:
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
0.000e+00 0.000e+00 0.000e+00 1.448e-09 4.750e-11 4.954e-08
> summary(ascPointsHR)
Object of class SpatialPoints
Coordinates:
      min     max
x 1599144 1617094
y 7127130 7138680
Is projected: NA
proj4string : [NA]
Number of points: 198320
> ascHR <- overlay(asc,ascPointsHR)
> summary(ascHR)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
 266300  464700  556800  552900  646600  818600




More information about the R-sig-Geo mailing list