Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2014 07:19
Show Gist options
  • Save anonymous/8252660 to your computer and use it in GitHub Desktop.
Save anonymous/8252660 to your computer and use it in GitHub Desktop.
qgis python script to generate azimuth lines
#!/usr/bin/env python
import math
from qgis.core import *
from processing.core.VectorWriter import VectorWriter
##degspacing=number 30
##distance=number 20000000
##centerx=number 0.0
##centery=number 0.0
##output=output vector
##crsId=string USER:100001
def mkpoint(start, distace, bearing):
# bearing in radians
angle = math.radians(bearing)
dist_x, dist_y = (distance * math.sin(angle), distance * math.cos(angle))
xfinal, yfinal = (start.x() + dist_x, start.y() + dist_y)
# resulting point
return QgsPoint(xfinal, yfinal)
crs = QgsCoordinateReferenceSystem(crsId)
shapetype = QGis.WKBLineString
writer = VectorWriter(output, None, [], shapetype, crs)
start = QgsPoint(centerx,centery)
points = [mkpoint(start, distance, b) for b in xrange(0, 360, degspacing)]
lines = [QgsGeometry.fromPolyline([start, p]) for p in points]
for line in lines:
f = QgsFeature()
f.setGeometry(line)
writer.addFeature(f)
del writer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment