[問題] subprocess.call with gdalwrap
大家好 我又來麻煩大家了
我現在想要用subprocess.call來用gdal裡面的gdalwrap來進行
shapefile 切 raster的方法(在Qgis 1.8.0 的python主控台下)
我先用raster→projections→wrap(reproject)產生下面command_line
-----------------------------------------------------------------------------
gdalwarp -t_srs "+proj=tmerc +lat_0=0 +lon_0=121 +k=0.9999 +x_0=250000 +y_0=0
+ellps=GRS80 +units=m +no_defs" -dstnodata 0 -q -cutline "C:/Program Files
(x86)/Quantum GIS Wroclaw/test/area.shp"
-dstalpha -of GTiff C:/Program Files
(x86)/Quantum GIS Wroclaw/test/wrapM_0.tif "C:/Program Files
(x86)/Quantum GIS Wroclaw/test/wrap"
------------------------------------------------------------------------------
其中 gdalwrap 是他的command名稱
下面是我的code
=============================================================================
#先加入gdal,subprocess.call兩個函式
import gdal
from subprocess import call
#將變數轉換成代號,再輸入會比較清楚
crs='"+proj=tmerc +lat_0=0 +lon_0=121 +k=0.9999 +x_0=250000 +y_0=0
+ellps=GRS80 +units=m +no_defs"'
mask='"C:/Program Files(x86)/Quantum GIS Wroclaw/test/area.shp"'
input='C:/Program Files(x86)/Quantum GIS Wroclaw/test/wrapM_0.tif'
output='"C:/Program Files(x86)/Quantum GIS Wroclaw/test/wrap"'
#將上面的command_line用代號代換之後執行call
call(gdalwarp, -t_srs crs -dstnodata 0 -q -cutline msak -dstalpha -of GTiff
input output)
=============================================================================
然後會出現下面的error
=============================================================================
File "<input>", line 1
call(gdalwarp, -t_srs crs -dstnodata 0 -q -cutline msak -dstalpha -of
GTiff input output)
^
SyntaxError: invalid syntax
=============================================================================
然後如果我的code用原本的command_line的話
也是會在同樣的地方發生錯誤
請問有用過的前輩知道大概哪邊錯了嗎?
fixed issue
=============================================================================
#將call函式改成這樣 就可以用了
call('gdalwarp -t_srs ' + crs + ' -dstnodata 0 -q -cutline ' + mask + '
-dstalpha -of GTIFF ' + input + ' ' + output, shell=True)
#或者這樣也可以
call(['gdalwarp', '-t_srs ' + crs, '-dstnodata 0', '-q', '-cutline ' + mask,
'-dstalpha', '-of GTIFF', input, output])
=============================================================================
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.63.202
推
05/06 19:30, , 1F
05/06 19:30, 1F
→
05/06 19:32, , 2F
05/06 19:32, 2F
→
05/06 19:41, , 3F
05/06 19:41, 3F
→
05/06 19:44, , 4F
05/06 19:44, 4F
→
05/06 20:50, , 5F
05/06 20:50, 5F
※ 編輯: MAGICXX 來自: 140.112.63.202 (05/08 11:03)
Python 近期熱門文章
PTT數位生活區 即時熱門文章