Skip to content

Commit

Permalink
Merge pull request qgis#31735 from alexbruy/fix-29663
Browse files Browse the repository at this point in the history
[processing] add support for WFS as input (fix qgis#29663)
  • Loading branch information
alexbruy authored Sep 17, 2019
2 parents 6942b4b + c7c91de commit 27b576c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
8 changes: 7 additions & 1 deletion python/plugins/processing/algs/gdal/GdalAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
QgsProcessingAlgorithm,
QgsProcessingContext,
QgsProcessingFeedback,
QgsProviderRegistry)
QgsProviderRegistry,
QgsDataSourceUri)

from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
from processing.algs.gdal.GdalUtils import GdalUtils
Expand Down Expand Up @@ -115,6 +116,11 @@ def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback,
#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!!
Expand Down
5 changes: 5 additions & 0 deletions python/plugins/processing/algs/gdal/GdalUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ def ogrConnectionStringAndFormatFromLayer(layer):

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
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))
Expand Down Expand Up @@ -161,7 +161,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('"')
arguments.append(ogrLayer)
arguments.append('-nlt NONE')
arguments.append(GdalUtils.ogrLayerName(inLayer))
arguments.append(layerName)
if launder:
arguments.append(launderstring)
if append:
Expand All @@ -175,7 +175,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
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')
Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/algs/gdal/ogrinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
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):
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/tests/GdalAlgorithmsVectorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def testOgrInfo(self):
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-al -so ' +
source])
source + ' polys2'])

source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
Expand All @@ -122,7 +122,7 @@ def testOgrInfo(self):
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-al -so "' +
source + '"'])
source + '" filename_with_spaces'])

source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
Expand All @@ -131,7 +131,7 @@ def testOgrInfo(self):
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-al "' +
source + '"'])
source + '" filename_with_spaces'])

source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
Expand All @@ -140,7 +140,7 @@ def testOgrInfo(self):
'NO_METADATA': True}, context, feedback),
['ogrinfo',
'-al -so -nomd "' +
source + '"'])
source + '" filename_with_spaces'])

def testBuffer(self):
context = QgsProcessingContext()
Expand Down

0 comments on commit 27b576c

Please sign in to comment.