Skip to content

Commit

Permalink
[processing][gdal] Fix polygonize field name is ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 5, 2019
1 parent 62e09d9 commit 06d5b99
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
8 changes: 5 additions & 3 deletions python/plugins/processing/algs/gdal/GdalUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,13 @@ def ogrConnectionStringAndFormatFromLayer(layer):
return ogrstr, '"' + format + '"'

@staticmethod
def ogrLayerName(uri):
def ogrOutputLayerName(uri):
uri = uri.strip('"')
#if os.path.isfile(uri):
# return os.path.basename(os.path.splitext(uri)[0])
return os.path.basename(os.path.splitext(uri)[0])

@staticmethod
def ogrLayerName(uri):
uri = uri.strip('"')
if ' table=' in uri:
# table="schema"."table"
re_table_schema = re.compile(' table="([^"]*)"\\."([^"]*)"')
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/polygonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if outFormat:
arguments.append('-f {}'.format(outFormat))

layerName = GdalUtils.ogrLayerName(output)
layerName = GdalUtils.ogrOutputLayerName(output)
if layerName:
arguments.append(layerName)
arguments.append(self.parameterAsString(parameters, self.FIELD, context))
Expand Down
24 changes: 21 additions & 3 deletions python/plugins/processing/tests/GdalAlgorithmsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ def testGetOgrCompatibleSourceFromFeatureSource(self):

QgsProject.instance().removeMapLayer(layer)

def testOgrOutputLayerName(self):
self.assertEqual(GdalUtils.ogrOutputLayerName('/home/me/out.shp'), 'out')
self.assertEqual(GdalUtils.ogrOutputLayerName('d:/test/test_out.shp'), 'test_out')
self.assertEqual(GdalUtils.ogrOutputLayerName('d:/test/TEST_OUT.shp'), 'TEST_OUT')
self.assertEqual(GdalUtils.ogrOutputLayerName('d:/test/test_out.gpkg'), 'test_out')

def testOgrLayerNameExtraction(self):
with tempfile.TemporaryDirectory() as outdir:
def _copyFile(dst):
Expand Down Expand Up @@ -2660,7 +2666,19 @@ def testGdalPolygonize(self):
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "ESRI Shapefile" DN'
'-b 1 -f "ESRI Shapefile" check DN'
])

self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'BAND': 1,
'FIELD': 'VAL',
'EIGHT_CONNECTEDNESS': False,
'OUTPUT': outsource}, context, feedback),
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "ESRI Shapefile" check VAL'
])

# 8 connectedness
Expand All @@ -2673,7 +2691,7 @@ def testGdalPolygonize(self):
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-8 -b 1 -f "ESRI Shapefile" DN'
'-8 -b 1 -f "ESRI Shapefile" check DN'
])

# custom output format
Expand All @@ -2687,7 +2705,7 @@ def testGdalPolygonize(self):
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "GPKG" DN'
'-b 1 -f "GPKG" check DN'
])


Expand Down

0 comments on commit 06d5b99

Please sign in to comment.