Created
January 4, 2014 07:19
-
-
Save anonymous/8252660 to your computer and use it in GitHub Desktop.
qgis python script to generate azimuth lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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