[GRASS-user] Re: Calculating mode value for each polygon

Sylvain Maillard sylvain.maillard at gmail.com
Mon Oct 18 10:07:30 EDT 2010


hello,

something strange, i was quite sure to have send a response but it seems
something goes wrong ...

I wrote a little script that use r.mode:
- convert the vector with polygon to raster
- loop for each polygon
- get the mode and update the specified column in the vector file

it process only one polygon at a time and is quite slow, but do the job ;)

cheers,
Sylvain

[code]
#!/bin/bash

# vector with polygon
vect=Parcellaire
# name of the column to store the mode
col=new2000
# name of your data_map raster
cover=classif
# name for the tmp raster to compute the polygon
base=parcelles

g.region rast=${cover}
v.to.rast input=${vect} output=${base} use=cat

for cat in `r.stats ${base} | grep -v "*"`
do

cat_u=$(($cat - 1))
cat_o=$(($cat + 1))

g.copy rast=${base},${base}.${cat}
r.null map=${base}.${cat} setnull=0-${cat_u},${cat_o}-11000
g.copy rast=${base}.${cat},MASK
r.mapcalc "${cover}.${cat}=${cover}"
r.mode base=${base}.${cat} cover=${cover}.${cat}
output=${base}.${cat}.reclass --o --v
class=$(echo `r.stats ${base}.${cat}.reclass | grep -v "*"`);
v.db.update map=${vect} column=${col} value=${class} where="cat=${cat}"
g.remove rast=MASK,${base}.${cat}.reclass,${base}.${cat},${cover}.${cat}

done
[/code]
-------------- section suivante --------------
Une pi?ce jointe HTML a ?t? enlev?e...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20101018/b963645b/attachment.html


More information about the grass-user mailing list