On 18/10/2010 16:07, Sylvain Maillard wrote:

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
Don't think this is necessary. Once the vector is rasterized, the values in the output raster will represent the mode, calculated from the cover map, for each area. Then just convert the output raster back to a vector with the '-v' flag to r.to.vect and it should contain the mode as it's cat value 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]


This mail was received via Mail-SeCure System.
_______________________________________________ grass-user mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/grass-user

This mail was received via Mail-SeCure System.




-- 
Micha Silver
http://www.surfaces.co.il/
Arava Development Co.  +972-52-3665918
_______________________________________________
grass-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-user

Reply via email to