Skip to content
Permalink
Browse files

[processing] add unittest for gdal_polygonize algorithm

  • Loading branch information
alexbruy committed Jan 1, 2019
1 parent f447745 commit 6809d346ab8ad6e42bb8020520c3d5fd70e331b7
@@ -111,7 +111,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if outFormat:
arguments.append('-f {}'.format(outFormat))

arguments.append(GdalUtils.ogrLayerName(output))
layerName = GdalUtils.ogrLayerName(output)
if layerName:
arguments.append(layerName)
arguments.append(self.parameterAsString(parameters, self.FIELD, context))

commands = []
@@ -62,6 +62,7 @@
from processing.algs.gdal.gdaladdo import gdaladdo
from processing.algs.gdal.sieve import sieve
from processing.algs.gdal.gdal2xyz import gdal2xyz
from processing.algs.gdal.polygonize import polygonize

from processing.tools.system import isWindows

@@ -2547,6 +2548,56 @@ def testGdal2Xyz(self):
source + ' ' +
outsource])

def testGdalPolygonize(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
source = os.path.join(testDataPath, 'dem.tif')

with tempfile.TemporaryDirectory() as outdir:
outsource = outdir + '/check.shp'
alg = polygonize()
alg.initAlgorithm()

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

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

# custom output format
outsource = outdir + '/check.gpkg'
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'BAND': 1,
'FIELD': 'DN',
'EIGHT_CONNECTEDNESS': False,
'OUTPUT': outsource}, context, feedback),
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "GPKG" DN'
])


class TestGdalOgrToPostGis(unittest.TestCase):

0 comments on commit 6809d34

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