2

I have two functions, first I check if a polygon is within a defined polygon. If it's not, but on the border, I cut it with ST_Intersection, and get a new polygon. If I check the result, I get that it is still intersecting, so it gets cut again and again.

BEGIN
   RETURN QUERY

SELECT
CASE 
WHEN (SELECT ST_Contains(a, b) 
    FROM (SELECT (SELECT geom from big_poly) As a, ST_SetSrid($1,4326)  As b)
    As tbl) = false
THEN (select * from geometry_check($1))
WHEN (SELECT ST_Contains(a, b) 
    FROM (SELECT (SELECT geom from big_poly) As a, ST_SetSrid(ST_GeomFromText($1),4326)  As b)
    As tbl) = true
THEN null

END;
END


BEGIN
   RETURN QUERY
SELECT ST_Intersection(a, b)
    FROM (SELECT (SELECT big_poly.geom from big_poly) As a, ST_SetSrid($1,4326)  As b) as foo;

END
  • 1
    please add the full function definitions; it's not exactly helpful to guess what's happening. – ThingumaBob Nov 22 '19 at 23:52
  • 1
    ST_Intersects includes features which share a single vertex, so if you clip with ST_Intersection, the result often will still intersect. – Vince Nov 23 '19 at 3:03
  • 1
    @Vince Sorry I rewrited, both times I use ST_Contains, but still the result is the same. Do you think that is there a way to solve it? – buboreka Nov 23 '19 at 9:58
  • the intersection is the common area between the two polygons, so it is expected that this common area is contained in the original polygons. Maybe you don't want the intersection but the difference between the original geometry and the intersection? – JGH Nov 23 '19 at 12:41
  • 1
    so it is contained/intersecting as expected... what is the problem then? – JGH Nov 23 '19 at 12:52

Your Answer

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

Browse other questions tagged or ask your own question.