When clipping the polygons of one table with polygons in another, ST_Intersection can return a set of results that can be handled with ST_Dump. The returned multiple geometries are not necessarily ST_Polygon but also ST_LineString (probably also a point). So when running a query
INSERT INTO c (geom)
(SELECT (ST_Dump(ST_Intersection(a.geom,b.geom))).geom
FROM a INNER JOIN b ON ST_Intersects(a.geom, b.geom));
when trying to populate the table "c" with clipped polygons, it fails with ERROR: Geometry type (LineString) does not match column type (Polygon)
I did another nested SELECT statement so only the polygon geometries came through, like:
INSERT INTO c (geom)
(SELECT geom FROM
(SELECT (ST_Dump(ST_Intersection(a.geom,b.geom))).geom
FROM a INNER JOIN b ON ST_Intersects(a.geom, b.geom))) AS cl
WHERE ST_GeometryType(cl.geom)='ST_Polygon');
As this is a bit cumbersome I am wondering if there is a more elegant solution for dropping invalid geometries?
{}
above the Question editing window.