Tuesday 20 August 2019

grass - splitting a lines layer using points


I'm looking to accomplish a similar task to this thread: Splitting line at point positions using QGIS?


Using QGIS and the Processing and GRASS toolboxes available, I'm looking to split a vector layer representing a hydrolic network at points which represent junctions. I've been told v.distance exists in Processing as well, but I can't access it. Using GRASS v.distance, I get the error notice that not enough columns are available.



Answer



When importing a line vector into GRASS, the topology cleaning automatically splits lines at every intersection. If you need to split lines at additional points, you can use


v.edit

The tool=break is what you need, and the "coords" parameter is for the X-Y of the point to split. If you have the coordinates of all your "junctions" then feed those in a loop into the v.edit command. You might do this by dumping the X-Y coordinates of the junctions into a text file with v.out.ascii. Then read the text file, line by line, in a bash loop, something like:


v.out.ascii junctions separator=" " out=junction_coords.txt

while read x y cat; do \
v.edit map=hydro_network tool=break coords=$x,$y; \
done < junction_coords.txt

BTW, if the junction points are not exactly on the line, you will want to look into the combination of:


v.distance
v.patch
v.clean

This procedure creates small connector lines from the jucntion points to the hydro_network, then by patching these connectors to the network, and running v.clean, you get an "error" output point vector which is the intersection points of each connector and the original hydro_network. THis way you can get a new set of "snapped" junction points which fall exactly on the hydro_network.



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