Monday, 24 August 2015

postgis - Split Line at intersection and attach attributes


I want to slit line at intersection and attach attributes and export I have roads table with columns id,road_name,road_type,geom with 2115 records. I try using this query - select st_astext((st_dump(st_union(geom))).geom) from roads; it successfully splits the line gives 5114 records but when i am trying to attach attributes it fails select id,road_name,road_type,st_astext((st_dump(st_union(geom))).geom) from roads;


split at intersection


I need to split line at intersection also keep attributes means line 1 divide in 3 having same id is 1 , road_name is abc similar to line 2 divide in 2 having same id is 2 , road_name is xyz and so on.



Answer



You could also use PostGIS topologies, they do just that.


http://blog.mathieu-leplatre.info/use-postgis-topologies-to-clean-up-road-networks.html


You can join your road table on topology edges, using this query:


SELECT r.road_type, r.road_name, e.geom
FROM roads_topo.edge e,

roads_topo.relation rel,
roads r
WHERE e.edge_id = rel.element_id
AND rel.topogeo_id = (r.topo_geom).id

I will add that part to the article. Thanks for insisting btw, I could dig into topology internal tables and attributes :)


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