Skip to content

Commit bd65fc6

Browse files
committedJun 1, 2018
[processing][gdal] Don't double quote output paths
Breaks for some drivers, e.g. KML Fixes #18264
1 parent 30ecb33 commit bd65fc6

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed
 

‎python/plugins/processing/algs/gdal/GdalUtils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def ogrConnectionStringAndFormat(uri, context):
276276
if layer is None:
277277
path, ext = os.path.splitext(uri)
278278
format = QgsVectorFileWriter.driverForExtension(ext)
279-
return '"' + uri + '"', '"' + format + '"'
279+
return uri, '"' + format + '"'
280280

281281
provider = layer.dataProvider().name()
282282
if provider == 'spatialite':
@@ -348,7 +348,7 @@ def ogrConnectionStringAndFormat(uri, context):
348348
path, ext = os.path.splitext(ogrstr)
349349
format = QgsVectorFileWriter.driverForExtension(ext)
350350

351-
return '"' + ogrstr + '"', '"' + format + '"'
351+
return ogrstr, '"' + format + '"'
352352

353353
@staticmethod
354354
def ogrLayerName(uri):

‎python/plugins/processing/algs/gdal/ogr2ogr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
8282
output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)
8383

8484
if outputFormat == 'SQLite' and os.path.isfile(output):
85-
raise QgsProcessinException(self.tr('Output file "{}" already exists.'.format(output)))
85+
raise QgsProcessingException(self.tr('Output file "{}" already exists.'.format(output)))
8686

8787
arguments = []
8888
if outputFormat:

‎python/plugins/processing/gui/BatchAlgorithmDialog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
from qgis.core import (QgsProcessingParameterDefinition,
3535
QgsProcessingParameterRasterDestination,
36+
QgsProcessingParameterVectorDestination,
3637
QgsProcessingParameterFeatureSink,
3738
QgsProcessingOutputLayerDefinition,
3839
QgsProcessingOutputHtml,
@@ -99,6 +100,7 @@ def accept(self):
99100
text = widget.getValue()
100101
if out.checkValueIsAcceptable(text):
101102
if isinstance(out, (QgsProcessingParameterRasterDestination,
103+
QgsProcessingParameterVectorDestination,
102104
QgsProcessingParameterFeatureSink)):
103105
# load rasters and sinks on completion
104106
parameters[out.name()] = QgsProcessingOutputLayerDefinition(text, project)

‎python/plugins/processing/tests/GdalAlgorithmsTest.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from processing.algs.gdal.GridInverseDistanceNearestNeighbor import GridInverseDistanceNearestNeighbor
4242
from processing.algs.gdal.GridLinear import GridLinear
4343
from processing.algs.gdal.GridNearestNeighbor import GridNearestNeighbor
44+
from processing.algs.gdal.ogr2ogr import ogr2ogr
4445
from processing.algs.gdal.proximity import proximity
4546
from processing.algs.gdal.rasterize import rasterize
4647
from processing.algs.gdal.retile import retile
@@ -233,10 +234,10 @@ def _copyFile(dst):
233234
def testOgrConnectionStringAndFormat(self):
234235
context = QgsProcessingContext()
235236
output, outputFormat = GdalUtils.ogrConnectionStringAndFormat('d:/test/test.shp', context)
236-
self.assertEqual(output, '"d:/test/test.shp"')
237+
self.assertEqual(output, 'd:/test/test.shp')
237238
self.assertEqual(outputFormat, '"ESRI Shapefile"')
238239
output, outputFormat = GdalUtils.ogrConnectionStringAndFormat('d:/test/test.mif', context)
239-
self.assertEqual(output, '"d:/test/test.mif"')
240+
self.assertEqual(output, 'd:/test/test.mif')
240241
self.assertEqual(outputFormat, '"MapInfo File"')
241242

242243
def testCrsConversion(self):
@@ -479,7 +480,7 @@ def testContour(self):
479480
['gdal_contour',
480481
'-b 1 -a elev -i 5.0 -f "ESRI Shapefile" ' +
481482
source + ' ' +
482-
'"d:/temp/check.shp"'])
483+
'd:/temp/check.shp'])
483484
# with NODATA value
484485
self.assertEqual(
485486
alg.getConsoleCommands({'INPUT': source,
@@ -491,7 +492,7 @@ def testContour(self):
491492
['gdal_contour',
492493
'-b 1 -a elev -i 5.0 -snodata 9999.0 -f "ESRI Shapefile" ' +
493494
source + ' ' +
494-
'"d:/temp/check.shp"'])
495+
'd:/temp/check.shp'])
495496
# with "0" NODATA value
496497
self.assertEqual(
497498
alg.getConsoleCommands({'INPUT': source,
@@ -503,7 +504,7 @@ def testContour(self):
503504
['gdal_contour',
504505
'-b 1 -a elev -i 5.0 -snodata 0.0 -f "GPKG" ' +
505506
source + ' ' +
506-
'"d:/temp/check.gpkg"'])
507+
'd:/temp/check.gpkg'])
507508

