Re: [postgis-users] Raster pixel value

2011-12-19 Thread Andreas Forø Tollefsen
I also as you see tried to divide on 3600 as that was the possible number of pixel count per geometry polygon (foo2.gid). Andreas 2011/12/19 Andreas Forø Tollefsen > Thanks Tom, > > I tried to select WHERE (ss).count > 0 and (ss).sum > 0, but i still got > the same error. I assume that this is

Re: [postgis-users] Raster pixel value

2011-12-19 Thread Andreas Forø Tollefsen
Thanks Tom, I tried to select WHERE (ss).count > 0 and (ss).sum > 0, but i still got the same error. I assume that this is something that need to be changed in the script. I will do some more testing. Does anyone have an idea for something that could bypass this in my query? SELECT foo2.gid, (ss

Re: [postgis-users] Raster pixel value

2011-12-19 Thread Tom van Tilburg
Yes, well found. I'm not familiar with plpgsql, but I'm sure it's easy to include some conditional statement. Just check the postgres documentation. You can also check if you can put the conditional into your SQL query (something like 'WHERE count(rast) > 0') so that you don't feed empty raste

Re: [postgis-users] Raster pixel value

2011-12-19 Thread Tom van Tilburg
Divisions by zero shouldn't happen as far as I know, at most it should give you null data as return. Sounds like a bug. Perhaps you can check: http://trac.osgeo.org/postgis/browser/trunk/raster/scripts/plpgsql/st_summarystatsagg.sql at line 69 it says: "($1).sum / ($1).count" my guess is that t

Re: [postgis-users] Raster pixel value

2011-12-19 Thread Andreas Forø Tollefsen
Line 59 to 77 in the st_summarystatsagg.sql. Could it be that line 69: ($1).sum / ($1).count leads to division by zero error if ($1).count is 0? How could i change this so this is not the case? -- raster_summarystatsfinal -- Final function used by the ST_SummaryStatsAgg aggregate CREATE OR REPLACE

Re: [postgis-users] Raster pixel value

2011-12-19 Thread Andreas Forø Tollefsen
Updated to latest trunk, and now it works. However, I ran into a new "division by zero" error. This halts the query. Could it be that something is divided by integer rather than decimal in the query, or what else causes this: ERROR: division by zero CONTEXT: PL/pgSQL function "raster_summarystat

Re: [postgis-users] Raster pixel value

2011-12-19 Thread Tom van Tilburg
Andreas, If you got the latest ST_Clip from the repository, I found this information with it: "Addition of C-based ST_MinPossibleValue to replace the existing ST_MinPossibleVal which uses hard-coded values. Updated dependent functions and scripts/plpgsql to use new function. Deleted scripts

Re: [postgis-users] Raster pixel value

2011-12-19 Thread Andreas Forø Tollefsen
Hi Tom, I tried both functions. The St_AreaWeightedSummaryStats() works great, but it takes a lot of time to complete. However, the ST_Clip() i cannot manage to get working. Seems like something is broken. Any idea what can cause this error? I installed the latest ST_SummaryStatsAgg() and ST_Clip

Re: [postgis-users] Raster pixel value

2011-12-06 Thread Tom van Tilburg
Andreas, I didn't have time to reproduce your problem yet. Did you have any succes by yourself on this issue? Could it have something to do with counting the non-data values as value? This is what I experience with a similar function (ST_Clip) that consequently gave me the value '0' instead of

Re: [postgis-users] Raster pixel value

2011-12-04 Thread Bborie Park
On Sun, Dec 4, 2011 at 11:09 AM, Tom van Tilburg wrote: > Pierre, > > I just ran a test to see the difference between my old method and your new > method with ST_Clip and ST_SummaryStatsAgg and came up with the following: > > 1. The old way took 38 secs. whereas the new one 46 (100 polygons, usual

Re: [postgis-users] Raster pixel value

2011-12-04 Thread Tom van Tilburg
Pierre, I just ran a test to see the difference between my old method and your new method with ST_Clip and ST_SummaryStatsAgg and came up with the following: 1. The old way took 38 secs. whereas the new one 46 (100 polygons, usually covering part of 1 raster tile). 2. ST_Clip appears to fill

Re: [postgis-users] Raster pixel value

2011-12-02 Thread Pierre Racine
sers Discussion > Subject: Re: [postgis-users] Raster pixel value > > Pierre, are these two new functions available in the latest trunk revision? > > Andreas ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.re

Re: [postgis-users] Raster pixel value

2011-12-02 Thread Pierre Racine
Tollefsen > Sent: Friday, December 02, 2011 8:21 AM > To: PostGIS Users Discussion > Subject: Re: [postgis-users] Raster pixel value > > Pierre, are these two new functions available in the latest trunk revision? > > Andreas ___ post

Re: [postgis-users] Raster pixel value

2011-12-02 Thread Andreas Forø Tollefsen
Pierre, are these two new functions available in the latest trunk revision? Andreas ___ postgis-users mailing list postgis-users@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users

Re: [postgis-users] Raster pixel value

2011-12-01 Thread Andreas Forø Tollefsen
This is great! Fantastic. I will do some testing. 2011/12/1 Tom van Tilburg > Pierre, > > This is great you're working on this. It is exactly what I think that > pgraster is going to make a great tool. > > Last days I didn't really have time to check out things, hopefully this > week. > > Cheers

Re: [postgis-users] Raster pixel value

2011-12-01 Thread Pierre Racine
: postgis-users@postgis.refractions.net > Subject: Re: [postgis-users] Raster pixel value > > Pierre, > > This is great you're working on this. It is exactly what I think that > pgraster is > going to make a great tool. > > Last days I didn't reall

Re: [postgis-users] Raster pixel value

2011-12-01 Thread Tom van Tilburg
Pierre, This is great you're working on this. It is exactly what I think that pgraster is going to make a great tool. Last days I didn't really have time to check out things, hopefully this week. Cheers, Tom On 30-11-2011 19:19, Pierre Racine wrote: Andreas, Tom, I have put two new func

Re: [postgis-users] Raster pixel value

2011-11-30 Thread Pierre Racine
Andreas, Tom, I have put two new functions you might be interested by in http://trac.osgeo.org/postgis/browser/trunk/raster/scripts/plpgsql The first one, st_areaweightedsummarystats.sql, is usefull when you want to compute summary stats (like the weighted mean) of values coming from a raster

Re: [postgis-users] Raster pixel value

2011-11-25 Thread Pierre Racine
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: > &g

Re: [postgis-users] Raster pixel value

2011-11-25 Thread Andreas Forø Tollefsen
Update: I think my suspicion is correct. If I do a ST_Summarystats().sum and divide this on 36 my MAX value will be 1. Hence, I think the number of values counted and the number of observations counted is not equal. New query: DROP TABLE IF EXISTS mountain_phil_cell; SELECT a.gid As gid, (ST_Sum

Re: [postgis-users] Raster pixel value

2011-11-25 Thread Andreas Forø Tollefsen
A small note regarding this issue. My problem is that I never get a mean value of 1 even if all pixels inside the geometry is one. Could this be because: 6x6 pixels goes into one polygon when visually controlling. If each pixel has the value 1, then this will be calculated as 36 / 36 = 1. However

Re: [postgis-users] Raster pixel value

2011-11-25 Thread Andreas Forø Tollefsen
Could this have to do with the tiling of the raster? I will try to run the same query with a untiled mountain raster to see if that changes anything. Btw. When loading a tiled postgis raster into qgis it shows up with many artifacts and no data areas. The same raster untiled does not show up the s

Re: [postgis-users] Raster pixel value

2011-11-25 Thread Andreas Forø Tollefsen
Hi, Thanks for all of the suggestions. I will do some more testing. However, as for suggestion 1 i think the pixel size should be the same as the original raster or am I wrong? Both the mean_mnt_bin raster and the priogrid_land shapefile can be downloaded as zip (2 mb) here: http://gisintersect.c

Re: [postgis-users] Raster pixel value

2011-11-24 Thread Tom van Tilburg
Andreas, Would it be possible to share code and/or sample data? With me St_SummaryStats seems to work correct, even when I set all my raster values to 1. Chrs, Tom On 24-11-2011 13:42, Andreas Forø Tollefsen wrote: I double checked the values that I get from this query and they do not seem t

Re: [postgis-users] Raster pixel value

2011-11-24 Thread Andreas Forø Tollefsen
I know. RTFM before asking dumb questions. Set the ST_Summary(rast, false) so it does not exclude_nodata_value? Right? Andreas 2011/11/24 Andreas Forø Tollefsen > Great. I updated to latest rev and added the st_union.sql to my function > list. Now it works. > However, I need to ask one more que

Re: [postgis-users] Raster pixel value

2011-11-24 Thread Andreas Forø Tollefsen
Great. I updated to latest rev and added the st_union.sql to my function list. Now it works. However, I need to ask one more question. When running the script, it calculates the average pixel value inside the polygon. It does not take into account the NULL DATA values. Is there any way i can make t

Re: [postgis-users] Raster pixel value

2011-11-24 Thread Tom van Tilburg
Yes, I think so. Current windows build is *r8221 * Also, I think ST_Union(raster) (which I used in the example) is not included in this version yet. You would have to download a prototype from. http://trac.osgeo.org/postgis/browser/trunk/raster/scripts/plpgsql/st_union.sql Chrs, Tom On 24-11-

Re: [postgis-users] Raster pixel value

2011-11-24 Thread Andreas Forø Tollefsen
Great, Thank you so much for this. However, I do not seem to have the ST_MapAlgebraExpr(rast, rast.) function. Was this implemented in rev 8001? Andreas 2011/11/24 Tom van Tilburg > Andreas, > > We did approx. the same thing for non-quadrate polygons. Perhaps it might > be useful: > > Step

Re: [postgis-users] Raster pixel value

2011-11-24 Thread Tom van Tilburg
Andreas, We did approx. the same thing for non-quadrate polygons. Perhaps it might be useful: Step 1: Make a raster from every polygon, based on the grid specifications of the elevation raster. Here is also the solution: the raster cells will only be created for cells that have their midpoin

[postgis-users] Raster pixel value

2011-11-24 Thread Andreas Forø Tollefsen
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_