每次执行 gdal 命令时停止打开新的 gdal 命令 window python
Stop new gdal command window opening each time gdal command is executed python
我写了一个使用 gdals warp 的 PyQGIS 脚本。为我做这件事的代码如下:
warp = 'gdalwarp -ot Byte -q -of GTiff -tr 2.81932541777e-05 -2.81932541777e-05 -tap -cutline %s -crop_to_cutline -co COMPRESS=DEFLATE -co PREDICTOR=1 -co ZLEVEL=6 -wo OPTIMIZE_SIZE=TRUE %s %s' % (instrv, ('"' + pathsplitedit + '"'), outputpath2)
call (warp)
所以我把它放在一个循环中,一切都很好。但是,每次执行新命令时都会打开 window,这并不理想,因为它会循环遍历 shapefile 中的多达 100 个要素。有没有办法让 window 命令根本无法打开?非常感谢任何帮助!!
自 GDAL 2.1(最新版本的 QGIS 使用)以来,您可以从绑定本身访问命令行实用程序,这有很多好处。
你的电话变成这样,注意我没有复制你所有的创建选项,只是为了让你知道如何使用它。
warpopts = gdal.WarpOptions(outputType=gdal.GDT_Byte,
format='GTiff',
xRes=2.81932541777e-05,
yRes=-2.81932541777e-05,
cutlineDSName='cutline_vec.shp',
cropToCutline=True,
targetAlignedPixels=True,
options=['COMPRESS=DEFLATE'])
ds = gdal.Warp('raster_out.tif', 'raster_in.tif', options=warpopts)
ds = None
其中一个好处是输入文件不必在磁盘上,但也可以打开 gdal/ogr 数据集。 gdal.Warp
cmd 还将输出文件 returns 作为打开的数据集,然后您可以将其传递给其他命令。
我写了一个使用 gdals warp 的 PyQGIS 脚本。为我做这件事的代码如下:
warp = 'gdalwarp -ot Byte -q -of GTiff -tr 2.81932541777e-05 -2.81932541777e-05 -tap -cutline %s -crop_to_cutline -co COMPRESS=DEFLATE -co PREDICTOR=1 -co ZLEVEL=6 -wo OPTIMIZE_SIZE=TRUE %s %s' % (instrv, ('"' + pathsplitedit + '"'), outputpath2)
call (warp)
所以我把它放在一个循环中,一切都很好。但是,每次执行新命令时都会打开 window,这并不理想,因为它会循环遍历 shapefile 中的多达 100 个要素。有没有办法让 window 命令根本无法打开?非常感谢任何帮助!!
自 GDAL 2.1(最新版本的 QGIS 使用)以来,您可以从绑定本身访问命令行实用程序,这有很多好处。
你的电话变成这样,注意我没有复制你所有的创建选项,只是为了让你知道如何使用它。
warpopts = gdal.WarpOptions(outputType=gdal.GDT_Byte,
format='GTiff',
xRes=2.81932541777e-05,
yRes=-2.81932541777e-05,
cutlineDSName='cutline_vec.shp',
cropToCutline=True,
targetAlignedPixels=True,
options=['COMPRESS=DEFLATE'])
ds = gdal.Warp('raster_out.tif', 'raster_in.tif', options=warpopts)
ds = None
其中一个好处是输入文件不必在磁盘上,但也可以打开 gdal/ogr 数据集。 gdal.Warp
cmd 还将输出文件 returns 作为打开的数据集,然后您可以将其传递给其他命令。