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])
Based heavily on this great answer by @xunilk, you can create a custom script which allows you select a feature from a point layer and insert the height and width parameters. You can create a script by going to:
Processing Toolbox > Scripts > Tools > Create new script
Then use something like:
##Example=name
##Point_layer=vector point
##Height=number 1
##Width=number 1
from qgis.core import QgsVectorLayer, QgsFeature, QgsPoint, QgsRectangle, QgsGeometry, QgsMapLayerRegistry
point_layer = processing.getObject(Point_layer)
feats = [ feat for feat in point_layer.selectedFeatures() ]
epsg = point_layer.crs().postgisSrid()
uri = "Polygon?crs=epsg:" + str(epsg) + "&field=id:integer&field=x:real&field=y:real&field=point_id:integer""&index=yes"
mem_layer = QgsVectorLayer(uri, 'rectangular_buffer', 'memory')
prov = mem_layer.dataProvider()
for i, feat in enumerate(feats):
point = feat.geometry().asPoint()
new_feat = QgsFeature()
new_feat.setAttributes([i, point[0], point[1], feat.id()])
bbox = feat.geometry().buffer((Width/2), -1).boundingBox()
tmp_feat = bbox.asWktPolygon()
xmin1,ymin1,xmax1,ymax1 = bbox.toRectF().getCoords()
xmin2,ymin2,xmax2,ymax2 = feat.geometry().buffer((Height/2), -1).boundingBox().toRectF().getCoords()
p1 = QgsPoint(xmin1, ymax2)
p2 = QgsPoint(xmax1, ymin2)
new_ext = QgsRectangle(p1,p2)
new_tmp_feat = new_ext.asWktPolygon()
new_feat.setGeometry(QgsGeometry.fromWkt(new_tmp_feat))
prov.addFeatures([new_feat])
QgsMapLayerRegistry.instance().addMapLayer(mem_layer)
Make sure to save it in your /.qgis2/processing/scripts/
directory.
Example:
A simple point which has been added to the area of interest and selected. Then executing the custom script from the Processing Toolbox:
A rectangular buffer is created around the point based on the height and width parameters:
A quick check showing the perimeter (300 = (100 x 2) + (50 x 2)
):
You can also use the Measuring Tool to do a quick check for the height and width.
- Then copy the rectangle polygon to your main polygon layer.
Best Answer
Check the "Rectangles, Ovals, Diamonds (Variable)" geoalgorithm in the QGIS's Processing Toolbox (Ctrl+Alt+T)