【问题标题】:How to convert shape file to GeoJSON using ogr2ogr?如何使用 ogr2ogr 将形状文件转换为 GeoJSON?
【发布时间】:2021-11-02 06:58:04
【问题描述】:

我正在尝试使用 tippecanoe 生成 MBTiles 文件,为此我首先使用 ogr2ogr 将从 Geofabric 下载的形状文件转换为 GeoJSON 文件,然后使用 tippecanoe 将该 GeoJSON 文件转换为 MBTiles 文件。

我坚持的步骤是这个

ogr2ogr -f GeoJSON turk.geojson turkmenistan-latest-free.shp

我从 Geofabric 下载的文件是 .shp.zip 文件 - https://download.geofabrik.de/asia/turkmenistan-latest-free.shp.zip。在解压这个 zip 文件时,我得到一个文件夹,其中包含各种文件,如 gis_osm_buildings_a_free_1.cpg 等。但是,没有 turkmenistan-latest-free.shp 文件 - 或一个 .shp 文件包含所有土库曼斯坦。

当我直接在从 .zip 文件中提取的文件夹上运行 ogr2ogr 命令时,我收到此错误

ERROR 1: Layer 'gis_osm_landuse_a_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Terminating translation prematurely after failed
translation of layer gis_osm_landuse_a_free_1 (use -skipfailures to skip errors)

如果我使用 -skipfailures 运行相同的命令,我会收到更多错误

ERROR 1: Layer 'gis_osm_landuse_a_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_natural_a_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_natural_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_places_a_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_places_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_pofw_a_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_pofw_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_pois_a_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_pois_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_railways_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_roads_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_traffic_a_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_traffic_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_transport_a_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_transport_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_water_a_free_1' does not already exist in the output dataset, and cannot be created by the output driver.
ERROR 1: Layer 'gis_osm_waterways_free_1' does not already exist in the output dataset, and cannot be created by the output driver.

但是,在检查文件夹时,所有这些文件都已存在于其中,但 ogr2ogr 不知何故无法找到它。这些是文件夹中的文件

