Hi Azzurra,

Are you sure that you aren't using Offset Curve (ST_OffsetCurve) operation,
instead of Singe Side Buffer (ST_SingleSidedBuffer) operation?

By the way, Offset Curve operation is broken in QGIS 2.18.x. If you want,
you can overwrite
../python/plugins/processing/algs/gdal/ogr2ogronesidebuffer.py file by the
one attached to this email.

This problem was already fixed in master by Alexander Bruy, using a
different approach than mine, spliting the operations. I think this change
should be backported Alexander, what you think? Or should I make a pull
request to QGIS 2.18.x with this change on ogr2ogronesidebuffer?

Best regards,
Pedro Venâncio




2016-12-19 21:44 GMT+00:00 Azzurra Lentini <azzurralent...@gmail.com>:

> Thanks Nyall.
>
> I dont know why but  GDAL SINGLE SIDED BUFFER it doesnt work really well.
> The result of this buffer is a line and not a polygone (the line is the
> same of the input file!!)
>
> I just put my input file and 150 m for the distance buffer for the left
> side.
> Thanks,
> ​A.L.​
>
>
> 2016-12-19 20:19 GMT+01:00 Nyall Dawson <nyall.daw...@gmail.com>:
>
>>
>>
>> On 20 Dec 2016 05:06, "Azzurra Lentini" <azzurralent...@gmail.com> wrote:
>>
>> Dear all I have a layer shapefile lines with around 30 lines.
>>
>> I need a buffer of one of these  lines with 2 different values of buffer
>> distance: 150 m on the left and 30 m on the right.
>>
>> Which kind of buffer option can I use??
>>
>> I know only single sided buffers but with this option I need to  repeat
>> the buffer for every side.
>>
>>
>> Buffer the left and right sides separately using single sided buffer,
>> then merge the resulting output and dissolve them based on a unique
>> identifier.
>>
>> Nyall
>>
>>
>>
>>
>> Thanks to all, A.L:
>>
>> --
>> Dr. Hydrogeologist
>> AZZURRA LENTINI
>> Expert of evaluation environmental hazards
>> GIS application
>> Haity Mobile Tel: 0050946057393 <+509%2046%2005%207393>
>> ++++++++++++++++++++++++++
>> Italy Mobile Tel.: **(39) 338 24 40 676
>> ++++++++++++++++++++++++++
>> SKYPE azzurrahydro
>> ++++++++++++++++++++++++++
>> azzurralent...@gmail.com
>> ++++++++++++++++++++++++++
>> *Par respect pour l'environnement,*
>>
>> *n'imprimez ce mail qu'en cas d'absolue nécessité*
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user@lists.osgeo.org
>> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>>
>>
>>
>
>
> --
> Dr. Hydrogeologist
> AZZURRA LENTINI
> Expert of evaluation environmental hazards
> GIS application
> Haity Mobile Tel: 0050946057393 <+509%2046%2005%207393>
> ++++++++++++++++++++++++++
> Italy Mobile Tel.: **(39) 338 24 40 676
> ++++++++++++++++++++++++++
> SKYPE azzurrahydro
> ++++++++++++++++++++++++++
> azzurralent...@gmail.com
> ++++++++++++++++++++++++++
> *Par respect pour l'environnement,*
>
> *n'imprimez ce mail qu'en cas d'absolue nécessité*
>
>
>
>
>
>
>
>
>
> --
> Dr. Hydrogeologist
> AZZURRA LENTINI
> Expert of evaluation environmental hazards
> GIS application
> Haity Mobile Tel: 0050946057393 <+509%2046%2005%207393>
> ++++++++++++++++++++++++++
> Italy Mobile Tel.: **(39) 338 24 40 676
> ++++++++++++++++++++++++++
> SKYPE azzurrahydro
> ++++++++++++++++++++++++++
> azzurralent...@gmail.com
> ++++++++++++++++++++++++++
> *Par respect pour l'environnement,*
>
> *n'imprimez ce mail qu'en cas d'absolue nécessité*
>
>
>
>
>
>
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user
>
# -*- coding: utf-8 -*-

"""
***************************************************************************
    ogr2ogronesidebuffer.py
    ---------------------
    Date                 : Janaury 2015
    Copyright            : (C) 2015 by Giovanni Manghi
    Email                : giovanni dot manghi at naturalgis dot pt
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************
"""

__author__ = 'Giovanni Manghi'
__date__ = 'January 2015'
__copyright__ = '(C) 2015, Giovanni Manghi'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterString
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterSelection
from processing.core.outputs import OutputVector

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils

from processing.tools.system import isWindows
from processing.tools.vector import ogrConnectionString, ogrLayerName


class Ogr2OgrOneSideBuffer(GdalAlgorithm):

    OUTPUT_LAYER = 'OUTPUT_LAYER'
    INPUT_LAYER = 'INPUT_LAYER'
    OPERATION = 'OPERATION'
    OPERATIONLIST = ['Single Side Buffer', 'Offset Curve']
    GEOMETRY = 'GEOMETRY'
    RADIUS = 'RADIUS'
    LEFTRIGHT = 'LEFTRIGHT'
    LEFTRIGHTLIST = ['Right', 'Left']
    DISSOLVEALL = 'DISSOLVEALL'
    FIELD = 'FIELD'
    MULTI = 'MULTI'
    OPTIONS = 'OPTIONS'

    def defineCharacteristics(self):
        self.name, self.i18n_name = self.trAlgorithm('Single sided buffers (and offset lines) for lines')
        self.group, self.i18n_group = self.trAlgorithm('[OGR] Geoprocessing')

        self.addParameter(ParameterVector(self.INPUT_LAYER,
                                          self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_LINE], False))
        self.addParameter(ParameterSelection(self.OPERATION,
                                             self.tr('Operation'), self.OPERATIONLIST, 0))
        self.addParameter(ParameterString(self.GEOMETRY,
                                          self.tr('Geometry column name ("geometry" for Shapefiles, may be different for other formats)'),
                                          'geometry', optional=False))
        self.addParameter(ParameterString(self.RADIUS,
                                          self.tr('Buffer distance'), '1000', optional=False))
        self.addParameter(ParameterSelection(self.LEFTRIGHT,
                                             self.tr('Buffer side'), self.LEFTRIGHTLIST, 0))
        self.addParameter(ParameterBoolean(self.DISSOLVEALL,
                                           self.tr('Dissolve all results'), False))
        self.addParameter(ParameterTableField(self.FIELD,
                                              self.tr('Dissolve by attribute'), self.INPUT_LAYER, optional=True))
        self.addParameter(ParameterBoolean(self.MULTI,
                                           self.tr('Output as singlepart geometries (only used when dissolving by attribute)'), False))
        self.addParameter(ParameterString(self.OPTIONS,
                                          self.tr('Additional creation options (see ogr2ogr manual)'),
                                          '', optional=True))

        self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Single sided buffer')))

    def getConsoleCommands(self):
        inLayer = self.getParameterValue(self.INPUT_LAYER)
        operation = self.getParameterValue(self.OPERATION)
        geometry = self.getParameterValue(self.GEOMETRY)
        distance = self.getParameterValue(self.RADIUS)
        leftright = self.getParameterValue(self.LEFTRIGHT)
        dissolveall = self.getParameterValue(self.DISSOLVEALL)
        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)

        layername = ogrLayerName(inLayer)

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

        if dissolveall or field is not None:
            if operation == 0:
                sql = "SELECT ST_Union(ST_SingleSidedBuffer({}, {}, {})), * FROM '{}'".format(geometry, distance, leftright, layername)
            else:
				if leftright:
					sql = "SELECT ST_Union(ST_OffsetCurve({}, {})), * FROM '{}'".format(geometry, distance, layername)
				else:
					sql = "SELECT ST_Union(ST_OffsetCurve({}, -{})), * FROM '{}'".format(geometry, distance, layername)
        else:
            if operation == 0:
                sql = "SELECT ST_SingleSidedBuffer({},{},{}), * FROM '{}'".format(geometry, distance, leftright, layername)
            else:
				if leftright:
					sql = "SELECT ST_OffsetCurve({}, {}), * FROM '{}'".format(geometry, distance, layername)
				else:
					sql = "SELECT ST_OffsetCurve({}, -{}), * 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:
            arguments.append(options)

        commands = []
        if isWindows():
            commands = ['cmd.exe', '/C ', 'ogr2ogr.exe',
                        GdalUtils.escapeAndJoin(arguments)]
        else:
            commands = ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]

        return commands

    def commandName(self):
        return 'ogr2ogr'
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to