508509
def testGdal2Tiles(self):
509510
context = QgsProcessingContext()
@@ -648,7 +649,7 @@ def testGdalTindex(self):
648649
'OUTPUT': 'd:/temp/test.shp'}, context, feedback),
649650
['gdaltindex',
650651
'-tileindex location -f "ESRI Shapefile" ' +
651-
'"d:/temp/test.shp" ' +
652+
'd:/temp/test.shp ' +
652653
source])
653654

654655
# with input srs
@@ -658,7 +659,7 @@ def testGdalTindex(self):
658659
'OUTPUT': 'd:/temp/test.shp'}, context, feedback),
659660
['gdaltindex',
660661
'-tileindex location -t_srs EPSG:3111 -f "ESRI Shapefile" ' +
661-
'"d:/temp/test.shp" ' +
662+
'd:/temp/test.shp ' +
662663
source])
663664

664665
# with target using proj string
@@ -669,7 +670,7 @@ def testGdalTindex(self):
669670
'OUTPUT': 'd:/temp/test.shp'}, context, feedback),
670671
['gdaltindex',
671672
'-tileindex location -t_srs EPSG:20936 -f "ESRI Shapefile" ' +
672-
'"d:/temp/test.shp" ' +
673+
'd:/temp/test.shp ' +
673674
source])
674675

675676
# with target using custom projection
@@ -680,7 +681,7 @@ def testGdalTindex(self):
680681
'OUTPUT': 'd:/temp/test.shp'}, context, feedback),
681682
['gdaltindex',
682683
'-tileindex location -t_srs "+proj=utm +zone=36 +south +a=63785 +b=6357 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs" -f "ESRI Shapefile" ' +
683-
'"d:/temp/test.shp" ' +
684+
'd:/temp/test.shp ' +
684685
source])
685686

686687
# with non-EPSG crs code
@@ -690,7 +691,7 @@ def testGdalTindex(self):
690691
'OUTPUT': 'd:/temp/test.shp'}, context, feedback),
691692
['gdaltindex',
692693
'-tileindex location -t_srs EPSG:3111 -f "ESRI Shapefile" ' +
693-
'"d:/temp/test.shp" ' +
694+
'd:/temp/test.shp ' +
694695
source])
695696

696697
def testGridAverage(self):
@@ -897,6 +898,34 @@ def testGridNearestNeighbour(self):
897898
source + ' ' +
898899
'd:/temp/check.jpg'])
899900

901+
def testOgr2Ogr(self):
902+
context = QgsProcessingContext()
903+
feedback = QgsProcessingFeedback()
904+
source = os.path.join(testDataPath, 'polys.gml')
905+
alg = ogr2ogr()
906+
alg.initAlgorithm()
907+
908+
self.assertEqual(
909+
alg.getConsoleCommands({'INPUT': source,
910+
'OUTPUT': 'd:/temp/check.shp'}, context, feedback),
911+
['ogr2ogr',
912+
'-f "ESRI Shapefile" d:/temp/check.shp ' +
913+
source + ' polys2'])
914+
915+
self.assertEqual(
916+
alg.getConsoleCommands({'INPUT': source,
917+
'OUTPUT': 'd:/temp/check.kml'}, context, feedback),
918+
['ogr2ogr',
919+
'-f "LIBKML" d:/temp/check.kml ' +
920+
source + ' polys2'])
921+
922+
self.assertEqual(
923+
alg.getConsoleCommands({'INPUT': source,
924+
'OUTPUT': 'd:/temp/my out/check.kml'}, context, feedback),
925+
['ogr2ogr',
926+
'-f "LIBKML" "d:/temp/my out/check.kml" ' +
927+
source + ' polys2'])
928+
900929
def testProximity(self):
901930
context = QgsProcessingContext()
902931
feedback = QgsProcessingFeedback()

0 commit comments

Comments
 (0)
Please sign in to comment.