Wednesday, 21 December 2016

qgis - Split Lines at Intersection of Other Lines


I have two line layers (roads and contours in this example) and I would like to split the roads layer every time it crosses/intersects a feature on the contour layer. I can't seem to find a tool that does this, as the intersect tool is expecting a polygon for at least one of the layers. It also appears that GRASS' v.clean only works on a single layer. It seems like a simple task, but I'm at a loss!


EDIT (per comments below): Trying to get this to work in PostGIS now, and having some very strange results. If I do a subset of my dataset (one road, one contour that crosses it), and use the following SQL, I get the expected result, with the road split where the contour crosses it:


insert into "road_split"
select
(ST_Dump(st_split(r.geom,c.geom))).geom
from "road" r, "contour" c


However, if I do the exact same thing with the complete dataset, no roads are split. What am I doing wrong here?


I should note that all features in both the road and contour table are LINESTRINGS.



Answer



I would do the job with OpenJUMP and the Noder tool.


Open your line layers into OpenJUMP


enter image description here


Combine the layers for further processing


enter image description here


This tool will transform all the attributes from the source layers and add a new attribute "LAYER". That will be useful later.


enter image description here



Next use the Noder tool from the menu "Tools - Edit Geometry - Noder.."


enter image description here


Lines will be noded and split. A few split roads selected as a proof.


enter image description here


Finally you can extract the contours and roads back to their own layers by utilizing the LAYER attribute. OpenJUMP has an "Extract Layer by Attribute" tool in the Edit menu for this purpose.


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