2

These look like three straight lines that could have two endpoints at the extreme vertices

enter image description here

But in reality they are each longer linestrings that have endpoints that are on the interior of the line, basically the line folds in on itself

enter image description here

enter image description here

They started out as separate lines that were parallel, and I tried to join the ones that intersected by using this function:

ST_CollectionExtract(unnest(ST_ClusterIntersecting(nl)))

where nl is the column of individual lines.

How can I change this query so I get a linestring made of 2 points where the endpoints are the expected endpoints from looking at the picture (the extreme vertices)

Alternatively, how can I take what I have after this point and turn it into what I want?

Here is an example line that I have: "LINESTRING(-101.47751335594317 31.489023992956714,-101.46871182786654 31.488981396096023,-101.47866855724968 31.489029536221512,-101.46986702785048 31.488987023468102)"

and here is how it should be: "LINESTRING(-101.46871182786654 31.488981396096023,-101.47866855724968 31.489029536221512)" (before these endpoints were on the inside of the line)

3
  • This would be nicely solved by a ST_MaximumDiameter function - except that doesn't exist in PostGIS yet.
    – dr_jts
    Sep 13, 2022 at 19:56
  • I think I solved it by using ST_LongestLine, about to test and then I'll post an answer if it works.
    – tbob
    Sep 13, 2022 at 20:19
  • Right, ST_LongestLine(A, A) computes the maximum diameter of A
    – dr_jts
    Sep 13, 2022 at 20:26

1 Answer 1

2

I fixed this by using:

ST_LongestLine((ST_CollectionExtract(unnest(ST_ClusterIntersecting(nl)))), (ST_CollectionExtract(unnest(ST_ClusterIntersecting(nl)))))

instead of:

ST_CollectionExtract(unnest(ST_ClusterIntersecting(nl)))

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.