mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
[processing] add unittest for gdal_polygonize algorithm
This commit is contained in:
parent
f447745b5f
commit
6809d346ab
@ -111,7 +111,9 @@ class polygonize(GdalAlgorithm):
|
||||
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.rearrange_bands import rearrange_bands
|
||||
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 @@ class TestGdalAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
|
||||
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):
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user