Skip to content

Commit ae21d07

Browse files
committedFeb 7, 2019
[processing][gdal] Fix polygonize field name is ignored
(cherry picked from commit 06d5b99)
1 parent 331f590 commit ae21d07

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed
 

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,13 @@ def ogrConnectionStringAndFormatFromLayer(layer):
353353
return ogrstr, '"' + format + '"'
354354

355355
@staticmethod
356-
def ogrLayerName(uri):
356+
def ogrOutputLayerName(uri):
357357
uri = uri.strip('"')
358-
#if os.path.isfile(uri):
359-
# return os.path.basename(os.path.splitext(uri)[0])
358+
return os.path.basename(os.path.splitext(uri)[0])
360359

360+
@staticmethod
361+
def ogrLayerName(uri):
362+
uri = uri.strip('"')
361363
if ' table=' in uri:
362364
# table="schema"."table"
363365
re_table_schema = re.compile(' table="([^"]*)"\\."([^"]*)"')

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
111111
if outFormat:
112112
arguments.append('-f {}'.format(outFormat))
113113

114-
layerName = GdalUtils.ogrLayerName(output)
114+
layerName = GdalUtils.ogrOutputLayerName(output)
115115
if layerName:
116116
arguments.append(layerName)
117117
arguments.append(self.parameterAsString(parameters, self.FIELD, context))

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ def testGetOgrCompatibleSourceFromFeatureSource(self):
258258

259259
QgsProject.instance().removeMapLayer(layer)
260260

261+
def testOgrOutputLayerName(self):
262+
self.assertEqual(GdalUtils.ogrOutputLayerName('/home/me/out.shp'), 'out')
263+
self.assertEqual(GdalUtils.ogrOutputLayerName('d:/test/test_out.shp'), 'test_out')
264+
self.assertEqual(GdalUtils.ogrOutputLayerName('d:/test/TEST_OUT.shp'), 'TEST_OUT')
265+
self.assertEqual(GdalUtils.ogrOutputLayerName('d:/test/test_out.gpkg'), 'test_out')
266+
261267
def testOgrLayerNameExtraction(self):
262268
with tempfile.TemporaryDirectory() as outdir:
263269
def _copyFile(dst):
@@ -2660,7 +2666,19 @@ def testGdalPolygonize(self):
26602666
['gdal_polygonize.py',
26612667
source + ' ' +
26622668
outsource + ' ' +
2663-
'-b 1 -f "ESRI Shapefile" DN'
2669+
'-b 1 -f "ESRI Shapefile" check DN'
2670+
])
2671+
2672+
self.assertEqual(
2673+
alg.getConsoleCommands({'INPUT': source,
2674+
'BAND': 1,
2675+
'FIELD': 'VAL',
2676+
'EIGHT_CONNECTEDNESS': False,
2677+
'OUTPUT': outsource}, context, feedback),
2678+
['gdal_polygonize.py',
2679+
source + ' ' +
2680+
outsource + ' ' +
2681+
'-b 1 -f "ESRI Shapefile" check VAL'
26642682
])
26652683

26662684
# 8 connectedness
@@ -2673,7 +2691,7 @@ def testGdalPolygonize(self):
26732691
['gdal_polygonize.py',
26742692
source + ' ' +
26752693
outsource + ' ' +
2676-
'-8 -b 1 -f "ESRI Shapefile" DN'
2694+
'-8 -b 1 -f "ESRI Shapefile" check DN'
26772695
])
26782696

26792697
# custom output format
@@ -2687,7 +2705,7 @@ def testGdalPolygonize(self):
26872705
['gdal_polygonize.py',
26882706
source + ' ' +
26892707
outsource + ' ' +
2690-
'-b 1 -f "GPKG" DN'
2708+
'-b 1 -f "GPKG" check DN'
26912709
])
26922710

26932711

0 commit comments

Comments
 (0)
Please sign in to comment.