Skip to content

Instantly share code, notes, and snippets.

@n1ywb
Forked from anonymous/genazlines.py
Created January 4, 2014 08:28
Show Gist options
  • Save n1ywb/8253057 to your computer and use it in GitHub Desktop.
Save n1ywb/8253057 to your computer and use it in GitHub Desktop.
import math
from qgis.core import *
from processing.core.VectorWriter import VectorWriter
##degspacing=number 30
##distance=number 5000000
##numrings=number 4
##centerx=number 0.0
##centery=number 0.0
##output=output vector
##crsId=string USER:100001
def mkpoint(start, distance, 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*numrings, b) for b in xrange(0, 360, degspacing)]
lines = [QgsGeometry.fromPolyline([start, p]) for p in points]
for n in xrange(1, numrings+1):
buf = QgsGeometry.fromPoint(start).buffer(distance * n, 25)
lines.append(buf)
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