Hi Alessandro,
you may use an edited version of the code that I posted for answering to a
GIS StackExchange question (linked here
<http://gis.stackexchange.com/questions/228419/connecting-points-to-polygon-edges-using-angular-bearing>
).

I slightly edited it for you, but refers to the answer from GIS SE for a
better understanding (remember to adapt the field names in the code to your
specifi case):

####### CODE STARTS HERE ###########

##Points=vector point

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

p_layer = processing.getObject(Points)
crs = p_layer.crs().toWkt()

# Create the output layer
outLayer = QgsVectorLayer('Linestring?crs='+ crs, 'land' , 'memory')
prov = outLayer.dataProvider()
fields = p_layer.pendingFields()
prov.addAttributes(fields)
outLayer.updateFields()

for feat in p_layer.getFeatures():
    attrs = feat.attributes()
    point = feat.geometry().asPoint()
    points = [feat.geometry().asPoint()]
    angle = math.radians(90-(feat["azimuth"]))
    tmp_len = (feat["length"])
    dist_x, dist_y = (tmp_len * math.cos(angle), tmp_len * math.sin(angle))
    point2 = QgsPoint(point[0] + dist_x, point[1] + dist_y)
    points.append(point2)
    outFeat = QgsFeature()
    outFeat.setAttributes(attrs)
    outFeat.setGeometry(QgsGeometry.fromPolyline(points))
    prov.addFeatures([outFeat])

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

####### CODE ENDS HERE ###########

Marco Grisolia

2017-02-15 10:41 GMT+01:00 <alessandro.confo...@cnr.it>:

>
> Hi to all Qgis user,
> I've a question for you guys:
> I've a point shape file, in the features table 'i've a field with the
> azimut value in degree and another field with a lenth in meters.
> i would like to produce a new line shape file with a vector tha has origin
> on the point azimut from the azimut field table and length from lenght
> value in metres.
> Sonbody can help me?
> thanks in advance
> Ale
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to