5

I'm trying to fortify a shape file that I loaded into R with rgdal, but I get the following error:

"Error: TopologyException: found non-noded intersection between LINESTRING 
        (34.7279 1.59723, 34.7278 1.59729) and LINESTRING 
         (34.7278 1.59723, 34.7278 1.59729) at 34.727793021883102 1.5972887049072426"

I am using a shape file for the continent of Africa from maplibrary.org. It is available from my dropbox here: https://www.dropbox.com/s/etqdw3nky52czv4/Africa%20map.zip

I am using the following code:

library(rgdal)
library(ggplot2)

africa = readOGR("Africa_SHP",    layer = "Africa")
africa.map = fortify(africa, region="COUNTRY")

And I get the error I mentioned before. I take it that R has some problems with the polygon - is there a way around this?

agstudy
  • 119,832
  • 17
  • 199
  • 261
David
  • 265
  • 4
  • 13
  • Often such problems are due to invalid geometries in inputs. But when I run you example I have no problem. maybe an install problem – agstudy Dec 01 '12 at 19:10
  • 1
    It means there is a line crossing another line and no intermediate coordinate records the intersection – mdsumner Dec 02 '12 at 10:32
  • gIsValid (from rgeos package) return TRUE for your shapefile? – Rodrigo Aug 06 '13 at 13:55

1 Answers1

7

As you can see from the comments mdsumner and agstudy were able to answer why this is happening, though agstudy was unable to recreate it with the dataset available. I did find a work-around for this problem.

library(rgdal)
library(rgeos)
library(ggplot2)
#LOADING IN DATA
africa = readOGR("directory", layer="filename")
#FIXING THE NON-NODED INTERSECTS#
africa = gBuffer(africa, width=0, byid=TRUE)
africa.map = fortify(africa, region="ID")
David
  • 265
  • 4
  • 13