I have a linestring which crosses itself, like in the picture below. There isn't any vertice at the crossing.

enter image description here

It is a MultiLinestring, so when I want to get the startpoint, the endpoint, or the azimuth (for instance), I get an empty result. I tried to use ST_Linemerge, but for the same result. I think the problem come from the fact that this linestring is crossing itself since I don't have that problem with the linestrings (in the same table) which don't cross themselves.

I am trying to get xmin, xmax, azimuth... in order to establish a process for an atlas in QGIS. I would prefer to manage that in PostGIS, do you have any idea on the way to go?

In my experience these self-crossing linestrings are a big source of problems (with ST_Dump for example), problems that nor me nor my colleagues ever managed to solve, so any insight would be very welcome.

  • 1
    You tried to use the function ST_MakeValid? Until you provide an example of code and geodata, it’s hard to help ... Commented Aug 19, 2019 at 17:28
  • Specify, the azimuth is determined from one point to another, postgis.net/docs/ST_Azimuth.html, how is this process connected with the intersection, which as you say you don’t have? Commented Aug 20, 2019 at 10:53
  • I am not sure to understand you second comment. I am using the azimuth to calculate a rotated bounding box. And to use it I need the startpoint and endpoint of a line, which in the case of a multilinestring doesn't exist. Commented Aug 22, 2019 at 12:26
  • Maybe I didn’t understand something, but you have a function ST_DumpPoints... Commented Aug 22, 2019 at 13:24

3 Answers 3


Self-intersecting linestring is valid but it is not simple as you can test in PostGIS with

select st_isvalid(
'LINESTRING (440 380, 560 460, 620 380, 540 320, 480 480)'));



select st_issimple(
'LINESTRING (440 380, 560 460, 620 380, 540 320, 480 480)'));


ST_MakeValid does not do anything for self-intersecting linestrings because they are already valid and there is no ST_MakeSimple even it has been under discussion several years ago https://trac.osgeo.org/postgis/ticket/399.

Best advice for making linestrings simple is perhaps in gis.stackexchange PostGIS help writing a ST_MakeSimple method for self intersecting lines?.


For making a self-intersecting linestring simple you must split the line at the intersection points. It may be necessary to create a new node at the intersection point first. OpenJUMP has a special utility "Noder" for that purpose.

Self-intersecting linestring to start with.

enter image description here

Dialog box of the Noder tool that is available in OpenJUMP Plus through menu Tools - Edit Geometry - Noder.

enter image description here

The result is three simple linestrings. New node added by OpenJUMP emphasized.

enter image description here

  • Thank you. However it doesn't give me the expected result since I would get 3 linestrings instead of a single one. Well I guess I could then imagine a process to get the values I want through those 3 linestrings, but it would be a quite heavy process for a relatively marginal situation. Commented Aug 22, 2019 at 7:13

If the data is a MultiLineString with only one component, you can use ST_GeometryN to get the component LineString, and then run the functions needed on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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