From 673e0f98528f7e7f2fc3c20a4f0ebeac9a322bbf Mon Sep 17 00:00:00 2001 From: Admire Nyakudya Date: Tue, 20 Aug 2024 10:28:08 +0200 Subject: [PATCH 01/10] Fix promote to multi logic and add makevalid option --- .../algs/gdal/ogr2ogrtopostgislist.py | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py index 5f56db6abe76..ef94ae174a07 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py +++ b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py @@ -47,7 +47,8 @@ class Ogr2OgrToPostGisList(GdalAlgorithm): SHAPE_ENCODING = 'SHAPE_ENCODING' GTYPE = 'GTYPE' GEOMTYPE = ['', 'NONE', 'GEOMETRY', 'POINT', 'LINESTRING', 'POLYGON', 'GEOMETRYCOLLECTION', 'MULTIPOINT', - 'MULTIPOLYGON', 'MULTILINESTRING', 'CIRCULARSTRING', 'COMPOUNDCURVE', 'CURVEPOLYGON', 'MULTICURVE', 'MULTISURFACE'] + 'MULTIPOLYGON', 'MULTILINESTRING', 'CIRCULARSTRING', 'COMPOUNDCURVE', 'CURVEPOLYGON', 'MULTICURVE', + 'MULTISURFACE'] S_SRS = 'S_SRS' T_SRS = 'T_SRS' A_SRS = 'A_SRS' @@ -76,6 +77,7 @@ class Ogr2OgrToPostGisList(GdalAlgorithm): INDEX = 'INDEX' SKIPFAILURES = 'SKIPFAILURES' PRECISION = 'PRECISION' + MAKEVALID = 'MAKEVALID' PROMOTETOMULTI = 'PROMOTETOMULTI' OPTIONS = 'OPTIONS' @@ -106,12 +108,14 @@ def initAlgorithm(self, config=None): schema_param = QgsProcessingParameterDatabaseSchema( self.SCHEMA, - self.tr('Schema (schema name)'), defaultValue='public', connectionParameterName=self.DATABASE, optional=True) + self.tr('Schema (schema name)'), defaultValue='public', connectionParameterName=self.DATABASE, + optional=True) self.addParameter(schema_param) table_param = QgsProcessingParameterDatabaseTable( self.TABLE, - self.tr('Table to import to (leave blank to use layer name)'), defaultValue=None, connectionParameterName=self.DATABASE, + self.tr('Table to import to (leave blank to use layer name)'), defaultValue=None, + connectionParameterName=self.DATABASE, schemaParameterName=self.SCHEMA, optional=True, allowNewTableNames=True) self.addParameter(table_param) @@ -165,9 +169,13 @@ def initAlgorithm(self, config=None): self.tr( 'Continue after a failure, skipping the failed feature'), defaultValue=False)) + self.addParameter(QgsProcessingParameterBoolean(self.MAKEVALID, + self.tr( + 'Validate geometries based on Simple Features specification'), + defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.PROMOTETOMULTI, self.tr('Promote to Multipart'), - defaultValue=True)) + defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.PRECISION, self.tr('Keep width and precision of input attributes'), defaultValue=True)) @@ -206,7 +214,8 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): md = QgsProviderRegistry.instance().providerMetadata('postgres') conn = md.createConnection(connection_name) except QgsProviderConnectionException: - raise QgsProcessingException(self.tr('Could not retrieve connection details for {}').format(connection_name)) + raise QgsProcessingException( + self.tr('Could not retrieve connection details for {}').format(connection_name)) uri = conn.uri() @@ -239,6 +248,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): index = self.parameterAsBoolean(parameters, self.INDEX, context) indexstring = "-lco SPATIAL_INDEX=OFF" skipfailures = self.parameterAsBoolean(parameters, self.SKIPFAILURES, context) + make_valid = self.parameterAsBoolean(parameters, self.MAKEVALID, context) promotetomulti = self.parameterAsBoolean(parameters, self.PROMOTETOMULTI, context) precision = self.parameterAsBoolean(parameters, self.PRECISION, context) options = self.parameterAsString(parameters, self.OPTIONS, context) @@ -316,7 +326,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): if len(gt) > 0: arguments.append('-gt') arguments.append(gt) - if promotetomulti: + if make_valid: + arguments.append('-makevalid') + if promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) < 1: arguments.append('-nlt PROMOTE_TO_MULTI') if precision is False: arguments.append('-lco PRECISION=NO') From e643ec67ce0fbee730837eb07af221c510aa4af0 Mon Sep 17 00:00:00 2001 From: Admire Nyakudya Date: Tue, 20 Aug 2024 13:35:40 +0200 Subject: [PATCH 02/10] Fix review comments --- .../processing/algs/gdal/OgrToPostGis.py | 17 +++++++++++++++-- .../algs/gdal/ogr2ogrtopostgislist.py | 10 +++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/python/plugins/processing/algs/gdal/OgrToPostGis.py b/python/plugins/processing/algs/gdal/OgrToPostGis.py index 97eb909a9725..bb7784e90b8e 100644 --- a/python/plugins/processing/algs/gdal/OgrToPostGis.py +++ b/python/plugins/processing/algs/gdal/OgrToPostGis.py @@ -40,7 +40,8 @@ class OgrToPostGis(GdalAlgorithm): SHAPE_ENCODING = 'SHAPE_ENCODING' GTYPE = 'GTYPE' GEOMTYPE = ['', 'NONE', 'GEOMETRY', 'POINT', 'LINESTRING', 'POLYGON', 'GEOMETRYCOLLECTION', 'MULTIPOINT', - 'MULTIPOLYGON', 'MULTILINESTRING', 'CIRCULARSTRING', 'COMPOUNDCURVE', 'CURVEPOLYGON', 'MULTICURVE', 'MULTISURFACE'] + 'MULTIPOLYGON', 'MULTILINESTRING', 'CIRCULARSTRING', 'COMPOUNDCURVE', 'CURVEPOLYGON', 'MULTICURVE', + 'MULTISURFACE', 'CONVERT_TO_LINEAR', 'CONVERT_TO_CURVE'] S_SRS = 'S_SRS' T_SRS = 'T_SRS' A_SRS = 'A_SRS' @@ -70,6 +71,7 @@ class OgrToPostGis(GdalAlgorithm): INDEX = 'INDEX' SKIPFAILURES = 'SKIPFAILURES' PRECISION = 'PRECISION' + MAKEVALID = 'MAKEVALID' PROMOTETOMULTI = 'PROMOTETOMULTI' OPTIONS = 'OPTIONS' @@ -161,6 +163,10 @@ def initAlgorithm(self, config=None): self.tr( 'Continue after a failure, skipping the failed feature'), defaultValue=False)) + self.addParameter(QgsProcessingParameterBoolean(self.MAKEVALID, + self.tr( + 'Validate geometries based on Simple Features specification'), + defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.PROMOTETOMULTI, self.tr('Promote to Multipart'), defaultValue=True)) @@ -248,6 +254,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): index = self.parameterAsBoolean(parameters, self.INDEX, context) indexstring = "-lco SPATIAL_INDEX=OFF" skipfailures = self.parameterAsBoolean(parameters, self.SKIPFAILURES, context) + make_valid = self.parameterAsBoolean(parameters, self.MAKEVALID, context) promotetomulti = self.parameterAsBoolean(parameters, self.PROMOTETOMULTI, context) precision = self.parameterAsBoolean(parameters, self.PRECISION, context) options = self.parameterAsString(parameters, self.OPTIONS, context) @@ -323,7 +330,13 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): if len(gt) > 0: arguments.append('-gt') arguments.append(gt) - if promotetomulti: + if make_valid: + arguments.append('-makevalid') + if promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) > 0: + raise QgsProcessingException( + self.tr( + 'Only one of Promote to Multipart or Output geometry type can be enabled at a time.')) + elif promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) < 1: arguments.append('-nlt PROMOTE_TO_MULTI') if precision is False: arguments.append('-lco PRECISION=NO') diff --git a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py index ef94ae174a07..cef23a16c226 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py +++ b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py @@ -48,7 +48,7 @@ class Ogr2OgrToPostGisList(GdalAlgorithm): GTYPE = 'GTYPE' GEOMTYPE = ['', 'NONE', 'GEOMETRY', 'POINT', 'LINESTRING', 'POLYGON', 'GEOMETRYCOLLECTION', 'MULTIPOINT', 'MULTIPOLYGON', 'MULTILINESTRING', 'CIRCULARSTRING', 'COMPOUNDCURVE', 'CURVEPOLYGON', 'MULTICURVE', - 'MULTISURFACE'] + 'MULTISURFACE', 'CONVERT_TO_LINEAR', 'CONVERT_TO_CURVE'] S_SRS = 'S_SRS' T_SRS = 'T_SRS' A_SRS = 'A_SRS' @@ -175,7 +175,7 @@ def initAlgorithm(self, config=None): defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.PROMOTETOMULTI, self.tr('Promote to Multipart'), - defaultValue=False)) + defaultValue=True)) self.addParameter(QgsProcessingParameterBoolean(self.PRECISION, self.tr('Keep width and precision of input attributes'), defaultValue=True)) @@ -328,7 +328,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): arguments.append(gt) if make_valid: arguments.append('-makevalid') - if promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) < 1: + if promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) > 0: + raise QgsProcessingException( + self.tr( + 'Only one of Promote to Multipart or Output geometry type can be enabled at a time.')) + elif promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) < 1: arguments.append('-nlt PROMOTE_TO_MULTI') if precision is False: arguments.append('-lco PRECISION=NO') From 367928b951d3b59b036287a159349b216c0b9543 Mon Sep 17 00:00:00 2001 From: Admire Nyakudya Date: Tue, 20 Aug 2024 16:05:20 +0200 Subject: [PATCH 03/10] update tests, fix append and overwrite options --- .../processing/algs/gdal/OgrToPostGis.py | 15 +- .../algs/gdal/ogr2ogrtopostgislist.py | 16 +- .../tests/GdalAlgorithmsVectorTest.py | 141 ++++++++++-------- 3 files changed, 101 insertions(+), 71 deletions(-) diff --git a/python/plugins/processing/algs/gdal/OgrToPostGis.py b/python/plugins/processing/algs/gdal/OgrToPostGis.py index bb7784e90b8e..f0e4ba655358 100644 --- a/python/plugins/processing/algs/gdal/OgrToPostGis.py +++ b/python/plugins/processing/algs/gdal/OgrToPostGis.py @@ -277,7 +277,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): arguments.append(indexstring) if launder: arguments.append(launderstring) - if append: + if append and overwrite: + raise QgsProcessingException( + self.tr( + 'Only one of Overwrite existing table or append to existing table can be enabled at a time.')) + elif append and not overwrite: arguments.append('-append') if include_fields: arguments.append(fields_string) @@ -333,9 +337,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): if make_valid: arguments.append('-makevalid') if promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) > 0: - raise QgsProcessingException( - self.tr( - 'Only one of Promote to Multipart or Output geometry type can be enabled at a time.')) + if self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)] == 'CONVERT_TO_LINEAR': + arguments.append('-nlt PROMOTE_TO_MULTI') + else: + raise QgsProcessingException( + self.tr( + 'Only one of Promote to Multipart or Output Geometry Type (excluding Convert to Linear) can be enabled.')) elif promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) < 1: arguments.append('-nlt PROMOTE_TO_MULTI') if precision is False: diff --git a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py index cef23a16c226..8ef885139ea8 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py +++ b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py @@ -275,7 +275,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): arguments.append(indexstring) if launder: arguments.append(launderstring) - if append: + if append and overwrite: + raise QgsProcessingException( + self.tr( + 'Only one of Overwrite existing table or append to existing table can be enabled at a time.')) + elif append and not overwrite: arguments.append('-append') if addfields: arguments.append('-addfields') @@ -329,9 +333,13 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): if make_valid: arguments.append('-makevalid') if promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) > 0: - raise QgsProcessingException( - self.tr( - 'Only one of Promote to Multipart or Output geometry type can be enabled at a time.')) + if self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)] == 'CONVERT_TO_LINEAR': + arguments.append('-nlt PROMOTE_TO_MULTI') + else: + raise QgsProcessingException( + self.tr( + 'Only one of Promote to Multipart or Output Geometry Type (excluding Convert to Linear) can be enabled.')) + elif promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) < 1: arguments.append('-nlt PROMOTE_TO_MULTI') if precision is False: diff --git a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py index abebefb4c3f9..39055240623f 100644 --- a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py +++ b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py @@ -116,9 +116,10 @@ def testOgr2Ogr(self): multi_source]) self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'CONVERT_ALL_LAYERS': True, - 'OUTPUT': outdir + '/check.gpkg'}, context, feedback), + alg.getConsoleCommands( + {'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'CONVERT_ALL_LAYERS': True, + 'OUTPUT': outdir + '/check.gpkg'}, context, feedback), ['ogr2ogr', '-f "GPKG" -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + outdir + '/check.gpkg ' + source]) @@ -370,9 +371,10 @@ def testBuffer(self): '-explodecollections -f "ESRI Shapefile"']) self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'DISTANCE': 5, - 'OUTPUT': outdir + '/check.shp'}, context, feedback), + alg.getConsoleCommands( + {'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'DISTANCE': 5, + 'OUTPUT': outdir + '/check.shp'}, context, feedback), ['ogr2ogr', outdir + '/check.shp ' + source + ' ' + @@ -589,10 +591,11 @@ def testDissolve(self): 'GROUP BY """my_field"""" "my opts" -f "ESRI Shapefile"']) self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'FIELD': 'my_field', - 'OPTIONS': 'my opts', - 'OUTPUT': outdir + '/check.shp'}, context, feedback), + alg.getConsoleCommands( + {'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'FIELD': 'my_field', + 'OPTIONS': 'my opts', + 'OUTPUT': outdir + '/check.shp'}, context, feedback), ['ogr2ogr', outdir + '/check.shp ' + source + ' ' + @@ -614,6 +617,7 @@ def testOgr2PostGis(self): context = QgsProcessingContext() feedback = QgsProcessingFeedback() source = os.path.join(testDataPath, 'polys.gml') + source_line = os.path.join(testDataPath, 'multilines.gml') source_with_space = os.path.join(testDataPath, 'filename with spaces.gml') alg = OgrToPostGis() alg.initAlgorithm() @@ -623,14 +627,14 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source_with_space}, context, feedback), ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 "' + source_with_space + '" filename_with_spaces ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.filename_with_spaces -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.filename_with_spaces -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -638,7 +642,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=google.com port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -646,7 +650,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=3333 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -654,7 +658,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public user=kevin_bacon" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -662,7 +666,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 dbname=secret_stuff active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -670,7 +674,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 password=passw0rd active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -678,7 +682,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=desktop" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln desktop.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln desktop.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -686,7 +690,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.out_table -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.out_table -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -694,7 +698,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -702,7 +706,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=new_fid -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=new_fid -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -711,7 +715,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=objectid -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=objectid -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -720,7 +724,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=new_id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=new_id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -728,7 +732,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=my_geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=my_geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -736,7 +740,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=3 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -744,7 +748,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -simplify 5 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -simplify 5 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -752,7 +756,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -segmentize 4 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -segmentize 4 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -760,7 +764,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -spat 1.0 2.0 3.0 4.0 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -spat 1.0 2.0 3.0 4.0 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -768,7 +772,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 -select "f1,f2" ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -776,7 +780,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -where "0=1" -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -where "0=1" -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -784,7 +788,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -gt 2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -gt 2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -792,7 +796,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -800,7 +804,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-append -overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-append -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -808,7 +812,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-addfields -overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-addfields -overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -816,7 +820,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-lco LAUNDER=NO -overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-lco LAUNDER=NO -overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -824,7 +828,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-lco SPATIAL_INDEX=OFF -overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-lco SPATIAL_INDEX=OFF -overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -832,7 +836,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -skipfailures -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -skipfailures -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -840,7 +844,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -848,7 +852,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI -lco PRECISION=NO']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI -lco PRECISION=NO']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -856,7 +860,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI blah']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI blah']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -864,7 +868,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES --config SHAPE_ENCODING blah -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -872,7 +876,15 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -nlt LINESTRING -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-overwrite -nlt LINESTRING -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2']) + + self.assertEqual( + alg.getConsoleCommands({'INPUT': source_line, + 'GTYPE': 15}, context, feedback), + ['ogr2ogr', + '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' + '-lco DIM=2 ' + source + ' multilines ' + '-overwrite -nlt CONVERT_TO_LINEAR -lco GEOMETRY_NAME=geom -lco FID=id -nln public.multilines -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -880,7 +892,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -888,7 +900,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) custom_crs = 'proj4: +proj=utm +zone=36 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs' self.assertEqual( @@ -897,7 +909,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:20936 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:20936 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -905,7 +917,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -t_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -t_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -913,7 +925,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -t_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -t_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) custom_crs = 'proj4: +proj=utm +zone=36 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs' self.assertEqual( @@ -922,7 +934,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -t_srs EPSG:20936 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -t_srs EPSG:20936 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -930,7 +942,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -s_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -s_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, @@ -938,7 +950,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -s_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -s_srs EPSG:3111 -nlt PROMOTE_TO_MULTI']) custom_crs = 'proj4: +proj=utm +zone=36 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-143,-90,-294,0,0,0,0 +units=m +no_defs' self.assertEqual( @@ -947,7 +959,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -s_srs EPSG:20936 -nlt PROMOTE_TO_MULTI']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -s_srs EPSG:20936 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', @@ -955,7 +967,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:3111 -nlt PROMOTE_TO_MULTI -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:3111 -nlt PROMOTE_TO_MULTI -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y']) self.assertEqual( alg.getConsoleCommands({'INPUT': source + '|credential:X=Y|credential:Z=A', @@ -963,7 +975,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:3111 -nlt PROMOTE_TO_MULTI --config X Y --config Z A']) + '-overwrite -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -a_srs EPSG:3111 -nlt PROMOTE_TO_MULTI --config X Y --config Z A']) def testOffsetCurve(self): context = QgsProcessingContext() @@ -985,9 +997,10 @@ def testOffsetCurve(self): '-f "ESRI Shapefile"']) self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'DISTANCE': 5, - 'OUTPUT': outdir + '/check.shp'}, context, feedback), + alg.getConsoleCommands( + {'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'DISTANCE': 5, + 'OUTPUT': outdir + '/check.shp'}, context, feedback), ['ogr2ogr', outdir + '/check.shp ' + source + ' ' + @@ -1057,10 +1070,11 @@ def testOneSidedBuffer(self): 'FROM """polys2""" GROUP BY """total population"""" -f "ESRI Shapefile"']) self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'DISTANCE': 5, - 'FIELD': 'total population', - 'OUTPUT': outdir + '/check.shp'}, context, feedback), + alg.getConsoleCommands( + {'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'DISTANCE': 5, + 'FIELD': 'total population', + 'OUTPUT': outdir + '/check.shp'}, context, feedback), ['ogr2ogr', outdir + '/check.shp ' + source + ' ' + @@ -1098,9 +1112,10 @@ def testPointsAlongLines(self): '-f "ESRI Shapefile"']) self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'DISTANCE': 0.2, - 'OUTPUT': outdir + '/check.shp'}, context, feedback), + alg.getConsoleCommands( + {'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'DISTANCE': 0.2, + 'OUTPUT': outdir + '/check.shp'}, context, feedback), ['ogr2ogr', outdir + '/check.shp ' + source + ' ' + From ee0fdd5eb772f3fd54031801cc90007492d8c210 Mon Sep 17 00:00:00 2001 From: Admire Nyakudya Date: Wed, 21 Aug 2024 18:20:44 +0200 Subject: [PATCH 04/10] update tests, set ovewrite ti false --- python/plugins/processing/tests/GdalAlgorithmsVectorTest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py index 39055240623f..2c67c6582074 100644 --- a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py +++ b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py @@ -800,6 +800,7 @@ def testOgr2PostGis(self): self.assertEqual( alg.getConsoleCommands({'INPUT': source, + 'OVERWRITE': False, 'APPEND': True}, context, feedback), ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' From 7e74b5ffa0e97e3ba1435b4b43816198d4f91904 Mon Sep 17 00:00:00 2001 From: Admire Nyakudya Date: Wed, 21 Aug 2024 19:10:15 +0200 Subject: [PATCH 05/10] update tests, remove extra space --- python/plugins/processing/tests/GdalAlgorithmsVectorTest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py index 2c67c6582074..696f4acb8393 100644 --- a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py +++ b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py @@ -805,7 +805,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source + ' polys2 ' - '-append -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) + '-append -lco GEOMETRY_NAME=geom -lco FID=id -nln public.polys2 -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, From 2617d3f8fe689ffc582acb7e385c875d0d3fc707 Mon Sep 17 00:00:00 2001 From: Admire Nyakudya Date: Wed, 21 Aug 2024 21:22:32 +0200 Subject: [PATCH 06/10] update tests, set promote to false --- python/plugins/processing/tests/GdalAlgorithmsVectorTest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py index 696f4acb8393..b26562c19fa8 100644 --- a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py +++ b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py @@ -873,6 +873,7 @@ def testOgr2PostGis(self): self.assertEqual( alg.getConsoleCommands({'INPUT': source, + 'PROMOTETOMULTI': False, 'GTYPE': 4}, context, feedback), ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' From 1c16769d18000235e557f6234ba9be0bc0f04e65 Mon Sep 17 00:00:00 2001 From: Admire Nyakudya Date: Thu, 22 Aug 2024 08:40:39 +0200 Subject: [PATCH 07/10] update tests, use same input --- python/plugins/processing/tests/GdalAlgorithmsVectorTest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py index b26562c19fa8..d6d94c507e74 100644 --- a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py +++ b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py @@ -885,7 +885,7 @@ def testOgr2PostGis(self): 'GTYPE': 15}, context, feedback), ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' - '-lco DIM=2 ' + source + ' multilines ' + '-lco DIM=2 ' + source_line + ' multilines ' '-overwrite -nlt CONVERT_TO_LINEAR -lco GEOMETRY_NAME=geom -lco FID=id -nln public.multilines -nlt PROMOTE_TO_MULTI']) self.assertEqual( From d0f078a418e2802a0cea0a983281e4d1030005dd Mon Sep 17 00:00:00 2001 From: Admire Nyakudya Date: Thu, 22 Aug 2024 09:56:29 +0200 Subject: [PATCH 08/10] Format file after changes --- python/plugins/processing/tests/GdalAlgorithmsVectorTest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py index d6d94c507e74..c2f535a40fd9 100644 --- a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py +++ b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py @@ -886,7 +886,7 @@ def testOgr2PostGis(self): ['ogr2ogr', '-progress --config PG_USE_COPY YES -f PostgreSQL "PG:host=localhost port=5432 active_schema=public" ' '-lco DIM=2 ' + source_line + ' multilines ' - '-overwrite -nlt CONVERT_TO_LINEAR -lco GEOMETRY_NAME=geom -lco FID=id -nln public.multilines -nlt PROMOTE_TO_MULTI']) + '-overwrite -nlt CONVERT_TO_LINEAR -lco GEOMETRY_NAME=geom -lco FID=id -nln public.multilines -nlt PROMOTE_TO_MULTI']) self.assertEqual( alg.getConsoleCommands({'INPUT': source, From c0e58071ad63831b31cd5d46e2c0bfded183cd4f Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 17 Oct 2024 15:50:16 +1000 Subject: [PATCH 09/10] Apply suggestions from code review --- python/plugins/processing/algs/gdal/OgrToPostGis.py | 10 +++++----- .../processing/algs/gdal/ogr2ogrtopostgislist.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/python/plugins/processing/algs/gdal/OgrToPostGis.py b/python/plugins/processing/algs/gdal/OgrToPostGis.py index f0e4ba655358..39012eedcc97 100644 --- a/python/plugins/processing/algs/gdal/OgrToPostGis.py +++ b/python/plugins/processing/algs/gdal/OgrToPostGis.py @@ -280,8 +280,8 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): if append and overwrite: raise QgsProcessingException( self.tr( - 'Only one of Overwrite existing table or append to existing table can be enabled at a time.')) - elif append and not overwrite: + 'Only one of "Overwrite existing table" or "Append to existing table" can be enabled at a time.')) + elif append: arguments.append('-append') if include_fields: arguments.append(fields_string) @@ -336,14 +336,14 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): arguments.append(gt) if make_valid: arguments.append('-makevalid') - if promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) > 0: + if promotetomulti and self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]: if self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)] == 'CONVERT_TO_LINEAR': arguments.append('-nlt PROMOTE_TO_MULTI') else: raise QgsProcessingException( self.tr( - 'Only one of Promote to Multipart or Output Geometry Type (excluding Convert to Linear) can be enabled.')) - elif promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) < 1: + 'Only one of "Promote to Multipart" or "Output geometry type" (excluding Convert to Linear) can be enabled.')) + elif promotetomulti and not self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]: arguments.append('-nlt PROMOTE_TO_MULTI') if precision is False: arguments.append('-lco PRECISION=NO') diff --git a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py index 8ef885139ea8..960afe84e037 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py +++ b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py @@ -278,8 +278,8 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): if append and overwrite: raise QgsProcessingException( self.tr( - 'Only one of Overwrite existing table or append to existing table can be enabled at a time.')) - elif append and not overwrite: + 'Only one of "Overwrite existing table" or "Append to existing table" can be enabled at a time.')) + elif append: arguments.append('-append') if addfields: arguments.append('-addfields') @@ -332,15 +332,15 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): arguments.append(gt) if make_valid: arguments.append('-makevalid') - if promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) > 0: + if promotetomulti and self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]: if self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)] == 'CONVERT_TO_LINEAR': arguments.append('-nlt PROMOTE_TO_MULTI') else: raise QgsProcessingException( self.tr( - 'Only one of Promote to Multipart or Output Geometry Type (excluding Convert to Linear) can be enabled.')) + 'Only one of "Promote to Multipart" or "Output geometry type" (excluding Convert to Linear) can be enabled.')) - elif promotetomulti and len(self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]) < 1: + elif promotetomulti and not self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context): arguments.append('-nlt PROMOTE_TO_MULTI') if precision is False: arguments.append('-lco PRECISION=NO') From 303025937be8fae71a12552102c5c70083294c23 Mon Sep 17 00:00:00 2001 From: Admire Nyakudya Date: Thu, 17 Oct 2024 15:24:45 +0200 Subject: [PATCH 10/10] fix missing bracket reported by flake --- python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py index 960afe84e037..c6645a8bcf8c 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py +++ b/python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py @@ -340,7 +340,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True): self.tr( 'Only one of "Promote to Multipart" or "Output geometry type" (excluding Convert to Linear) can be enabled.')) - elif promotetomulti and not self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context): + elif promotetomulti and not self.GEOMTYPE[self.parameterAsEnum(parameters, self.GTYPE, context)]: arguments.append('-nlt PROMOTE_TO_MULTI') if precision is False: arguments.append('-lco PRECISION=NO')