如何读取R中的Mapinfo文件


Minions
2025-03-12 04:07:12 (27天前)
  1. 法国国家研究所(Insee)以MapInfo格式提供地理数据(两个文件.mid和.mif以及一个dbf文件)。如何在R中读取这些文件?

这是一个例子。

3 条回复
  1. 0# 求赞有赞必回 | 2019-08-31 10-32



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

    rgdal

    ):




    1. R> library(“rgdal”)
      R> ogrDrivers()[28, ]
      name write
      28 MapInfo File TRUE

    2. </code>


    但是你的文件/几何有问题,

    readOGR

    给出错误消息:




    1. R> ogrListLayers(“R02_rfl09_UTM20N1000.mid”)
      [1] R02_rfl09_UTM20N1000

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

    3. </code>


    但是,我能够读取文件

    GRASS GIS

    ,可以从R(包

    spgrass6

    ):




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

    2. </code>




  2. 1# 疯子哥哥 | 2019-08-31 10-32



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



    这取决于你想对日期做什么,但看看它,.mid文件有每个区域的SW合作,并检查.mif文件,每个区域是1000平方米,所以你可以只计算面积(这个数据样本)而不是加载它们。



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



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




    1. coords<-read.csv(file=”R02_rfl09_UTM20N1000.mid”, header=FALSE)
      colnames(coords)<-c(“SW.E”,”SW.N”,”ind”,”indXYNE1”)

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

    3. head(coords)

    4. </code>


    这会给你:




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

    2. </code>


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



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


登录 后才能参与评论