7

法国国家研究所 (Insee) 提供 MapInfo 格式的地理数据(两个文件 .mid 和 .mif 以及一个 dbf 文件)。如何在 R 中读取这些文件?

这是一个例子

4

2 回答 2

9

MapInfo 文件有一个 OGR 驱动程序(包rgdal):

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

但是你的文件/几何有问题,readOGR给出错误信息:

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

但是,我能够使用GRASS GIS读取文件,这些文件可以从 R (包spgrass6)编写脚本:

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

草截图

于 2013-11-20T18:54:47.963 回答
5

说起来有点难,因为你的 pdf 只定义了 .mid 结构。

这取决于您想对日期做什么,但是查看它,.mid 文件具有每个区域的 SW 坐标,并检查 .mif 文件,每个区域为 1000m2,因此您可以计算面积(对于这个数据样本),而不是加载它们。

所以这是加载它的一种方法,但它取决于你想对数据做什么

首先将 .csv 文件复制到您的工作目录中,然后

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)

这会给你:

    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
....

这是每个区域的四个边界点,加上我猜你正在寻找的 ind 和 indXYNE1 ?然后,您可以使用 SW 点(或新的派生键)作为每个区域的参考来转换数据。

希望有帮助!取决于您想对数据做什么。

于 2013-11-20T17:22:10.640 回答