我正在 Jupyter Notebook 中制作一个脚本,它将ogr2ogr
在一个循环中执行多个转换。据我所知,我不能直接将变量传递给 ogr2ogr。我可以用字符串格式化程序做到这一点吗?
! ogr2ogr -f "ESRI Shapefile" {fout} "my_orignal_shp.shp".format(fout = "my_output.shp")
返回
FAILURE: Unable to open datasource `my_output.shp.format(fout' with the following drivers.
并! (ogr2ogr -f "ESRI Shapefile" {fout} "my_orignal_shp.shp").format(fout = "my_output.shp")
返回.format(fout was unexpected at this time.
使用 Windows、Python 3.7、GDAL 3.3.1 和 Jupyter Notebook
更新 我还尝试了以下方法,如GDAL 示例指南中所建议的那样
command = 'ogr2ogr -f "ESRI Shapefile" {i} {o}'
i = r'D:\Documents\my_orignal_shp.shp'
o = r'D:\Documents\my_output.shp'
! os.system(command.format(input=fin, output=fout))
并收到此错误:'os.system' is not recognized as an internal or external command, operable program or batch file.