[R-sig-Geo] Handling invalid geometries from the ‘mapdata’ package

Karl Ove Hufthammer karl at huftis.org
Mon Mar 28 11:41:16 CEST 2011

I have discovered what looks like a geometry error in data from ‘worldHires’
data set. Here’s an illustration:


x.map = map("worldHires", "Norway", fill=TRUE, col="transparent", plot=FALSE, xlim=c(0,40), ylim=c(50,73))
x.sp = map2SpatialPolygons(x.map, x.map$names, proj4string=CRS("+init=epsg:4326"))

plot(x.sp)            # *Looks* OK
gPointOnSurface(x.sp) # Error: TopologyException: side location conflict at 3.97911 0.0769463
gIsValid(x.sp)        # Error: Self-intersection at or near point 27.9364 70.0864
points(27.9364, 70.0864, col="red", pch=19)

I guess this is to be be expected, as the ‘worldHires’ data isn’t of very
high quality, and is not guaranteed to be consistent. My questions are 
1) is it possible to automatically ‘fix’ this problem inside R, and 
2) what other problems may I expect from continuing to use the invalid data?

Karl Ove Hufthammer

More information about the R-sig-Geo mailing list