ring not closed - readShapePoly - read.shape - maptools
A new package, spsurvey, has function to read ESRI shapefiles -
read.shape and read.dbf. The result is an sp spatial object. The
functions read point, line, and polygon shapefiles. package is on CRAN.
We have encountered all types of issues with shapefiles so may handle
your problem.
Tony
Roger Bivand
<Roger.Bivand at nh
h.no> To
Sent by: Susumu Tanimura
r-sig-geo-bounce <stanimura-ngs at umin.ac.jp>
s at stat.math.ethz cc
.ch r-sig-geo at stat.math.ethz.ch,
patrick.giraudoux at univ-fcomte.fr
Subject
02/09/2007 10:35 Re: [R-sig-Geo] ring not closed -
AM readShapePoly - read.shape -
maptools
Please respond
to
Roger.Bivand at nhh
.no
On Sat, 10 Feb 2007, Susumu Tanimura wrote:
Hi there,
The same problem happened to me when I used the shape file that is sold as commercial products.
getinfo.shape("Phu_Yen_Commune_ll_region.shp")
Shapefile type: Polygon, (5), # of Shapes: 104
a <- read.shape("Phu_Yen_Commune_ll_region.shp")
Field name: 1__PERS changed to: X1__PERS
Field name: 2_PERS changed to: X2_PERS
Field name: 3_PERS changed to: X3_PERS
[snip]
Shapefile type: Polygon, (5), # of Shapes: 104
b <- readShapePoly("Phu_Yen_Commune_ll_region.shp",verbose=TRUE)
Field name: 1__PERS changed to: X1__PERS
Field name: 2_PERS changed to: X2_PERS
Field name: 3_PERS changed to: X3_PERS
[snip]
Shapefile type: Polygon, (5), # of Shapes: 104
Error in validityMethod(object) : ring not closed
So, read.shape seems to be OK, but readShapePoly does not. Since readShapePoly uses internally read.shape and then Map object is passed to .Map2PolyDF(), I tried to find Map2PolyDF or validityMethod in source of maptools and sp package. However, I could not find them.
Dose anybody have better solution?
Patrick, Susumu, Could (either or both) you please make sample files available? I think that readOGR() will do the same as readShapePoly(), even though it does not use the same intermediate R code (same shapelib code in OGR). The internal function .Map2PolyDF can be accessed inside the maptools namespace as maptools:::.Map2PolyDF; it calls maptools:::.asSpatialPolygonsShapes, calling maptools:::.shp2srsI. This calls Polygon() with coords set to the current ring, so if it isn't closed, no check is made. It would be possible to pass an argument through closing unclosed rings if TRUE, default FALSE. Best wishes, Roger
OK... after a check, none of the rings are closed... suppose closing
was
managed automatically by ArcGIS and read.Shape... Patrick Giraudoux a ??crit :
Hi, I have slept on some data of a project which started in 2003 and
just
coming back on them today gives the opportunity to compare
read.shape
(shapefiles were initially imported with this function) and readShapePoly (the new one sp style). The latter will be much more interesting for the next step, giving directed handling to overlay methods. Importing one of my shapefile with read.shape ( read as polyshape in
ArcGIS) made (and still makes) no problem. However, when I try to import it again via readShapePoly, I get this message:
UG<-readShapePoly("U:/Documents and Settings/giraudoux/Mes
documents/FC25/NewSIG050317/UG.shp") Error in validityMethod(object) : ring not closed Clear enough: at least one of the polygons is not closed... which is
confirmed by the fact that I can import the shapefile easy with readShapeLines. I suppose the readShapePoly is more demanding in validity control than the older read.Shape and ArcGIS: one cannot complain for that. I am not afraid of sorting this out with some lines of programme. I have however a question before writing it: is there already a
function
making a check somewhere which could be used to know which one(s) of
the polygons are not closed? Patrick
-- Susumu Tanimura MSc PhD Dept. of Socio-environmental Medicine Inst. of Tropical Medicine, Nagasaki University TEL +81-95-849-7865 FAX +81-95-849-7867 e-mail stanimura-ngs at umin.ac.jp _______________________________________________ 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 _______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo