I solved both cases of the previous email.
If you want to buffer starting from a specified distance stored in a field,
please have a look on this post [0] (written by me):

[0] https://howtoinqgis.wordpress.com/2016/11/28/how-to-buffer-v
ectors-from-fields-in-qgis-using-python/

If you want to directly buffer (for your specific case) without any
preliminary edit on the layer, copy&paste the code at the end of this
email: it was adapted from the link above (please refer to it for a clear
comprehension)

For both cases, you may decide to buffer all the features or only the
selected ones.
I hope it would be useful.
Best regards,
Marco

******** code below ********

##Input_Layer=vector
##Segments=number 30
##Buffer_only_selected_features=Boolean False

from qgis.core import *
from qgis.PyQt.QtCore import QVariant
import math

layer = processing.getObject(Input_Layer)
crs = layer.crs().toWkt()

# Create a dictionary with the preferred distances
distances = {'normal fault': 30, 'inverse fault': 20, 'Overthrust': 50,
'Syncline': 20}

# Create the output layer
outLayer = QgsVectorLayer('Polygon?crs='+ crs, 'outLayer' , 'memory')
prov = outLayer.dataProvider()
fields = layer.pendingFields() # Fields from the input layer
#fields.append(QgsField('drawn_area', QVariant.Double, '', 10, 3))
prov.addAttributes(fields) # Add input layer fields to the outLayer
outLayer.updateFields()

# Check for selected features
if layer.selectedFeatures() and Buffer_only_selected_features is True:
    features = layer.selectedFeatures()
else:
    features = layer.getFeatures()

# Generate buffers
for feat in features:
    inAttr = feat.attributes() # Input attributes
    inGeom = feat.geometry() # Input geometry
    bf_inGeom = inGeom.buffer(distances[feat['type']], Segments)
    poly=bf_inGeom.asPolygon()
    drawn_area = bf_inGeom.area()
    inAttr.append(drawn_area)
    outGeom = QgsFeature()
    outGeom.setGeometry(QgsGeometry.fromPolygon(poly))
    outGeom.setAttributes(inAttr) # Output attributes
    prov.addFeatures([outGeom]) # Output geometry

# Add the layer to the Layers panel
QgsMapLayerRegistry.instance().addMapLayer(outLayer)

******** end of the code ********


2016-11-27 20:11 GMT+01:00 Marco Grisolia <marco.grisol...@gmail.com>:

> Don't worry for the delay...
> Your goal is to generate the buffer a priori (i.e. by assigning a
> specific value of radius for each feature, without any preliminary
> edit on the layer) or by searching for it in a field of the layer
> (i.e. as Randal Hale suggested)?
> Marco
>
> 2016-11-27 18:54 GMT+01:00 Azzurra Lentini <azzurralent...@gmail.com>:
> > Dear Marco, apologies to write you only now.
> > Yes with variable distance buffer is fine. Thanks a lot.
> >
> > If you can, could you please write me the PyQgis script for the other
> > option?
> >
> > all regards, Azzurra
> >
> > 2016-11-16 9:22 GMT+01:00 Marco Grisolia <marco.grisol...@gmail.com>:
> >>
> >> If you want to assign a specified buffer for each kind of feature, you
> >> may use a simple PyQGIS script using a call of buffer() from
> >> QgsGeometry(). Are you able to do it? Otherwise I may try to write it
> >> for you if my understanding of the problem was right.
> >> Therefore, if your buffer distances are inside a field, you may use
> >> the "Variable Distance Buffer" algorithm from Processing.
> >> Best regards,
> >> Marco
> >>
> >> 2016-11-16 1:26 GMT+01:00 Azzurra Lentini <azzurralent...@gmail.com>:
> >> > Dear all,
> >> >
> >> > I have a shape file with a field called “type”.  In the “type”  field
> I
> >> > have
> >> > 4 kinds of samples ( 19 records).
> >> >
> >> > See in the attachment.
> >> >
> >> > The 4 samples are: normal fault, inverse fault, overthrust, syncline.
> >> >
> >> > I would like to create a buffer with different distance for each
> sample
> >> > (the
> >> > best it would be to obtain a shape with 5 different buffer distances).
> >> >
> >> > For example  the buffer distance for the sample “ normal fault” is 30
> m,
> >> > for
> >> > the “inverse fault “ is 20 m, for the “overthrust” is 50 m and for the
> >> > “syncline” is 20 m.
> >> >
> >> >
> >> >
> >> > How I can do this kind of buffer??
> >> >
> >> >
> >> >
> >> > Thanks A.L.
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > Dr. Hydrogeologist
> >> > AZZURRA LENTINI
> >> > Expert of evaluation environmental hazards
> >> > GIS application
> >> > Haity Mobile Tel: 0050946057393
> >> > ++++++++++++++++++++++++++
> >> > 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
> > ++++++++++++++++++++++++++
> > 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

Reply via email to