Search code examples
rmapinfo

How can I read Mapinfo files in R


The French national institute (Insee) provides geographical data in the MapInfo format (two files .mid and .mif and one dbf file). How can I read those files in R ?

Here is one example.


Solution

  • There is an OGR-Driver for MapInfo files (package rgdal):

    R> library("rgdal")
    R> ogrDrivers()[28, ]
               name write
    28 MapInfo File  TRUE
    

    But there is a problem with your files/geometry, readOGR gives the error message:

    R> ogrListLayers("R02_rfl09_UTM20N1000.mid")
    [1] "R02_rfl09_UTM20N1000"
    
    R> readOGR("R02_rfl09_UTM20N1000.mid", layer="R02_rfl09_UTM20N1000")
    OGR data source with driver: MapInfo File 
    Source: "R02_rfl09_UTM20N1000.mid", layer: "R02_rfl09_UTM20N1000"
    with 967 features and 4 fields
    Feature type: wkbPolygon with 2 dimensions
    Error in stopifnot(is.list(srl)) : ring not closed
    

    However, I was able to read the files with GRASS GIS, which can be scripted from R (package spgrass6):

    v.in.ogr dsn=R02_rfl09_UTM20N1000.mid output=R02_rfl09_UTM20N1000 snap=1e-08
    

    GRASS screenshot