<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">You could try something like gdal2xyz.py on you raster to create points for each raster cell which can be imported directly into postgis as point geometries, like:<br><br>psql "create table xyz (id serial,x decimal, y decimal, z decimal)"<br>gdal2xyz.py <raster file> | psql "copy xyz (x,y,z) from stdin..."<br>psql "select addgeometrycolumn()"<br>psql "update xyz set geom=setsrid(makepoint(x,y),<srid>)"<br><br>The result is then a simple spatial join using the polygons & the new points, based on ST_Contains().<br><br><br>HTH,<br><br>   Brent Wood<br><br><br>--- On <b>Tue, 5/29/12, Francois Hugues <i><hugues.francois@irstea.fr></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Francois Hugues <hugues.francois@irstea.fr><br>Subject: [postgis-users]
 RE :  get unique values from raster intersecting apolygon<br>To: "PostGIS Users Discussion" <postgis-users@postgis.refractions.net><br>Date: Tuesday, May 29, 2012, 1:05 AM<br><br><div class="plainMail">I want one value per red point (which are raster data).<br><br>The gid of one polygon will appear as many times as necessary regarding how it intersects the raster.<br><br>Hugues.<br><br><br>-------- Message d'origine--------<br>De: <a ymailto="mailto:postgis-users-bounces@postgis.refractions.net" href="/mc/compose?to=postgis-users-bounces@postgis.refractions.net">postgis-users-bounces@postgis.refractions.net</a> de la part de Pierre Racine<br>Date: lun. 28/05/2012 14:24<br>À: PostGIS Users Discussion<br>Objet : Re: [postgis-users] get unique values from raster intersecting apolygon<br> <br>You want one value per polygon or one value per red point? It is not clear to me from your drawing.<br><br>Pierre<br><br>> -----Original
 Message-----<br>> From: <a ymailto="mailto:postgis-users-bounces@postgis.refractions.net" href="/mc/compose?to=postgis-users-bounces@postgis.refractions.net">postgis-users-bounces@postgis.refractions.net</a> [mailto:postgis-users-<br>> <a ymailto="mailto:bounces@postgis.refractions.net" href="/mc/compose?to=bounces@postgis.refractions.net">bounces@postgis.refractions.net</a>] On Behalf Of Francois Hugues<br>> Sent: Saturday, May 26, 2012 5:29 PM<br>> To: <a ymailto="mailto:postgis-users@postgis.refractions.net" href="/mc/compose?to=postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>> Subject: [postgis-users] get unique values from raster intersecting a polygon<br>> <br>> Hello list,<br>> <br>> I have to get values from raster where they intersect polygons from a layer with<br>> numerous polygons which have shared boundaries, but I don't want to have<br>> duplicate values from raster. The
 final result must be something like : gid | val.<br>> <br>> To explain my case, I made a picture.<br>> <br>> I think ST_intersection could help but I don't know what will be the exact result.<br>> In my example, we have a grid (a DEM for example), each red point is the value<br>> in the centre of each cell and two polygons A and B. I think cells totally within<br>> polygons are not a problem, but in green I have highlighted some ambiguous<br>> cases :<br>> - 1 and 2 are cells shared by both polygons but not in the same proportions and I<br>> would like to get value 1 for polygon A but not for B and value 2 for polygon B<br>> but not for A<br>> - What will be the result for cell number 3 and for the other green cell without<br>> number (and for all the ones which are not totally within a polygon) ? I think the<br>> value is the same for the whole cell (st_dumpaspolygon) and will be returned<br>> whatever the
 part of the cell covered by the polygon, but if someone could<br>> confirm.<br>> <br>> If st_intersection use st_DumpAsPolygon, could it be better to work directly with<br>> this polygonized table using its own gist index and dealing with shared areas of<br>> cells between different polygons ?<br>> <br>> Hugues.<br>> <br>> <br>> <br>> <br><br>_______________________________________________<br>postgis-users mailing list<br><a ymailto="mailto:postgis-users@postgis.refractions.net" href="/mc/compose?to=postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br><a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br><br></div><br>-----Inline Attachment Follows-----<br><br><div class="plainMail">_______________________________________________<br>postgis-users mailing list<br><a
 ymailto="mailto:postgis-users@postgis.refractions.net" href="/mc/compose?to=postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br><a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br></div></blockquote></td></tr></table>