Saturday, 17 March 2018

Split polylines at a specific distance in QGIS / ogr2ogr



Similar to this question I have a set of polylines that I need to be split by a equal distance. How do I do this with QGIS, gdal/ogr2ogr and other open source tools (on Mac)? I don't have access to ArcGIS, therefore not a duplicate question, I hope.


I figured out to extract the coordinates at a specific distance from start of a line with this in QGIS (1000 m from start):


 x(line_interpolate_point($geometry, 1000))
y(line_interpolate_point($geometry, 1000))

From there I'm not sure how to continue.


I need this to be able to create points along contour lines where I can extract angle and elevation value (from attribute). See this question and answer where I need this information.



Answer



There is a GRASS plugin under QGIS to split the polyline by specific length. The tool "v.split.length - Split lines to shorter segments by length" does exactly what you are asking for, as you can see below:


enter image description here



Under the Maximum segment length, you need to specify the desired length. In this example it is specified every 500 meters.


Before split:


enter image description here


After applying split tool:


enter image description here


You need to make sure that your data is projected to a suitable spatial reference that uses meters or feet. However, it may not give the desired length if the lines are complex or have some topological errors.


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...