首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用ogr2ogr将shape文件转换为GeoJSON?

如何使用ogr2ogr将shape文件转换为GeoJSON?
EN

Stack Overflow用户
提问于 2021-09-04 07:37:59
回答 1查看 316关注 0票数 0

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

我被卡住的步骤是这样的

代码语言:javascript
运行
复制
ogr2ogr -f GeoJSON turk.geojson turkmenistan-latest-free.shp

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

当我直接在从.zip文件中解压出来的文件夹上运行ogr2ogr命令时,我得到这个错误

代码语言:javascript
运行
复制
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运行相同的命令,我会得到更多的错误

代码语言:javascript
运行
复制
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不知何故无法找到它。这些是文件夹中的文件

代码语言:javascript
运行
复制
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文件?

EN

回答 1

Stack Overflow用户

发布于 2021-09-06 07:44:37

首先,没有turkmenistan-latest-free.shp形状文件,所以您不能将其转换为GeoJSON。

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

代码语言:javascript
运行
复制
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检查文件(输入或输出)是否有效

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69053309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档