[QGIS-Developer] QGIS 3 modeler - GDAL call parameters double escaped

Jorge Gustavo Rocha jgr at di.uminho.pt
Wed Jun 13 02:47:57 PDT 2018


Hi,

I was showing a very small use case of the modeler, with just two steps,
to count reindeers in a IR raster. It failed with a very simple error.
If I use spaces in the final output name, it fails. This is not a high
priority issue.

If I set the output name as 'reindeer polygons', the gdal call is:

gdal_polygonize.py
/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/dfee0e38cbd1483ca732fd82a12110c5/OUTPUT.tif
"\"/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/ef043a13ea8044c4a4ab9fee9c373b1f/gdal_polygonize_1_reindeer
polygons.shp\"" -b 1 -f "ESRI Shapefile"

But the additional " are not necessary and it will fail. The entire log
is below.

If the generated string was just (without the additional \"):

gdal_polygonize.py
/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/dfee0e38cbd1483ca732fd82a12110c5/OUTPUT.tif
"/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/ef043a13ea8044c4a4ab9fee9c373b1f/gdal_polygonize_1_reindeer
polygons.shp" -b 1 -f "ESRI Shapefile"

it works.

So, it is escaped only if there are spaces on the output name. In Linux
this double escaping fails. Does this escaping works on other OS? Is it
safe to discard this double escaping mechanism?

Regards,

J. Gustavo
-- 
Jorge Gustavo Rocha
Departamento de Informática
Universidade do Minho
4710-057 Braga
Tel: +351 253604480
Fax: +351 253604471
Móvel: +351 910333888
skype: nabocudnosor

-----------------------------------------------------------------------------------------

Processing algorithm…
Algorithm 'Counting Reindeer' starting…
Input parameters:
{ 'gdal:polygonize_1:reindeer polygons' :
'/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/ed2a4eb50e1d4a6ebe98392ea9f1c520/gdal_polygonize_1_reindeer
polygons.shp', 'infrared' :
'/home/jgr/Documentos/Classification/classification.tif' }

Prepare algorithm: qgis:rastercalculator_1
Running Raster calculator [1/2]
Input Parameters:
{ CELLSIZE: 1, CRS: 'EPSG:32633', EXPRESSION:
'"<qgis._core.QgsProcessingModelChildParameterSource object at
0x7f0f3e23be58>@1" = 12', EXTENT:
'/home/jgr/Documentos/Classification/classification.tif', LAYERS: '',
OUTPUT:
'/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/b2be67056f714fcca6a0317233b4b134/OUTPUT.tif'
}
OK. Execution took 0.321 s (1 outputs).
Prepare algorithm: gdal:polygonize_1
Running Polygonize (raster to vector) [2/2]
Input Parameters:
{ BAND: 1, EIGHT_CONNECTEDNESS: False, FIELD: 'DN', INPUT:
'/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/b2be67056f714fcca6a0317233b4b134/OUTPUT.tif',
OUTPUT:
'/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/ed2a4eb50e1d4a6ebe98392ea9f1c520/gdal_polygonize_1_reindeer
polygons.shp' }
GDAL command:
gdal_polygonize.py
/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/b2be67056f714fcca6a0317233b4b134/OUTPUT.tif
"\"/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/ed2a4eb50e1d4a6ebe98392ea9f1c520/gdal_polygonize_1_reindeer
polygons.shp\"" -b 1 -f "ESRI Shapefile" None DN
GDAL command output:
ERROR 1: Failed to create directory
"/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/ed2a4eb50e1d4a6ebe98392ea9f1c520/gdal_polygonize_1_reindeer
polygons.shp" for shapefile datastore.

Creating output
"/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/ed2a4eb50e1d4a6ebe98392ea9f1c520/gdal_polygonize_1_reindeer
polygons.shp" of format ESRI Shapefile.

Traceback (most recent call last):

File "/usr/bin/gdal_polygonize.py", line 197, in <module>

dst_layer = dst_ds.CreateLayer(dst_layername, geom_type=ogr.wkbPolygon,
srs = srs )

AttributeError: 'NoneType' object has no attribute 'CreateLayer'

OK. Execution took 0.144 s (1 outputs).
Model processed OK. Executed 2 algorithms total in 0.772 s.
Execution completed in 0.79 seconds
Results:
{'gdal:polygonize_1:reindeer polygons':
<QgsProcessingOutputLayerDefinition
{'sink':/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/ed2a4eb50e1d4a6ebe98392ea9f1c520/gdal_polygonize_1_reindeer
polygons.shp, 'createOptions': {'fileEncoding': 'System'}}>}

Loading resulting layers
The following layers were not correctly generated.
/tmp/processing_7b5b06e1a8f14ee09ac38187a00ce932/ed2a4eb50e1d4a6ebe98392ea9f1c520/gdal_polygonize_1_reindeer
polygons.shp
You can check the 'Log Messages Panel' in QGIS main window to find more
information about the execution of the algorithm.



More information about the QGIS-Developer mailing list