سؤال

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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

It's a bit difficult to say, because your pdf only defines the .mid structure.

It depends what you want to do with the date, but looking at it, the .mid file has the SW co-ords of each area, and inspecting the .mif file, each area is 1000m2, so you can just calcuate the areas (for this data sample) rather than loading them in.

So here is one way of loading it in, BUT it will depend on what you want to do with the data

First copy the .csv file into your working directory, then

coords<-read.csv(file="R02_rfl09_UTM20N1000.mid", header=FALSE)
colnames(coords)<-c("SW.E","SW.N","ind","indXYNE1")
# add the co-ords for the area
coords$SE.N=coords$SW.N
coords$SE.E=coords$SW.E+1000
coords$NW.N=coords$SW.N+1000
coords$NW.E=coords$SW.E
coords$NE.N=coords$SW.N+1000
coords$NE.E=coords$SW.E+1000

head(coords)

This will give you:

    SW.E    SW.N ind indXYNE1    SE.N   SE.E    NW.N   NW.E    NE.N   NE.E
1 690000 1636000 241        6 1636000 691000 1637000 690000 1637000 691000
2 690000 1637000 414        3 1637000 691000 1638000 690000 1638000 691000
3 690000 1638000 240        6 1638000 691000 1639000 690000 1639000 691000
4 690000 1640000   8        0 1640000 691000 1641000 690000 1641000 691000
5 691000 1634000 142        0 1634000 692000 1635000 691000 1635000 692000
6 691000 1635000 216        5 1635000 692000 1636000 691000 1636000 692000
....

which is the four bounding points of each area, plus the ind and indXYNE1 which I guess are what you are looking for? Then you can transform the data using the SW point (or a new derived key) as a reference for each area.

Hope that helps! Depends a bit what you want to do with the data.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top