Skip to content

Commit 0a365b2

Browse files
committedAug 13, 2017
Fix OGR algs always export shapefiles, regardless of output file extension
1 parent e33647d commit 0a365b2

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed
 

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,31 @@ def gdalHelpPath():
229229

230230
@staticmethod
231231
def ogrConnectionString(uri, context):
232-
"""Generates OGR connection sting from layer source
232+
"""Generates OGR connection string from layer source
233+
"""
234+
return GdalUtils.ogrConnectionStringAndFormat(uri, context)[0]
235+
236+
@staticmethod
237+
def ogrConnectionStringAndFormat(uri, context):
238+
"""Generates OGR connection string and format string from layer source
239+
Returned values are a tuple of the connection string and format string
233240
"""
234241
ogrstr = None
242+
format = None
235243

236244
layer = QgsProcessingUtils.mapLayerFromString(uri, context, False)
237245
if layer is None:
238-
return '"' + uri + '"'
246+
path, ext = os.path.splitext(uri)
247+
format = QgsVectorFileWriter.driverForExtension(ext)
248+
return '"' + uri + '"', format
239249

240250
provider = layer.dataProvider().name()
241251
if provider == 'spatialite':
242252
# dbname='/geodata/osm_ch.sqlite' table="places" (Geometry) sql=
243253
regex = re.compile("dbname='(.+)'")
244254
r = regex.search(str(layer.source()))
245255
ogrstr = r.groups()[0]
256+
format = 'SQLite'
246257
elif provider == 'postgres':
247258
# dbname='ktryjh_iuuqef' host=spacialdb.com port=9999
248259
# user='ktryjh_iuuqef' password='xyqwer' sslmode=disable
@@ -270,6 +281,7 @@ def ogrConnectionString(uri, context):
270281
QgsCredentials.instance().put(conninfo, user, passwd)
271282

272283
ogrstr = "PG:%s" % dsUri.connectionInfo()
284+
format = 'PostgreSQL'
273285
elif provider == "oracle":
274286
# OCI:user/password@host:port/service:table
275287
dsUri = QgsDataSourceUri(layer.dataProvider().dataSourceUri())
@@ -299,10 +311,13 @@ def ogrConnectionString(uri, context):
299311
ogrstr += dsUri.schema() + "."
300312

301313
ogrstr += dsUri.table()
314+
format = 'OCI'
302315
else:
303316
ogrstr = str(layer.source()).split("|")[0]
317+
path, ext = os.path.splitext(ogrstr)
318+
format = QgsVectorFileWriter.driverForExtension(ext)
304319

305-
return '"' + ogrstr + '"'
320+
return '"' + ogrstr + '"', format
306321

307322
@staticmethod
308323
def ogrLayerName(uri):

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ def getConsoleCommands(self, parameters, context, feedback):
8181

8282
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
8383

84-
output = GdalUtils.ogrConnectionString(outFile, context)
84+
output, format = GdalUtils.ogrConnectionStringAndFormat(outFile, context)
8585
options = self.parameterAsString(parameters, self.OPTIONS, context)
8686

8787
arguments = []
88+
if format:
89+
arguments.append('-f {}'.format(format))
8890
arguments.append(output)
8991
arguments.append(ogrLayer)
9092

0 commit comments

Comments
 (0)
Please sign in to comment.