diff --git a/python/plugins/processing/algs/gdal/OgrToPostGis.py b/python/plugins/processing/algs/gdal/OgrToPostGis.py index 97eb909a9725..39012eedcc97 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) @@ -270,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: arguments.append('-append') if include_fields: arguments.append(fields_string) @@ -323,7 +334,16 @@ 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 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 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 5f56db6abe76..c6645a8bcf8c 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', 'CONVERT_TO_LINEAR', 'CONVERT_TO_CURVE'] 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,6 +169,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)) @@ -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) @@ -265,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: arguments.append('-append') if addfields: arguments.append('-addfields') @@ -316,7 +330,17 @@ 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 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 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/tests/GdalAlgorithmsVectorTest.py b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py index abebefb4c3f9..c2f535a40fd9 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,15 +796,16 @@ 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, + 'OVERWRITE': False, 'APPEND': True}, context, feedback), ['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 +813,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 +821,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 +829,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 +837,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 +845,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 +853,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 +861,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,15 +869,24 @@ 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, + 'PROMOTETOMULTI': False, 'GTYPE': 4}, context, feedback), ['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_line + ' 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 +894,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 +902,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 +911,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 +919,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 +927,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 +936,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 +944,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 +952,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 +961,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 +969,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 +977,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 +999,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 +1072,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 +1114,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 + ' ' +