7

I've got some linestrings covering a road network, and need to split them at the crossroads. Does anybody have any idea on how to do it?

I'm using QGIS 2.4, with a Postgis 2.1.3.

  • Do you not already have vertices at road intersections or do you really have intersecting lines because that would be fairly unusual for a road network. Where did you get the data? Did you digitize it yourself? Are the roads contained in a single file or across multiple files? – WhiteboxDev Oct 2 '14 at 14:23
  • @WhiteboxDev some roads can cross (if they are superimposed) without intersection like where there is viaducts. Maybe it is important for his analysis to split those roads anyway. – Below the Radar Oct 2 '14 at 14:32
  • 3
    @BelowtheRadar I'm not saying it's not important; clearly it is. I'm just trying to get my head around the kind of data the OP is handling; where it came from...how it's structured, that sort of thing. Knowing this can help people to produce better answers for the OP. – WhiteboxDev Oct 2 '14 at 14:36
  • 1
    I have two datasets, one from major avenues, that is already split at crossings (giving me features 1st_ave_1, 1st_ave_2 and so on), and one probably digitized from city maps, in which every feature is an full street. I haven't digitized any of them – ebarbara Oct 2 '14 at 14:57
5

There is few resolutions of this issue, maybe there are few better ones but this two should do also:

'By hand' (in steps)

Cut every line with another line which intersects it

Create table road_1 as 
  Select 
    row_number() over() as ID,
    input.name,
    (st_dump(st_split(input.geom, blade.geom))).geom as geom
  from roads input
  join roads blade on st_intersects(input.geom, blade.geom);

Now you've got few too much lines cause every time you're splitting one line into 2 parts, so you have to delete all lines that are covering another smaller ones (Thats why ST_NODE exists)

delete from road_1 a
where exists 
  (
  select 1 from road_1 b where a.id != b.id and st_coveredby(b.geom,a.geom)
  );

Automagically

Splitting every line in point of intersection with another line is one of things you have to do to create road topology so maybe it'll be easiest to get familiar with function pgr_createTopology of PG Routing project.

This workshop could be helpfull

0

You can use PostGIS ST_NODE function

or if you have PostGIS > 2.0 and want to do a cleaner job considering topology, you can follow instructions in this blog

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.