README                          gis_osm_natural_free_1.shp   gis_osm_pofw_free_1.prj      gis_osm_roads_free_1.dbf        gis_osm_transport_free_1.cpg
gis_osm_buildings_a_free_1.cpg  gis_osm_natural_free_1.shx   gis_osm_pofw_free_1.shp      gis_osm_roads_free_1.prj        gis_osm_transport_free_1.dbf
gis_osm_buildings_a_free_1.dbf  gis_osm_places_a_free_1.cpg  gis_osm_pofw_free_1.shx      gis_osm_roads_free_1.shp        gis_osm_transport_free_1.prj
gis_osm_buildings_a_free_1.prj  gis_osm_places_a_free_1.dbf  gis_osm_pois_a_free_1.cpg    gis_osm_roads_free_1.shx        gis_osm_transport_free_1.shp
gis_osm_buildings_a_free_1.shp  gis_osm_places_a_free_1.prj  gis_osm_pois_a_free_1.dbf    gis_osm_traffic_a_free_1.cpg    gis_osm_transport_free_1.shx
gis_osm_buildings_a_free_1.shx  gis_osm_places_a_free_1.shp  gis_osm_pois_a_free_1.prj    gis_osm_traffic_a_free_1.dbf    gis_osm_water_a_free_1.cpg
gis_osm_landuse_a_free_1.cpg    gis_osm_places_a_free_1.shx  gis_osm_pois_a_free_1.shp    gis_osm_traffic_a_free_1.prj    gis_osm_water_a_free_1.dbf
gis_osm_landuse_a_free_1.dbf    gis_osm_places_free_1.cpg    gis_osm_pois_a_free_1.shx    gis_osm_traffic_a_free_1.shp    gis_osm_water_a_free_1.prj
gis_osm_landuse_a_free_1.prj    gis_osm_places_free_1.dbf    gis_osm_pois_free_1.cpg      gis_osm_traffic_a_free_1.shx    gis_osm_water_a_free_1.shp
gis_osm_landuse_a_free_1.shp    gis_osm_places_free_1.prj    gis_osm_pois_free_1.dbf      gis_osm_traffic_free_1.cpg      gis_osm_water_a_free_1.shx
gis_osm_landuse_a_free_1.shx    gis_osm_places_free_1.shp    gis_osm_pois_free_1.prj      gis_osm_traffic_free_1.dbf      gis_osm_waterways_free_1.cpg
gis_osm_natural_a_free_1.cpg    gis_osm_places_free_1.shx    gis_osm_pois_free_1.shp      gis_osm_traffic_free_1.prj      gis_osm_waterways_free_1.dbf
gis_osm_natural_a_free_1.dbf    gis_osm_pofw_a_free_1.cpg    gis_osm_pois_free_1.shx      gis_osm_traffic_free_1.shp      gis_osm_waterways_free_1.prj
gis_osm_natural_a_free_1.prj    gis_osm_pofw_a_free_1.dbf    gis_osm_railways_free_1.cpg  gis_osm_traffic_free_1.shx      gis_osm_waterways_free_1.shp
gis_osm_natural_a_free_1.shp    gis_osm_pofw_a_free_1.prj    gis_osm_railways_free_1.dbf  gis_osm_transport_a_free_1.cpg  gis_osm_waterways_free_1.shx
gis_osm_natural_a_free_1.shx    gis_osm_pofw_a_free_1.shp    gis_osm_railways_free_1.prj  gis_osm_transport_a_free_1.dbf
gis_osm_natural_free_1.cpg      gis_osm_pofw_a_free_1.shx    gis_osm_railways_free_1.shp  gis_osm_transport_a_free_1.prj
gis_osm_natural_free_1.dbf      gis_osm_pofw_free_1.cpg      gis_osm_railways_free_1.shx  gis_osm_transport_a_free_1.shp
gis_osm_natural_free_1.prj      gis_osm_pofw_free_1.dbf      gis_osm_roads_free_1.cpg     gis_osm_transport_a_free_1.shx

我在这里做错了什么以及如何正确生成 GeoJSON 文件?

【问题讨论】:

    标签: gis geojson gdal shapefile


    【解决方案1】:

    首先,没有turkmenistan-latest-free.shp的shape文件,所以不能转换成GeoJSON。

    您可以转换目录中的任一 shapefile:

    gis_osm_buildings_a_free_1.shp
    gis_osm_landuse_a_free_1.shp
    gis_osm_natural_a_free_1.shp
    gis_osm_natural_free_1.shp
    gis_osm_places_a_free_1.shp
    gis_osm_places_free_1.shp
    gis_osm_pofw_a_free_1.shp
    gis_osm_pofw_free_1.shp
    gis_osm_pois_a_free_1.shp
    gis_osm_pois_free_1.shp
    gis_osm_railways_free_1.shp
    gis_osm_roads_free_1.shp
    gis_osm_traffic_a_free_1.shp
    gis_osm_traffic_free_1.shp
    gis_osm_transport_a_free_1.shp
    gis_osm_transport_free_1.shp
    gis_osm_water_a_free_1.shp
    gis_osm_waterways_free_1.shp
    

    通过跑步

    ogr2ogr output.json input.shp

    例如:

    ogr2ogr gis_osm_buildings_a_free_1.json gis_osm_buildings_a_free_1.shp

    您可以使用ogrinfo检查文件(输入或输出)是否有效:

    ogrinfo gis_osm_buildings_a_free_1.json
    
    # INFO: Open of `gis_osm_buildings_a_free_1.json'
    #       using driver `GeoJSON' successful.
    # 1: gis_osm_buildings_a_free_1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 2020-07-16
      • 2015-12-23
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      相关资源
      最近更新 更多