1

I have a map showing administrative boundaries (available here). I've loaded it into R and have attempted to run gTouches (from rgeos) to determine which areas are adjacent to which, but receive an error:

library(rgeos)
library(rgdal)

> Districts <- readOGR(... )
OGR data source with driver: ESRI Shapefile
with 9235 features and 16 fields
Feature type: wkbPolygon with 2 dimensions

> adj <- gTouches(Districts)
Error in RGEOSBinPredFunc(spgeom1, spgeom2, byid, "rgeos_touches") : 
  TopologyException: side location conflict at 34.353274826787519 -15.739538287828307

After Googling that error I found a lot of advice about "bad geometries." Following that I took the file into QGIS (following advice here from Faunalia's "Bad, bad polygon" document) and ArcMap (using Python code here) and run the geometry checking/repair tools. Neither program found an error.

I've zoomed my map into the offending coordinates but don't see anything that appears wrong--it's a location where two lines come together near another vertex.

How do I repair the geometry, ignore that particular region, or some other R function that might work better than gTouches?

1

Try:

adj <- gTouches(Districts, byid = TRUE)

This produced a matrix indicating which regions share a border with other regions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.