Skip to content

Commit

Permalink
[processing] refactor ogr buffer algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Sep 16, 2016
1 parent 448961b commit 8bf95fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
45 changes: 21 additions & 24 deletions python/plugins/processing/algs/gdal/ogr2ogrbuffer.py
Expand Up @@ -75,43 +75,40 @@ def defineCharacteristics(self):

def getConsoleCommands(self):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
layername = "'" + ogrLayerName(inLayer) + "'"
geometry = unicode(self.getParameterValue(self.GEOMETRY))
distance = unicode(self.getParameterValue(self.DISTANCE))
geometry = self.getParameterValue(self.GEOMETRY)
distance = self.getParameterValue(self.DISTANCE)
dissolveall = self.getParameterValue(self.DISSOLVEALL)
field = unicode(self.getParameterValue(self.FIELD))
field = self.getParameterValue(self.FIELD)
multi = self.getParameterValue(self.MULTI)
options = self.getParameterValue(self.OPTIONS)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
layername = ogrLayerName(inLayer)

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value

output = ogrConnectionString(outFile)
options = unicode(self.getParameterValue(self.OPTIONS))

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append(ogrLayerName(inLayer))
if dissolveall or field != 'None':
arguments.append('-dialect sqlite -sql "SELECT ST_Union(ST_Buffer(')
else:
arguments.append('-dialect sqlite -sql "SELECT ST_Buffer(')
arguments.append(geometry)
arguments.append(',')
arguments.append(distance)
if dissolveall or field != 'None':
arguments.append(')),*')
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')

if dissolveall or field is not None:
sql = "SELECT ST_Union(ST_Buffer({}, {})), * FROM '{}'".format(geometry, distance, layername)
else:
arguments.append('),*')
arguments.append('FROM')
arguments.append(layername)
if field != 'None':
arguments.append('GROUP')
arguments.append('BY')
arguments.append(field)
arguments.append('"')
if field != 'None' and multi:
sql = "SELECT ST_Buffer({}, {}), * FROM '{}'".format(geometry, distance, layername)

if field is not None:
sql = '{} GROUP BY {}'.format(sql, field)

arguments.append(sql)

if field is not None and multi:
arguments.append('-explodecollections')

if len(options) > 0:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/onesidebuffer.py
Expand Up @@ -89,7 +89,7 @@ def getConsoleCommands(self):
options = self.getParameterValue(self.OPTIONS)

ogrLayer = ogrConnectionString(inLayer)[1:-1]
layername = "'" + ogrLayerName(inLayer) + "'"
layername = ogrLayerName(inLayer)

output = self.getOutputFromName(self.OUTPUT_LAYER)
outFile = output.value
Expand Down

0 comments on commit 8bf95fe

Please sign in to comment.