diff --git a/python/plugins/processing/algs/gdal/GdalAlgorithm.py b/python/plugins/processing/algs/gdal/GdalAlgorithm.py index 1c1a94c9cda..c92ddb637a0 100644 --- a/python/plugins/processing/algs/gdal/GdalAlgorithm.py +++ b/python/plugins/processing/algs/gdal/GdalAlgorithm.py @@ -32,7 +32,8 @@ from qgis.core import (QgsApplication, QgsProcessingAlgorithm, QgsProcessingContext, QgsProcessingFeedback, - QgsProviderRegistry) + QgsProviderRegistry, + QgsDataSourceUri) from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog from processing.algs.gdal.GdalUtils import GdalUtils @@ -115,6 +116,11 @@ class GdalAlgorithm(QgsProcessingAlgorithm): #for the command line preview since it has no meaning outside of a QGIS session! ogr_data_path = GdalUtils.ogrConnectionStringAndFormatFromLayer(input_layer)[0] ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri()) + elif input_layer.dataProvider().name().lower() == 'wfs': + uri = QgsDataSourceUri(input_layer.source()) + baseUrl = uri.param('url').split('?')[0] + ogr_data_path = "WFS:{}".format(baseUrl) + ogr_layer_name = uri.param('typename') else: # vector layer, but not OGR - get OGR compatible path # TODO - handle "selected features only" mode!! diff --git a/python/plugins/processing/algs/gdal/GdalUtils.py b/python/plugins/processing/algs/gdal/GdalUtils.py index ce40dcc8b8f..f8c4234916a 100644 --- a/python/plugins/processing/algs/gdal/GdalUtils.py +++ b/python/plugins/processing/algs/gdal/GdalUtils.py @@ -341,6 +341,11 @@ class GdalUtils: ogrstr += dsUri.table() format = 'OCI' + elif provider.lower() == "wfs": + uri = QgsDataSourceUri(layer.source()) + baseUrl = uri.param('url').split('?')[0] + ogrstr = "WFS:{}".format(baseUrl) + format = 'WFS' else: ogrstr = str(layer.source()).split("|")[0] path, ext = os.path.splitext(ogrstr) diff --git a/python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py b/python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py index c665365ba82..becffe5dba0 100644 --- a/python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py +++ b/python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py @@ -126,7 +126,7 @@ class Ogr2OgrTableToPostGisList(GdalAlgorithm): uri = GeoDB(uri=uri).uri inLayer = self.getParameterValue(self.INPUT_LAYER) - ogrLayer = GdalUtils.ogrConnectionStringFromLayer(inLayer) + ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing) shapeEncoding = self.getParameterValue(self.SHAPE_ENCODING) schema = str(self.getParameterValue(self.SCHEMA)) table = str(self.getParameterValue(self.TABLE)) @@ -161,7 +161,7 @@ class Ogr2OgrTableToPostGisList(GdalAlgorithm): arguments.append('"') arguments.append(ogrLayer) arguments.append('-nlt NONE') - arguments.append(GdalUtils.ogrLayerName(inLayer)) + arguments.append(layerName) if launder: arguments.append(launderstring) if append: @@ -175,7 +175,7 @@ class Ogr2OgrTableToPostGisList(GdalAlgorithm): elif primary_key is not None: arguments.append("-lco FID=" + primary_key) if len(table) == 0: - table = GdalUtils.ogrLayerName(inLayer).lower() + table = layerName.lower() if schema: table = '{}.{}'.format(schema, table) arguments.append('-nln') diff --git a/python/plugins/processing/algs/gdal/ogrinfo.py b/python/plugins/processing/algs/gdal/ogrinfo.py index 0bc2609bddb..d51657abed7 100644 --- a/python/plugins/processing/algs/gdal/ogrinfo.py +++ b/python/plugins/processing/algs/gdal/ogrinfo.py @@ -81,8 +81,9 @@ class ogrinfo(GdalAlgorithm): if inLayer is None: raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT)) - connectionString = GdalUtils.ogrConnectionStringFromLayer(inLayer) - arguments.append(connectionString) + ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing) + arguments.append(ogrLayer) + arguments.append(layerName) return [self.commandName(), GdalUtils.escapeAndJoin(arguments)] def processAlgorithm(self, parameters, context, feedback): diff --git a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py index cbbd59a150a..03552de825a 100644 --- a/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py +++ b/python/plugins/processing/tests/GdalAlgorithmsVectorTest.py @@ -113,7 +113,7 @@ class TestGdalVectorAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsT 'NO_METADATA': False}, context, feedback), ['ogrinfo', '-al -so ' + - source]) + source + ' polys2']) source = os.path.join(testDataPath, 'filename with spaces.gml') self.assertEqual( @@ -122,7 +122,7 @@ class TestGdalVectorAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsT 'NO_METADATA': False}, context, feedback), ['ogrinfo', '-al -so "' + - source + '"']) + source + '" filename_with_spaces']) source = os.path.join(testDataPath, 'filename with spaces.gml') self.assertEqual( @@ -131,7 +131,7 @@ class TestGdalVectorAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsT 'NO_METADATA': False}, context, feedback), ['ogrinfo', '-al "' + - source + '"']) + source + '" filename_with_spaces']) source = os.path.join(testDataPath, 'filename with spaces.gml') self.assertEqual( @@ -140,7 +140,7 @@ class TestGdalVectorAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsT 'NO_METADATA': True}, context, feedback), ['ogrinfo', '-al -so -nomd "' + - source + '"']) + source + '" filename_with_spaces']) def testBuffer(self): context = QgsProcessingContext()