将 ASCII 码转换为轮廓形状文件

Convert ASCII to contour shapefile

有没有办法将 ASCII 文件或 numpy 数组直接转换为等高线并导出为 shapefile(例如使用 geopandas)?例如栅格高程数据。

我通常做的是将 ASCII 作为 numpy 数组加载到 python 中,并将元数据存储在变量中。执行一些计算后,我将 numpy 数组与元数据一起导出为 ASCII,然后将其转换为 QGIS 中的等高线图。我很好奇是否有办法在 Python 中执行所有这些操作。任何建议都会很有帮助。

可以使用 GDAL 实用程序将 ASCII GRID 文件转换为等高线的 shapefile gdal_countour

https://gdal.org/programs/gdal_contour.html

例如,

gdal_contour -a elev dem.asc contour.shp -i 10.0

...将从 dem.asc 中的 DEM 数据创建 10 米等高线,并在 contour.shp|shx|dbf 中生成 shapefile,等高线高程在 elev属性。

关于从 Python 调用实用程序,因为 GDAL 2.1,GDAL 和 OGR 实用程序可以用作库函数,更多信息在这里:

http://erouault.blogspot.com/2015/10/gdal-and-ogr-utilities-as-library.html

甚至在 GDAL 主干上还有一个使用 Python 绑定的 gdal_countour 测试,您可以在其中查看如何以编程方式调用实用程序 Python:

https://svn.osgeo.org/gdal/trunk/autotest/utilities/test_gdal_contour.py