Geographic Information Systems Asked by hexamon on January 11, 2021
I have a line layer that I want to rasterize. I run the Rasterize (vector to raster) tool in QGIS Processing to do so. However, the output is lacking in that it doesn’t capture each cell that the line layer touches. See image below.
So, how can I rasterize a line layer in QGIS and make sure all intersected cells are given a value?
This can be achieved by converting your lines to polygons using the Vector-->Geoprocessing Tools-->Buffer tool and then rasterizing the buffer layer instead.
When polygons are rasterized, it seems the cell center needs to be covered by a polygon in order to be assigned values from the vector layer. So the trick would be to use a buffer size that is just more than half the diagonal of your intended cell cize.
So, assuming your intended cell size is 1 m, the buffer size could be set to sqrt(2 * cellsize^2) / 2
rounded up to the desired precision.
EDIT: A tip for the buffer tool parameters is to use round
for both End cap style and for the Join style and to set the segments
parameter sufficiently high to lower the risk of "missing" some cell center points.
EDIT2: While this approach would not "miss" any cells touched by the line, almost vertical/horizontal lines would assign values to cells on both sides of the lines, causing "thicker" lines in the resulting raster. So this approach assigns values to more cells than only those intersected by by the lines.
Answered by MattiasSp on January 11, 2021
Previous answer by MattiasSp left me with a raster that still had "holes" in it, corresponding to lines that hadn't been properly "rasterized".
Here, I propose an alternative solution using a vectorial grid in QGIS, that is still pretty quick to do.
This should give you a raster where every cell corresponded to a cell that was touching a line one way or another.
Answered by Gwynbleidd on January 11, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP