Hi, I am trying to calculate fraction of a polygon that is intersected by
another polygon. I have data in two shape files; the first file corresponds
to a rectangular grid with uniform intervals whereas the second file
corresponds to US climate divisions, which are polygons. The script worked
fine expect for one ploygon; please see the below message. It looks like
coordinates of a polygon are corrupted but I am not sure whether it is the
cause and if so how to fix it. Any feedback is greatly appreciated. Data
sets and excerpts of my script are below mentioned.
Thanks,
Satish
library(rgdal); library(rgeos)
grid=readOGR("C:/Temp","Gaussian_Poylgon_ExtendedCONUS")
climagdiv=readOGR("C:/Temp","US102ClimateDivisions")
iclimdiv=45
print(paste("Climate Division ",iclimdiv,sep=""))
int = gIntersects(climagdiv[iclimdiv,],grid,byid=TRUE)
vec = vector(mode="list", length=dim(int)[2])
for (i in seq(along=vec)) vec[[i]] =
try(gIntersection(climagdiv[iclimdiv,],grid[int[,i],], byid=TRUE))
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, "rgeos_intersection")
:
TopologyException: found non-noded intersection between LINESTRING
(-91.043 32.5763, -90.964 32.5763) and LINESTRING (-90.964 32.5763, -91.035
32.5763) at -90.964 32.5763
Data sets:
1. Rectangular Grid
http://r-sig-geo.2731867.n2.nabble.com/file/n7240529/GaussianPolygonExtendedCONUS.zip
GaussianPolygonExtendedCONUS.zip
2. US 102 climate divisions
http://r-sig-geo.2731867.n2.nabble.com/file/n7240529/US102ClimateDivisions.zip
US102ClimateDivisions.zip
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Unable-to-apply-gIntersection-successfully-tp7240529p7240529.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
Unable to apply 'gIntersection' successfully
3 messages · satishr, Edzer Pebesma
Maybe this helps:
y = readOGR("US102ClimateDivisions", "US102ClimateDivisions")
OGR data source with driver: ESRI Shapefile Source: "US102ClimateDivisions", layer: "US102ClimateDivisions" with 102 features and 5 fields Feature type: wkbPolygon with 2 dimensions
gIsValid(y)
[1] FALSE Warning message: In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") : Ring Self-intersection at or near point -121.807 44.7908
which(!gIsValid(y, byid=TRUE))
21 28 44 98 100 22 29 45 99 101 Warning messages: 1: In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") : Ring Self-intersection at or near point -121.807 44.7908 2: In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") : Self-intersection at or near point -118.222 46.0004 3: In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") : Self-intersection at or near point -91.035 32.5763 4: In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") : Ring Self-intersection at or near point -73.834 40.5904 5: In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") : Ring Self-intersection at or near point -69.3086 43.9069
On 01/31/2012 06:32 PM, satishr wrote:
Hi, I am trying to calculate fraction of a polygon that is intersected by
another polygon. I have data in two shape files; the first file corresponds
to a rectangular grid with uniform intervals whereas the second file
corresponds to US climate divisions, which are polygons. The script worked
fine expect for one ploygon; please see the below message. It looks like
coordinates of a polygon are corrupted but I am not sure whether it is the
cause and if so how to fix it. Any feedback is greatly appreciated. Data
sets and excerpts of my script are below mentioned.
Thanks,
Satish
library(rgdal); library(rgeos)
grid=readOGR("C:/Temp","Gaussian_Poylgon_ExtendedCONUS")
climagdiv=readOGR("C:/Temp","US102ClimateDivisions")
iclimdiv=45
print(paste("Climate Division ",iclimdiv,sep=""))
int = gIntersects(climagdiv[iclimdiv,],grid,byid=TRUE)
vec = vector(mode="list", length=dim(int)[2])
for (i in seq(along=vec)) vec[[i]] =
try(gIntersection(climagdiv[iclimdiv,],grid[int[,i],], byid=TRUE))
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, "rgeos_intersection")
:
TopologyException: found non-noded intersection between LINESTRING
(-91.043 32.5763, -90.964 32.5763) and LINESTRING (-90.964 32.5763, -91.035
32.5763) at -90.964 32.5763
Data sets:
1. Rectangular Grid
http://r-sig-geo.2731867.n2.nabble.com/file/n7240529/GaussianPolygonExtendedCONUS.zip
GaussianPolygonExtendedCONUS.zip
2. US 102 climate divisions
http://r-sig-geo.2731867.n2.nabble.com/file/n7240529/US102ClimateDivisions.zip
US102ClimateDivisions.zip
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Unable-to-apply-gIntersection-successfully-tp7240529p7240529.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
Edzer, It helps. Thanks. For the future audience reference, here is the solution that worked in this situation Thanks to Colin Rundel. I calculated areas and compared with values after gBuffer application - they are same for all polygons except for two polygons for which values of 'area' differed on the order of 10^(-4). However, I found gBuffer resulted one or two additional rings though. This is OK for my calculations purpose. " the US 102 climate divisions polygons are invalid as they have self intersections. These self intersections cause geos to fail, you can see which of the polygons in climagdiv are invalid using the following code: gIsValid(climagdiv,reason=TRUE,byid=TRUE) There is not a simple cure all for fixing this kind of geometry issue, but in some cases using gBuffer with width=0 can fix things, which seems to be the case here. gIsValid(gBuffer(climagdiv,byid=TRUE,width=0),byid=TRUE) reports all the polygons as being valid. Fixing the climate divisions with climagdiv = gBuffer(climagdiv,width=0,byid=TRUE) " -- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Unable-to-apply-gIntersection-successfully-tp7240529p7241456.html Sent from the R-sig-geo mailing list archive at Nabble.com.