Skip to content
Permalink
Browse files

[processing] correctly handle layers without attributes in GDAL-based

geoprocessing algorithms (fix #17287)
  • Loading branch information
alexbruy committed Oct 23, 2017
1 parent 5261a9a commit 4a51c40821bc5adca738cab79b9b9c3672de8b7f
@@ -116,6 +116,11 @@ def getConsoleCommands(self, parameters, context, feedback):
continue
other_fields.append(f.name())

if other_fields:
other_fields = ', {}'.format(','.join(other_fields))
else:
other_fields = ''

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
@@ -124,9 +129,9 @@ def getConsoleCommands(self, parameters, context, feedback):
arguments.append('-sql')

if dissolve or fieldName:
sql = "SELECT ST_Union(ST_Buffer({}, {})) AS {}, {} FROM '{}'".format(geometry, distance, geometry, ','.join(other_fields), layerName)
sql = "SELECT ST_Union(ST_Buffer({}, {})) AS {}{} FROM '{}'".format(geometry, distance, geometry, other_fields, layerName)
else:
sql = "SELECT ST_Buffer({}, {}) AS {}, {} FROM '{}'".format(geometry, distance, geometry, ','.join(other_fields), layerName)
sql = "SELECT ST_Buffer({}, {}) AS {}{} FROM '{}'".format(geometry, distance, geometry, other_fields, layerName)

if fieldName:
sql = '{} GROUP BY {}'.format(sql, fieldName)
@@ -127,6 +127,11 @@ def getConsoleCommands(self, parameters, context, feedback):

other_fields.append(f.name())

if other_fields:
other_fields = ', {}'.format(','.join(other_fields))
else:
other_fields = ''

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
@@ -148,12 +153,12 @@ def getConsoleCommands(self, parameters, context, feedback):
params = ','.join(tokens)
if params:
if self.parameterAsBool(parameters, self.KEEP_ATTRIBUTES, context):
sql = "SELECT ST_Union({}) AS {}, {}, {} FROM {} GROUP BY {}".format(geometry, geometry, ','.join(other_fields), params, layerName, fieldName)
sql = "SELECT ST_Union({}) AS {}{}, {} FROM {} GROUP BY {}".format(geometry, geometry, other_fields, params, layerName, fieldName)
else:
sql = "SELECT ST_Union({}) AS {}, {}, {} FROM {} GROUP BY {}".format(geometry, geometry, fieldName, params, layerName, fieldName)
else:
if self.parameterAsBool(parameters, self.KEEP_ATTRIBUTES, context):
sql = "SELECT ST_Union({}) AS {}, {} FROM {} GROUP BY {}".format(geometry, geometry, ','.join(other_fields), layerName, fieldName)
sql = "SELECT ST_Union({}) AS {}{} FROM {} GROUP BY {}".format(geometry, geometry, other_fields, layerName, fieldName)
else:
sql = "SELECT ST_Union({}) AS {}, {} FROM {} GROUP BY {}".format(geometry, geometry, fieldName, layerName, fieldName)

@@ -97,14 +97,19 @@ def getConsoleCommands(self, parameters, context, feedback):
continue
other_fields.append(f.name())

if other_fields:
other_fields = ', {}'.format(','.join(other_fields))
else:
other_fields = ''

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')

sql = "SELECT ST_OffsetCurve({}, {}) AS {}, {} FROM '{}'".format(geometry, distance, geometry, ','.join(other_fields), layerName)
sql = "SELECT ST_OffsetCurve({}, {}) AS {}{} FROM '{}'".format(geometry, distance, geometry, other_fields, layerName)
arguments.append(sql)

if options:
@@ -126,6 +126,11 @@ def getConsoleCommands(self, parameters, context, feedback):
continue
other_fields.append(f.name())

if other_fields:
other_fields = ', {}'.format(','.join(other_fields))
else:
other_fields = ''

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
@@ -134,9 +139,9 @@ def getConsoleCommands(self, parameters, context, feedback):
arguments.append('-sql')

if dissolve or fieldName:
sql = "SELECT ST_Union(ST_SingleSidedBuffer({}, {}, {})) AS {}, {} FROM '{}'".format(geometry, distance, side, geometry, ','.join(other_fields), layerName)
sql = "SELECT ST_Union(ST_SingleSidedBuffer({}, {}, {})) AS {}{} FROM '{}'".format(geometry, distance, side, geometry, other_fields, layerName)
else:
sql = "SELECT ST_SingleSidedBuffer({}, {}, {}) AS {}, {} FROM '{}'".format(geometry, distance, side, geometry, ','.join(other_fields), layerName)
sql = "SELECT ST_SingleSidedBuffer({}, {}, {}) AS {}{} FROM '{}'".format(geometry, distance, side, geometry, other_fields, layerName)

if fieldName:
sql = '"{} GROUP BY {}"'.format(sql, fieldName)
@@ -102,14 +102,19 @@ def getConsoleCommands(self, parameters, context, feedback):
continue
other_fields.append(f.name())

if other_fields:
other_fields = ', {}'.format(','.join(other_fields))
else:
other_fields = ''

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')

sql = "SELECT ST_Line_Interpolate_Point({}, {}) AS {}, {} FROM '{}'".format(geometry, distance, geometry, ','.join(other_fields), layerName)
sql = "SELECT ST_Line_Interpolate_Point({}, {}) AS {}{} FROM '{}'".format(geometry, distance, geometry, other_fields, layerName)
arguments.append(sql)

if options:

0 comments on commit 4a51c40

Please sign in to comment.
You can’t perform that action at this time.