[R-sig-Geo] Problem with overlay(x="SpatialGridDataFrame", y="SpatialPoints")

Roger Bivand Roger.Bivand at nhh.no
Tue Mar 31 14:16:08 CEST 2009


On Tue, 31 Mar 2009, Rainer M Krug wrote:

> Hi
>
> I want to get the data from a grid at locations based in a point vector
> file. I am using the following code, and I get the error below.

Rainer:

The quick workaround is to read the shapefile with readOGR(), which does 
not give the coordinates matrix row names, so the failing test for 
matching with data frame row names is skipped. I have fixed overlay() 
to suit in sp's CVS on R-spatial on sourceforge - could you try it, 
please? The following will show if it is fixed:

library(sp)
data(meuse)
coordinates(meuse) <- c("x", "y")
data(meuse.grid)
coordinates(meuse.grid) <- c("x", "y")
gridded(meuse.grid) <- TRUE
fullgrid(meuse.grid) <- TRUE
zz <- overlay(meuse.grid, meuse)
library(rgdal)
writeOGR(meuse, "/tmp", "meuse", driver="ESRI Shapefile")
meuse <- readOGR("/tmp", "meuse")
zz <- overlay(meuse.grid, meuse)
library(maptools)
meuse <- readShapePoints("/tmp/meuse.shp")
zz <- overlay(meuse.grid, meuse)

Hope this helps,

Roger


>
> Could anybody help to solve this?
>
> Thanks
>
> Rainer
>
>
>> lastFire <- readAsciiGrid("fire_last_2006.asc")
>> biota <- readShapePoints("Biota")
>> overlay(lastFire, biota)
> Error in SpatialPointsDataFrame(cc, x at data[idx, , drop = FALSE], proj4string
> = CRS(proj4string(x))) :
>  row.names of data and coords do not match
>>
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list