Sunday 6 January 2019

polygon - Creating flat end buffer using geometry generator in QGIS?


I'm new to GIS software and I've been introduced to QGIS 2.18 as part of my internship.


I was tasked with creating new styles for the company's maps, however I've encountered a problem with one of the requested styles.


I was to create a style for a line that would create a buffer for a line and then apply a gradient depending on the angle of the line (This part I manage to get using geometry generator). However, it returns the line buffers as an oval and I would like it to be flat ended (take a shape as a rectangle).


I am aware that v.buffer.distance allows for creation of flat-ends but I'm hoping for the same result but by using geometry generator so that it could be saved as a style.


Buffer, and bounds(Buffer example



The picture above shows what I've managed to create the buffer($geometry,0.05) vs the bounds method in Using QGIS Geometry Generator to get rectangle from point?


To specify again, I want to rectangularize(?) the result I got from buffer($geometry, 0.05)



Answer



You can create a virtual layer that transforms your line into a polygon. You would then style this new layer.


Go to layer / add layer / add - edit virtual layer and type the following query. Rename a by your line layer, and add fields as needed. 0.01 is the 1/2 buffer size (here in degrees) and the ending 0 / 1 is for right or left side.


You can at the same time compute the line azimuth (angle between the horizontal and the 1st/last point of the line, expressed in radians)


select id, 
st_union(ST_SingleSidedBuffer(geometry,0.01,0) , ST_SingleSidedBuffer(geometry,0.01,1)),
st_azimuth(st_startpoint(geometry),st_endpoint(geometry)) azim
from a


enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...