Skip to content

Commit ed94b69

Browse files
committedJul 24, 2018
[processing][gdal] Fix layer paths are sometimes incorrect within command preview
Fixes #19451
1 parent 6a4d9c9 commit ed94b69

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed
 

‎python/plugins/processing/algs/gdal/GdalAlgorithm.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback,
103103
else:
104104
#not executing - don't worry about 'selected features only' handling. It has no meaning
105105
#for the command line preview since it has no meaning outside of a QGIS session!
106-
ogr_data_path = GdalUtils.ogrConnectionString(input_layer.dataProvider().dataSourceUri(), context)[1:-1]
106+
ogr_data_path = GdalUtils.ogrConnectionStringAndFormatFromLayer(input_layer)[0]
107107
ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
108108
else:
109109
# vector layer, but not OGR - get OGR compatible path
110110
# TODO - handle "selected features only" mode!!
111-
ogr_data_path = GdalUtils.ogrConnectionString(input_layer.dataProvider().dataSourceUri(), context)[1:-1]
111+
ogr_data_path = GdalUtils.ogrConnectionString(input_layer.dataProvider().dataSourceUri(), context)
112112
ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
113113
return ogr_data_path, ogr_layer_name
114114

‎python/plugins/processing/algs/gdal/GdalUtils.py

+4
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ def ogrConnectionStringAndFormat(uri, context):
278278
format = QgsVectorFileWriter.driverForExtension(ext)
279279
return uri, '"' + format + '"'
280280

281+
return GdalUtils.ogrConnectionStringAndFormatFromLayer(layer)
282+
283+
@staticmethod
284+
def ogrConnectionStringAndFormatFromLayer(layer):
281285
provider = layer.dataProvider().name()
282286
if provider == 'spatialite':
283287
# dbname='/geodata/osm_ch.sqlite' table="places" (Geometry) sql=

‎python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
130130
uri = GeoDB(uri=uri).uri
131131

132132
inLayer = self.getParameterValue(self.INPUT_LAYER)
133-
ogrLayer = GdalUtils.ogrConnectionString(inLayer, context)[1:-1]
133+
ogrLayer = GdalUtils.ogrConnectionString(inLayer, context)
134134
shapeEncoding = self.getParameterValue(self.SHAPE_ENCODING)
135135
schema = str(self.getParameterValue(self.SCHEMA))
136136
table = str(self.getParameterValue(self.TABLE))

‎python/plugins/processing/algs/gdal/rasterize_over.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
7878
inLayer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
7979
inRasterLayer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT_RASTER), context)
8080

81-
ogrLayer = GdalUtils.ogrConnectionString(inLayer, context)[1:-1]
82-
ogrRasterLayer = GdalUtils.ogrConnectionString(inRasterLayer, context)[1:-1]
81+
ogrLayer = GdalUtils.ogrConnectionString(inLayer, context)
82+
ogrRasterLayer = GdalUtils.ogrConnectionString(inRasterLayer, context)
8383

8484
arguments = []
8585
arguments.append('-a')

‎python/plugins/processing/tests/GdalAlgorithmsTest.py

+19
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
QgsGeometry,
6161
QgsPointXY,
6262
QgsProject,
63+
QgsVectorLayer,
6364
QgsRectangle,
6465
QgsProcessingException,
6566
QgsProcessingFeatureSourceDefinition)
@@ -154,6 +155,24 @@ def testGetOgrCompatibleSourceFromMemoryLayer(self):
154155

155156
QgsProject.instance().removeMapLayer(layer)
156157

158+
def testGetOgrCompatibleSourceFromOgrLayer(self):
159+
p = QgsProject()
160+
source = os.path.join(testDataPath, 'points.gml')
161+
vl = QgsVectorLayer(source)
162+
self.assertTrue(vl.isValid())
163+
p.addMapLayer(vl)
164+
165+
context = QgsProcessingContext()
166+
context.setProject(p)
167+
feedback = QgsProcessingFeedback()
168+
169+
alg = ogr2ogr()
170+
alg.initAlgorithm()
171+
path, layer = alg.getOgrCompatibleSource('INPUT', {'INPUT': vl.id()}, context, feedback, True)
172+
self.assertEqual(path, source)
173+
path, layer = alg.getOgrCompatibleSource('INPUT', {'INPUT': vl.id()}, context, feedback, False)
174+
self.assertEqual(path, source)
175+
157176
def testGetOgrCompatibleSourceFromFeatureSource(self):
158177
# create a memory layer and add to project and context
159178
layer = QgsVectorLayer("Point?field=fldtxt:string&field=fldint:integer",

0 commit comments

Comments
 (0)
Please sign in to comment.