I'm intesecting a polygon with a raster using PostGIS > 2.0. The outer boundary of the polygon is formed by the convex hull of polygons (building outlines plus safety margin) and the inner rings are actually the building outlines itself. In summary I want to get all the raster values that are within the polygon but are not within buildings - so all raster points in free area basically.
The problem is that even if buildings are actually adjacent, in between the buildings I get values from the raster, which are artefacts from the rastering routine of the polygons.
The query I perform looks like this:
select ST_AsText(ST_Centroid(ST_Transform((inside.geomval).geom,32633))) As geomwkt, (inside.geomval).val from (select ST_Intersection(rast, ST_GeomFromText('...',32633)) AS geomval from elevation where ST_Intersects(rast, ST_GeomFromText('...',32633))) AS inside;
Here's an example from QGIS: buildings considered are marked in yellow, the raster data is actually the blue background:
Here's the output of the query routine, where ... is a polygon containing the convex hull of the three buildings, and the buildings itself as inner rings.
I want to get rid of the sample points in between the selected buildings. Unfortunately I can't easily use something like concavehull, because on a larger set of buildings (e.g. on opposite side of streets), this will not work...
Is there any way to tackle this problem?