Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to join linestrings which are connected to each other. The preferred output is a longer linestring based on all joined single linestings! The table that holds my single linestrings is called “traffic_roads_temp”. Each linestring has the attribute ref. Ref describes in my table the affiliation to a certain motorway or road.

As you can see in the picture below the motorway A 2 and A 7 could be easily joined by using something like this:

select ref, st_linemerge(st_collect(way)) from traffic_roads_temp group by ref

One of the problem is, that the output seems to be a multilinestring and not a linestring.

The main problem is the motorway A 39. It consists out of two separated road segments. Therefor I would like to generate two linestrings of the A 39 --> A 39.1 and A 39.2 All other motorways could be stored in one linestring per motorway.

Maybe somebody of the experts in this forum could help me to solve this problem(s):

  1. Generate long linestrings from single smaller linestring. (No multilinestring)

  2. I case of the motorway A 39 which consists out of two spread road parts – I would like to generate something like a series: A 39.1 and A 39.2


enter image description here

share|improve this question
It seems that you need only a query that generates the start and end point and all segments that contatin the route, perhaps give it an alternate name to be used for the thru route. I don't know postgis syntax but say (linestring = start xy and name = x or name = b and ref = aa or ref = ab and linestring = end xy = (') and string = (0 0, 1 1, 2 1, 2 2)') = linestring " ". That said maybe you could select your string in a gui and then export or decompose the selection to get working values to reverse engineer your solution. – lewis Feb 22 '13 at 20:03
Maybe a litte bit more practical solution for my problem? Anybody? Thanks in advance!!! – user15454 Feb 23 '13 at 20:58
i want to solution for same ... if any one have practical implementation... – yogesh prajapati Apr 9 '13 at 16:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.