0

I am trying to find a solution to do the function of the QGIS-tool 'Generate points(pixel centroids) inside polygons' in PostGIS.

In the picture below you can see the output. Is there a way to do it in PostGIS?

output

3

Use ST_PixelAsCentroids:

Returns the centroid (point geometry) for each pixel of a raster band along with the value, the X and the Y raster coordinates of each pixel.

Example:

create table centroids as(
SELECT x, y, val, ST_AsText(geom), geom
    FROM (SELECT dp.* FROM someraster, LATERAL ST_PixelAsCentroids(rast, 1) AS dp) foo
    join somepolygon
    on st_intersects(foo.geom, somepolygon.wkb_geometry)
    where somepolygon.id=328045)

enter image description here

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.