[Qgis-user] Re: how to rotate a line?
gene
martin.laloux at gmail.com
Wed May 9 23:29:28 PDT 2012
Hello,
In geology, I need to draw lines based on a direction and a distance
(euclidean).
I do it in the Python console and here is a part of one of my scripts that
might help you :
from numpy import *
class dist_angle(object):
def __init__(self,a,angle,distance):
self.a = a.asPoint()
self.xori = self.a[0]
self.yori = self.a[1]
self.angle = angle
self.distance = distance
self.x =0
self.y = 0
self.dist_x = 0
self.dist_y = 0
@property
def resultat(self):
self.dist_x, self.dist_x = (self.distance *
sin(radians(self.angle)),self.distance * cos(radians(self.angle)))
self.x, self.y = (self.xori + self.dist_x, self.yori +
self.dist_x)
return self.x, self.y
@property
def xfinal(self):
return self.resultat[0]
@property
def yfinal(self):
return self.resultat[1]
I use it as follow:
firstpoint = QgsGeometry.fromPoint(QgsPoint(231009.737,110767.821))
newpoint = dist_angle(firstpoint, 20, 100) #new point in a direction of 20°
and a distance of 100m
newpoint.xfinal
231103.70626207857
newpoint.yfinal
110861.79026207859
etc., you can continue from the new point.
after that, I can draw the line
def trace(self):
self.pr = self.vl.dataProvider()
fields = { 0 : QgsField("first", QVariant.Int) }
self.pr.addAttributes( [ QgsField("first", QVariant.Int)])
self.fet.setGeometry(QgsGeometry.fromPolyline( [
QgsPoint(self.xori , self.yori ), QgsPoint(self.x, self.y) ] ))
self.fet.setAttributeMap( { 0 : QVariant(1)} )
self.pr.addFeatures( [ self.fet ] )
self.vl.updateExtents()
self.vl.updateFieldMap()
QgsMapLayerRegistry.instance().addMapLayer(self.vl)
and points if i want
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/how-to-rotate-a-line-tp4963083p4964920.html
Sent from the Quantum GIS - User mailing list archive at Nabble.com.
More information about the Qgis-user
mailing list