【问题标题】:Looping through shapefiles in GDAL OSGeo4W在 GDAL OSGeo4W 中循环遍历 shapefile
【发布时间】:2013-10-25 13:26:35
【问题描述】:

我有一个要转换为 geoJSON 的形状文件列表。我正在使用 GDAL OSGeo4W shell 进行转换。

首先,我定义坐标系(因为它们不是为 shapefile 定义的)然后我转换它们。

我可以轻松地为单个文件执行此操作,但是由于我有 200 多个 shapefile,因此我想遍历它们。

我的个人命令是:

ogr2ogr -s_srs http://spatialreference.org/ref/epsg/27700/ srs_def x.shp

ogr2ogr -f GeoJSON -t_srs EPSG:27700 x.geojson x.shp

【问题讨论】:

    标签: loops gdal shapefile osgeo


    【解决方案1】:

    制作一个在主 OSGeo4w shell 中运行的批处理脚本,或者一个在 MSYS shell 中运行的 shell 脚本。要了解它们的外观,请参阅https://gis.stackexchange.com/a/7806/1872

    【讨论】:

      【解决方案2】:

      批处理gdal或ogr命令的一种简单方法是使用python(您可以通过启动python直接在OSGeo4w中使用它):

      import os
      os.system('ogr2ogr -s_srs http://spatialreference.org/ref/epsg/27700/ srs_def x.shp')
      os.system('ogr2ogr -f GeoJSON -t_srs EPSG:27700 x.geojson x.shp')
      

      然后,你就可以做一个简单的循环了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-04-21
        • 2010-11-15
        • 2018-06-19
        • 2012-11-08
        • 2011-10-08
        • 2021-03-20
        • 2012-07-20
        相关资源
        最近更新 更多