[R-sig-Geo] Map2Poly: Error message
Roger.Bivand at nhh.no
Thu Aug 3 19:00:36 CEST 2006
On Thu, 3 Aug 2006, Graham Cookson wrote:
> Dear List,
> I hope you can help me with this problem.
> I am attempting to form an adjacency matrix and I'm trying to get my
> shapefile into R. However, I get error messages at the initial stages.
> I used the following code:
> The map object is created fine and it finds all 8490 polygons, but the
> Map2poly command generates the following error message:
> Error in if (res[] > 0) return(as.integer(-1)) else return(as.integer(1))
> I have searched the web and the R Help Archives but can't find examples of
> this problem occurring before.
> The shapefile I am using was created in ArcView by merging the separate
> Wales and England shapefiles available from UK Borders at Edina.ac.uk
> I am using R2.2.0 on an Apple iBook G4 running Mac OS X 10.3.9
> I hope that this isn't a really stupid question
No, a relevant question on the right list with lots of helpful details.
The error is thrown in Map2poly -> .get.polylist -> .ringDirxy, where the
two last functions are internal ones, and the last one, with the error, is
trying to determine the ring direction.
This is implemented differently in the readShapePoly() function also in
maptools, which imports a shapefile into a SpatialPolygonsDataFrame. From
there, you just coerce to SpatialPolygons to run poly2nb() -
poly2nb(as(SPDF, "SpatialPolygons")) should work. Could you please try
that route first, and let us know if it works?
If you'd prefer not to use the SpatialPolygonsDataFrame class, then we'll
need to debug the older code, and then access to your shapefile (or a
subset displaying the same symptoms) will be needed just for testing. In
any case the output of sessionInfo() and of traceback() immediately after
the error, together with the full error message would be very useful.
Setting quiet=FALSE in the Map2poly() call may also show that some
polygons are getting their ring directions reversed.
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