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

Edzer Pebesma edzer.pebesma at uni-muenster.de
Thu Jan 15 12:07:14 CET 2009



David Wahlund wrote:
> 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.
>   
There is one except that it is y="SpatialPolygons" rather than 
"SpatialPolygon":

 > showMethods(overlay)
Function: overlay (package sp)
x="SpatialGridDataFrame", y="SpatialPoints"
x="SpatialGrid", y="SpatialPoints"
x="SpatialPixelsDataFrame", y="SpatialPoints"
x="SpatialPixelsDataFrame", y="SpatialPolygons"
    (inherited from: x="SpatialPointsDataFrame", y="SpatialPolygons")
x="SpatialPixels", y="SpatialPoints"
x="SpatialPointsDataFrame", y="SpatialPolygons"
x="SpatialPoints", y="SpatialPolygons"
x="SpatialPolygons", y="SpatialPoints"

(note that it's only visible this way only after you've used it)
> 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. 
This is wrong; where exactly does it say so? Documentation is a bit 
scattered sometimes.

> 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?
>   
Do you manage to get the pixels you want from the indexes returned?
--
Edzer
> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>   

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de/
http://www.springer.com/978-0-387-78170-9 e.pebesma at wwu.de




More information about the R-sig-Geo mailing list