我正在QGIS中处理python脚本,并试图栅格化包含单个多边形的矢量层。我正在使用QGIS 3.2,并且遇到以下无法解决的追溯:
"cordova-plugin-mauron85-background-geolocation": {
...
"CONTENT_AUTHORITY": "$PACKAGE_NAME"
}
以下代码生成上面的错误(第118行是最后一行):
File "C:\OSGEO4~1\apps\Python36\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 118, in <module>
File "C:\OSGEO4~1\apps\Python36\lib\site-packages\osgeo\gdal.py", line 2738, in RasterizeLayer
return _gdal.RasterizeLayer(*args, **kwargs)
TypeError: in method 'RasterizeLayer', argument 4 of type 'OGRLayerShadow *'
任何提示和技巧都将不胜感激,因为我用尽了所有想法。谢谢!
答案 0 :(得分:0)
最后通过使用处理模块解决了该问题:
import processing
extent = layer.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()
processing.run("gdal:rasterize",
{"INPUT":layer,
"FIELD":"myElev",
"UNITS":0,
"WIDTH":300,
"HEIGHT":300,
"EXTENT":"%f,%f,%f,%f"% (xmin, xmax, ymin, ymax),
"NODATA":0,
"DATA_TYPE":1,
"INVERT":0,
"OUTPUT":"D:/myPath/file.tif"})
希望可以帮助遇到相同问题的人。干杯!