I've to create a spatial intersection of two tables (poly_a and poly_b) containing polygon features. Is there any way to remove unexpected linestring results?

CREATE VIEW poly_intersection AS SELECT
row_number() over() AS gid,
    (ST_Dump(ST_Intersection(poly_a.geom, poly_b.geom))).geom::geometry(polygon, 4326)
    FROM poly_a, poly_b
    WHERE ST_Intersects(poly_a.geom, poly_b.geom) AND NOT ST_Touches(poly_a.geom, poly_b.geom)
    ) AS subquery;

enter image description here

ERROR:  Geometry type (LineString) does not match column type (Polygon)

I'm wondering about the line geometries because of using AND NOT ST_Touches(poly_a.geom, poly_b.geom) in the WHERE clause.


Yes, use ST_CollectionExtract to pull only the polygonal parts out of the intersection output.

  • Shouldn't AND NOT ST_Touches(poly_a.geom, poly_b.geom) do this? – Lunar Sea Mar 5 '16 at 21:51
  • Dimensional collapse during overlay could be causing slight overlaps to turn into boundary touches. Dunno, guessing. Perfection is not available :) – Paul Ramsey Mar 6 '16 at 22:05

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.