Skip to content
Permalink
Browse files

[processing][gdal] Fix polygonize field name is ignored

  • Loading branch information
nyalldawson committed Feb 5, 2019
1 parent 62e09d9 commit 06d5b996bfc37f2877ecbf708af608952420ed45
@@ -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="([^"]*)"\\."([^"]*)"')
@@ -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))
@@ -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):
@@ -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
@@ -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
@@ -2687,7 +2705,7 @@ def testGdalPolygonize(self):
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "GPKG" DN'
'-b 1 -f "GPKG" check DN'
])


0 comments on commit 06d5b99

Please sign in to comment.
You can’t perform that action at this time.