I'm trying to query a list of polygons (geo_parcels) and get all of them, and also spatially add any points or polygons (geo_buildings) that are in or on that polygon. Normally I'd use a query like this:
SELECT DISTINCT geo_parcels.objectid FROM geo_parcels LEFT JOIN geo_buildings ON st_contains(geo_parcels.geom, geo_buildings.geom) WHERE (ST_IsValid(ST_MakeValid(ST_CurveToLine(geo_parcels.geom))) OR geo_parcels.geom IS NULL) AND (ST_IsValid(ST_MakeValid(ST_CurveToLine(geo_buildings.geom))) OR geo_buildings.geom IS NULL); However, that gave a new to me error of
GEOSContains: TopologyException: side location conflict at # #. This can occur if the input geometry is invalid.
I dug around and got it working by removing the ST_MakeValid, which is surprising, but works.
SELECT DISTINCT geo_parcels.objectid FROM geo_parcels LEFT JOIN geo_buildings ON st_contains(geo_parcels.geom, geo_buildings.geom) WHERE (ST_IsValid((ST_CurveToLine(geo_parcels.geom))) OR geo_parcels.geom IS NULL) AND (ST_IsValid((ST_CurveToLine(geo_buildings.geom))) OR geo_buildings.geom IS NULL); With this, I get 23146 results. However, If I just query the geo_parcels directly, I get 23396 results.
SELECT DISTINCT geo_parcels.objectid FROM geo_parcels; I'd like to find a way to not remove any results when I add in the ST_Contains. Is this possible?