# How to Simplify a Line Network Preserving Topology?

I have a Shapefile (consisting of European major roads) with about 250.000 Segments which I have to simplify for pgrouting. But I can't seem to find a way to do that properly.

This is what it looks like:

and this is what it should look like:

I somehow have to remove every Point of the Lines which is connected to less than 3 Lines (being not an intersection) while preserving the topological connections between the remaining points. If anybody has an idea, it would be greatly appreciated!

Best regards

EDIT: I tried to implement the idea of @dkastl and managed to get only the unneccessary nodes (nodes with only 2 adjacent linestrings) from my network with the code below (network generation taken from underdark's blog http://underdark.wordpress.com/2011/02/07/a-beginners-guide-to-pgrouting/):

``````SELECT * FROM
(SELECT tmp.id as gid, node.the_geom FROM
(SELECT id, count(*) FROM network
JOIN node
ON (start_id = id OR end_id = id) AND (end_id = id OR start_id = id)
GROUP BY id ORDER BY id) as tmp
JOIN node ON (tmp.id = node.id)
WHERE tmp.count = 2) as unn_node;
``````

So, all I now have to do is the merging of the lines. However, I have no clue how. I imagine it has to be a loop which for every row of the result of above query gets the adjacent lines and merges them. Then it would rebuild the network completely and repeat the process until the query above returns an empty result.

• Why do you have to do this for pgRouting? If you already have source/target ID assigned you can create a new geometry with linestrings only contain source and target ID. That should look like your second image. – dkastl Apr 14 '12 at 6:05
• The problem is that the lines are segmented (if you look at the first image I posted, every point you see starts/ends a new segment), your approach simplifies the geometry (which is good) but not the topology. – chriserik Apr 15 '12 at 11:23
• I don't think it's obvious from your image that each point starts a new linestring geometry. Did you already run pgRouting's assign_vertex_id function to fill source/target columns? In that case you may later do some queries to identify source/target ID's that only exist twice, which means that you should be able to merge the two line segments at this point. In case source/target ID exist more that two times it must be an intersection. – dkastl Apr 16 '12 at 0:23
• @dkastl : A very good idea! I updated my question showing how far i got with it. – chriserik Apr 20 '12 at 11:21