我一直在試驗Python的子流程模塊。我想效仿以下,成功的命令:Python子流程公式
命令行:
ogr2ogr -f GeoJSON -clipsrc cutting.json output.json input.json
Python實現:
import subprocess
subprocess.call(["ogr2ogr", "-f", "GeoJSON", "-clipsrc", "cutting.json", "output.json", "input.json"], shell=True)
然而,python腳本輸出: FAILURE: no target datasource provided
從文檔,我可以看到該語法是正確的,並且我正在指定源數據源和目標數據源 正確的順序。當然,由於它在命令行上工作,我傾向於認爲數據方向是正確的。我是否錯誤地調用子進程?
僅供參考,使用ogr2ogr
:
Usage: ogr2ogr [--help-general] [-skipfailures] [-append] [-update]
[-select field_list] [-where restricted_where]
[-progress] [-sql <sql statement>] [-dialect dialect]
[-preserve_fid] [-fid FID]
[-spat xmin ymin xmax ymax] [-geomfield field]
[-a_srs srs_def] [-t_srs srs_def] [-s_srs srs_def]
[-f format_name] [-overwrite] [[-dsco NAME=VALUE] ...]
dst_datasource_name src_datasource_name
[-lco NAME=VALUE] [-nln name] [-nlt type] [-dim 2|3|layer_dim] [layer [layer ...]]
Advanced options :
[-gt n]
[-clipsrc [xmin ymin xmax ymax]|WKT|datasource|spat_extent]
[-clipsrcsql sql_statement] [-clipsrclayer layer]
[-clipsrcwhere expression]
[-clipdst [xmin ymin xmax ymax]|WKT|datasource]
[-clipdstsql sql_statement] [-clipdstlayer layer]
[-clipdstwhere expression]
[-wrapdateline][-datelineoffset val]
[[-simplify tolerance] | [-segmentize max_dist]]
[-addfields]
[-relaxedFieldNameMatch]
[-fieldTypeToString All|(type1[,type2]*)] [-unsetFieldWidth]
[-fieldmap identity | index1[,index2]*]
[-splitlistfields] [-maxsubfields val]
[-explodecollections] [-zfield field_name]
[-gcp pixel line easting northing [elevation]]* [-order n | -tps]
是否有任何理由指定'shell = True'? – zondo
不!隨意發佈作爲答案;) – LearningSlowly
做類似'sub.call(['回聲',' - 幫助'],殼=真)'工程? – Rptk99