This is due to an attempt to cause intersections or contains a type request in a geometry collection, i.e. where you have a mixture of points, lines, and polygons (maybe a few).
There are at least a few possible fixes. The first one is simpler, but it seems a bit hacked, which simply reduces the input geometry first to 0, which will remove the non-polygons, so in your case, just change the command.commandText command to
SELECT area_code FROM area WHERE ST_INTERSECTS(ST_SetSRID(ST_Point(:x, :y), 4326), ST_Buffer(shape, 0)) AND area_type_code = :typecode";
Please note: this approach can often be used to correct incorrect geometries using self-intersecting loops, etc.
The second approach is to use ST_Dump in the form field to split into separate geometries, and then use only polygons in the real query using ST_GeometryType .
SELECT area_code FROM (SELECT area_code, (ST_Dump(area)).geom FROM area) poly WHERE ST_INTERSECTS(ST_SetSRID(ST_Point(:x, :y), 4326), poly.geom) AND ST_GeometryType(poly.geom) = 'ST_Polygon' OR ST_GeometryType(poly.geom) = 'ST_MultiPolygon' AND area_type_code = :typecode";
This is not verified as I cannot verify this clearly on your data, but these approaches work in practice.
source share