[GIS] Converting lines to polylines with PostGIS/QGIS

polyline-creationpostgisqgis

I have a PostGIS table containing linestrings. Some of these are parts of larger logical constructs (tracks, roads or boundaries). I have been going though the data using snapping tools to make sure that that coordinates match up properly.

I now want to change my "tracks" layer to have polyline features, one for each logical track so I can label them on the maps and export them to GPS as a single named entity, or convert them to a route.

I am pretty sure that the answer will involve ST_MakeLine but I cannot see how construct the query?

The line table has an attribute 'part_of' which has the name of the logical entity and a sequence attribute too.

Pointers to a good basic tutorial on working with various geometric constructs would be useful.

Best Answer

ST_UNION is what you are looking for: https://postgis.net/docs/ST_Union.html

However, if you've already cleaned up your data, it may be faster to use ST_COLLECT: https://postgis.net/docs/ST_Collect.html

Both will achieve what you are trying to do - create multilinestrings from linestrings

ST_UNION will produce a cleaner/more OGC compliant dataset as it will dissolve boundaries and re-order geometries to ensure there are no self-intersections.

Here is the documentation for ST_MULTI, which will return the geometry as a multigeometry: https://postgis.net/docs/ST_Multi.html

Related Question