Error in reading .shp
On Tue, 7 May 2013, Danielle Rappaport wrote:
Hi there: I am trying to have R read a shapefile of a simple landscape classification (posted here <http://temp-share.com/show/3YgF8Kd4x>) and am getting an error message, which I'm not sure how to resolve:
Shape2 <-readShapePoly("JustForest_BahiaSul_1990.shp")
Error in Polygon(coords = crds) : ring not closed I also tried specifying force_ring=TRUE, which does not seem to help:
shape3 <-readShapePoly("JustForest_BahiaSul_1990_Test.shp", force_ring=TRUE, delete_null_obj=TRUE)Error in Polygon(coords = crds) : ring not closed
The same error results when I try with rgdal as an alternative:
shape1 <-readOGR("JustForest_BahiaSul_1990_Test.shp", layer="JustForest_BahiaSul_1990_Test")OGR data source with driver: ESRI Shapefile
Source: "JustForest_BahiaSul_1990_Test.shp", layer: "JustForest_BahiaSul_1990_Test" with 19122 features and 6 fields Feature type: wkbPolygon with 2 dimensionsError in stopifnot(is.list(srl)) : ring not closed
Thanks for making the data available for reproduction, makes debugging much easier! The same happens in GRASS: Counting polygons for 19122 features... Importing map 19122 features... 100% ----------------------------------------------------- Building topology for vector map <test_tmp>... Registering primitives... v.in.ogr: index.c:159: RTreeInsertRect1: Assertion `r->boundary[i] <= r->boundary[3 + i]' failed. So the shapefile is broken, and the problem is in the software used by your collaborator. The specific problem is that all of the x-coordinates in entity 15755, first ring are NaN, not finite. If you are able to install sp and rgdal from R-forge from source checked out from SVN, you can get the corrected error message:
Shape2 <-readOGR(".", "JustForest_BahiaSul_1990", useC=TRUE)
OGR data source with driver: ESRI Shapefile Source: ".", layer: "JustForest_BahiaSul_1990" with 19122 features and 6 fields Feature type: wkbPolygon with 2 dimensions Error in stopifnot(is.list(srl)) : non-finite x coordinate and now by setting useC=FALSE, retrieve the entity number for errors. readOGR() will actually correct non-closed rings automatically, so the error message as it stood was misleading. So your collaborator has to create a new file with finite coordinates. Hope this clarifies, Roger
If it's of any use in troubleshooting, here is another shapefile (posted here <http://temp-share.com/show/KdPfyYg6h>) that was generated by the same collaborator of the same landscape just classified at another point in time, which R is reading without any problem. I can't seem to figure out why "JustForest_BahiaSul_2007.shp" is being read successfully, and "JustForest_BahiaSul_1990.shp" is not. Many thanks in advance for offering your time and sage R-dom. Best, Danielle sessionInfo() R version 2.15.3 (2013-03-01) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] grid stats graphics grDevices utils datasets [7] methods base other attached packages: [1] rgdal_0.8-8 maptools_0.8-23 lattice_0.20-13 [4] sp_1.0-9 foreign_0.8-52 loaded via a namespace (and not attached): [1] tools_2.15.3 Danielle Ivonne Rappaport Master of Forestry 2012, Yale University Skype | Danielle_Rappaport [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand Department of Economics, NHH Norwegian School of Economics, 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