[GRASS-user] How to list all unique pixel values (of a raster) covered by polygons (areas) for each polygon separately(?)

Nikos Alexandris nikos.alexandris at felis.uni-freiburg.de
Thu Jan 17 21:23:54 EST 2008


Giovanni,

thank you for your proposal.

The link to the FAQ (the one that Jose provided) looks like a solution.

But your idea is clever as well and I had a similar way in my mind.

If I got it correct you suggest:

1. VectorTargetAreas  ~~~v.to.rast (based on unique attribute like cat
or FID~~~> RasterTargetAreas (all pixels of a "TargetArea" have now the
same value

2.MASK out everything besides the "TargetAreas" ---looping to create as
many MASKS as the the number of the "TargetAreas"

3.  For each MASK run r.stats

4 (I would also like to have) add the output list(s) as a new table
(column pixval) into the initial VectorTargetAreas (with db.connect,
db.addcol, etc). Let's say for a polygons which covers 20 pixels it
would be like:

FID - cat - pixval
1    -     1 -    200
2    -     1 -    198
3    -     1 -    234
..    -     .. -      .....
20 -      1 -    765


Is it possible to put all this together?


r.stats and output into a new column (pixval) 
On Thu, 2008-01-17 at 18:25 +0100, G. Allegri wrote:
> Just a rapid idea.
> You could make just one rasterized map of your polygons and then
> insert in a loop this, giving each pixel a unique category value:
> 
> r.mapcalc "MASK = if(raster=$i,1,null())"
> with $1 the cat value (deriving from you original polygon)
> 
> and then run r.stats, which will work only for the un-masked pixels.
> 
> I don't have time to try this method, hope it helps.
> GIovanni
> 
> 2008/1/17, nikos.alexandris at felis.uni-freiburg.de
> <nikos.alexandris at felis.uni-freiburg.de>:
> > Salut Jose!
> >
> > This is what I am doing... and I only have 7 polygons - so
> > it is ok.
> >
> > But if I have 50 polygons... I am not so sure how to script
> > it to get (finally) a table with all pixels for each unique
> > polygon for 2 different images of the same location (for
> > raster MODIS year 2006 and then another of the same area
> > MODIS 2007!).
> >
> > I want to run a regression with the pixel values... (pairs
> > of 2006 and 2007 values).
> >
> > Thank you,
> >
> > Nikos.
> >
> >
> >
> > On Thu, 17 Jan 2008 16:42:31 +0000
> >  "Jose Gomez-Dans" <jgomezdans at gmail.com> wrote:
> > > On Jan 17, 2008 4:30 PM,
> > > <nikos.alexandris at felis.uni-freiburg.de> wrote:
> > >
> > > > How can I get listed all unique pixel values enclosed
> > > in
> > > > each of the polygons I digitised (and for which the
> > > univ.
> > > > stats are calculated)?
> > > >
> > >
> > > Can't you just rasterise your polygons, and use that as a
> > > mask with
> > > r.mapcalc? You can loop around in your shell. I tend to
> > > do that with python,
> > > but it's similar in GRASS. You can also try starspan.
> > > Or.... <
> > > http://grass.gdf-hannover.de/wiki/Aggregate_Values>
> > >
> > > Cheers,
> > > Jose
> > >
> > >
> > >
> > > --
> > > Centre for Terrestrial Carbon Dynamics
> > > Department of Geography, University College London
> > > Gower Street, London WC1E 6BT, UK
> >
> >
> >                         .
> >          Nikos Alexandris - Ph.D. Candidate
> >                         .
> >             Department of Remote Sensing
> >                        and
> >             Landscape Information Systems
> >                      (FeLIS)
> >                         .
> >       Faculty of Forestry and Natural Environment
> >           Albert-Ludwigs-University Freiburg
> >                         .
> >             Tel.  +49 (0) 761 203 3697
> >             Fax.  +49 (0) 761 203 3701
> >              Skype: Nikos.Alexandris
> >                         .
> >            Address: Tennenbacher str. 4
> >               D-79106 Freiburg i. Br.
> >                      Germany
> >                         .
> > _______________________________________________
> > grass-user mailing list
> > grass-user at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/grass-user
> >
-- 
Nikos Alexandris
.
Department of Remote Sensing & Landscape Information Systems
Faculty of Forestry & Environmental Sciences, Albert-Ludwigs-University Freiburg
.
Tel.  +49 (0) 761 203 3697 / Fax.  +49 (0) 761 203 3701 / Skype: Nikos.Alexandris
.
Address: Tennenbacher str. 4, D-79106 Freiburg i. Br., Germany
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.osgeo.org/pipermail/grass-user/attachments/20080118/2cadbd4e/attachment-0001.bin


More information about the grass-user mailing list