[R-sig-Geo] Looping over spatial data
Roger Bivand
Roger.Bivand at nhh.no
Thu Sep 10 18:23:09 CEST 2009
On Thu, 10 Sep 2009, Jason Bryer wrote:
> Sorry for what may be a simple question. I am having an issue looping over
> spatial data. Here is the code:
>
> usa.map = read.shape(file.choose()) #Shape file of the US, 51 records
There is a reason for read.shape() saying that it is deprecated. Please
use classes defined in the sp package, and methods to read them, here
possiblt readShapeSpatial() in maptools.
>
> pt = data.frame(x=-73.793, y=42.857)
If pt is a SpatialPoints object, you just use an overlay() method.
> shapes = Map2poly(usa.map)
> shape = shapes[[35]] #This is New York
>
> pip(pt, shape) #This works, returns the point as I expect since it is within
> NY
>
> for(i in 1:length(shapes)) {
> shape = shapes[[i]]
> pip(pt, shape)
> #This is where the error occurs
> }
>
> This is the error I get:
>
> Error in inout(pt, shape) : NA/NaN/Inf in foreign function call (arg 4).
>
Almost certainly your assumption that the shape is a single ring is not
met for some i, leading the splancs functions you are using to fail. Use
sp classes, they are there to help.
Roger
> Thanks for any help.
>
> -Jason
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
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