0

I'm trying to get all the points from a Self-Intersection LineString.

  1. On LineString segments intersection with no vertex on intersection: ST_Intersection make the job;
  2. Now, how catch the vertex intersection like image? Just crosses points...

http://imgur.com/UsMmwUj

1

Segments with 3 points each... nop, ST_Crosses dont work properly... :(

DROP FUNCTION IF EXISTS temp.ST_Segments3points(geometry);
CREATE OR REPLACE FUNCTION temp.ST_Segments3points(geom1 geometry)
RETURNS geometry
AS $$
DECLARE
i int;
n_points int;
newLines text  = 'MULTILINESTRING(';

BEGIN
    newLines := newLines || '(' || ST_X(ST_PointN(geom1,1)) || ' ' || ST_Y(ST_PointN(geom1,1)) || ' ' || ST_Z(ST_PointN(geom1,1)) || ',';
    newLines := newLines || ST_X(ST_PointN(geom1,2)) || ' ' || ST_Y(ST_PointN(geom1,2)) || ' ' || ST_Z(ST_PointN(geom1,2)) || ',';
    newLines := newLines || ST_X(ST_PointN(geom1,3)) || ' ' || ST_Y(ST_PointN(geom1,3)) || ' ' || ST_Z(ST_PointN(geom1,3)) || '),';
    FOR i IN 4..ST_NumPoints(geom1) LOOP
        newLines := newLines || '(' || ST_X(ST_PointN(geom1,i-2)) || ' ' || ST_Y(ST_PointN(geom1,i-2)) || ' ' || ST_Z(ST_PointN(geom1,i-2)) || ',';
        newLines := newLines || ST_X(ST_PointN(geom1,i-1)) || ' ' || ST_Y(ST_PointN(geom1,i-1)) || ' ' || ST_Z(ST_PointN(geom1,i-1)) || ',';
        newLines := newLines || ST_X(ST_PointN(geom1,i)) || ' ' || ST_Y(ST_PointN(geom1,i)) || ' ' || ST_Z(ST_PointN(geom1,i)) || '),';
    END LOOP;
    newLines := newLines || ')';
    newLines := REPLACE(newLines, ',)',')');

    RETURN ST_SetSRID(newLines, ST_SRID(geom1));
END $$
LANGUAGE plpgsql
STABLE
RETURNS NULL ON NULL INPUT;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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