3

Extracting coordinate pairs of crossing points of two polygons in PostGIS

Is it possible to extract x,y-coordinate pairs of crossing points of two overlapping polygons in PostGIS?

Suppose there are only 2 overlapping points of the polygons the ST_Intersection function extracts more than two coordinate pairs (also the shared vertices of polygons are included).

SELECT ST_Intersection(geometry geomA , geometry geomB);

I am interested only in the 2 boundary crossing points of polygons.

1

Here is one method that'll work with basic polygons (no inner rings)

SELECT ST_AsText(
    ST_Intersection(
        ST_Boundary(ST_GeomFromText('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))')), 
        ST_Boundary(ST_GeomFromText('POLYGON((0.5 0.5, .5 1.5, 1.5 1.5, 1.5 0.5, 0.5 0.5))'))
    )
);

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.