Creating Polygon Shapefile from Point data using QGIS?
I generated a rectangle for each point in data according to your specification (rectangles of height = distance_f; width = swath; heading according to Track_deg). I got this result:
There is a problem with units, so feel free to change magic constants in width and height to achieve desired result.
How to reproduce result
- Open your .shp layer and make sure that is the only opened layer.
- Open Python console. Find button to "Open Editor" (it's easier to paste code into editor than to interpreter).
- Paste code from below and "Run script". After a while there should be a new layer named "poly", which will contain rectangles (each has attribute Rt_Apd_Liq).
Code:
import math
from PyQt4.QtCore import QVariant
def rotate(point, angle):
angle *= math.pi / 180.
px, py = point
qx = math.cos(angle) * px - math.sin(angle) * py
qy = math.sin(angle) * px + math.cos(angle) * py
return qx, qy
def translate(point, translation):
return point[0] + translation[0], point[1] + translation[1]
def rectangle(width, height, angle, center):
p1 = (-width/2, -height/2)
p2 = (-width/2, +height/2)
p3 = (+width/2, +height/2)
p4 = (+width/2, -height/2)
rotated = [rotate(p, angle) for p in [p1, p2, p3, p4]]
translated = [translate(p, center) for p in rotated]
points = [QgsPoint(x, y) for x, y in translated]
return points
in_layer = QgsMapLayerRegistry.instance().mapLayers().values()[0]
layer = QgsVectorLayer('Polygon?crs=epsg:4326', 'poly' , "memory")
pr = layer.dataProvider()
pr.addAttributes([QgsField("rate", QVariant.Double)])
layer.updateFields()
for feature in in_layer.getFeatures():
geom = feature.geometry()
p = geom.asPoint()
width = 0.8*0.3048 * feature.attribute('Swth_Wdth_') / 100000 # MAGIC
length = 1.2*0.3048 * feature.attribute('Distance_f') / 100000 # MAGIC
direction = feature.attribute('Track_deg_')
rate = feature.attribute('Rt_Apd_Liq')
center = (p.x(), p.y())
poly = QgsFeature()
points = rectangle(width, length, -direction, center)
poly.setGeometry(QgsGeometry.fromPolygon([points]))
poly.setAttributes([rate])
pr.addFeatures([poly])
layer.updateExtents()
QgsMapLayerRegistry.instance().addMapLayers([layer])