[postgis-users] Raster pixel value

Pierre Racine Pierre.Racine at sbf.ulaval.ca
Fri Nov 25 13:37:26 PST 2011


Andreas,

My way of solving this issue is to do a weighted mean based on the area of the part of the pixel intersecting. ST_Intersection() return a geomval of the true intersecting part. You must weigh the elevation with the area of the intersecting part. I explain how to do this at the end of the tutorial:

http://trac.osgeo.org/postgis/wiki/WKTRasterTutorial01

Pierre

> -----Original Message-----
> From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-
> bounces at postgis.refractions.net] On Behalf Of Andreas Forø Tollefsen
> Sent: Thursday, November 24, 2011 5:14 AM
> To: PostGIS Users Discussion
> Subject: [postgis-users] Raster pixel value
> 
> Hi,
> 
> I am trying to calculate the average pixel value in a elevation raster inside
> quadrate polygons.
> However, I am not getting the correct values from my query:
> 
> SELECT gid, AVG(((foo.geomval).val)) as avgmnt FROM (SELECT p.gid,
> ST_Intersection(p.cell, r.rast) AS geomval FROM mountain r, priogrid_land p
> WHERE ST_Intersects(p.cell, r.rast, ) AND p.gid =186124) AS foo GROUP BY
> gid ORDER BY gid;
> 
> The problem here is that the ST_Intersects(geom, rast) takes into
> consideration the pixels that is outside, but touches the border of the
> quadrate polygons. Then, the average values for each quadrate polygon is
> affected by pixels inside other polygons. This will potentially lead to a
> flawed result.
> So what I want is to be able to calculate the average value for the pixels
> INSIDE the polygon excluding those outside.
> 
> How can i restrict the AVG pixel value to be calculated only for pixels that is
> inside the polygon, and not the pixels that touch the outside of the border?
> 
> Thanks!
> 
> Best,
> Andreas
> 




More information about the postgis-users mailing list