[GRASS-user] v.rast.stats for just a single statistic, in a python loop

Ismael Gómez gomez.ismael at gmail.com
Wed Apr 18 17:44:12 EDT 2012


Thanks a million, Moritz.
Yours,
Ismael

2012/4/18 Moritz Lennert <mlennert at club.worldonline.be>

> On 18/04/12 20:54, Ismael Gómez wrote:
>
>> Hello,
>>
>> I would like to use the v.rast.stats inside a loop in a python script.
>> The thing is I just need to get one of the nine columns it generates
>> (sum).
>> As it runs many times in the loop, it takes a lot of (unnecessary, for
>> this script) time and also creates a huge table with too many
>> (unnecessary, for this script) columns.
>> I was wondering then if there was a way to specify the calculation for
>> just that single statistic.
>>
>
> v.rast.stats is a script, so fairly easy to modify (see below for
> accessing it).
>
>
>
>
>> Also, I wanted to ask you if there is a way to access the source code of
>> a specific module (in this case, v.rast.stats) via web (without
>> downloading the whole source code), just to have a quick look at it (and
>> try to adapt it to my needs, eventually contribute to it if possible,
>>
>
> http://trac.osgeo.org/grass/**browser/grass<http://trac.osgeo.org/grass/browser/grass>
>
> For the development version (aka grass7) go to trunk, for other version to
> branches.
>
> For v.rast.stats in the 6.4 release branch:
>
> http://trac.osgeo.org/grass/**browser/grass/branches/**
> releasebranch_6_4/scripts/v.**rast.stats/v.rast.stats<http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_6_4/scripts/v.rast.stats/v.rast.stats>
> .
>
> See "Download in other formats" at the bottom for downloading it.
>
> A quick and dirty guess would be that modifying
>
> line 247: BASECOLS="n min max range mean stddev variance cf_var sum"
>
> and
>
> line 368    sed -e '1d' "$STATSTMP" | awk -F "|" '{printf "\nUPDATE
> '${TABLE}' SET '${col1}' = %i , '${col2}' = %.2f , '${col3}' = %.2f ,
> '${col4}' = %.2f , '${col5}' = %.2f , '${col6}' = %.2f , '${col7}' = %.2f ,
> '${col8}' = %.2f , '${col9}' = %.2f WHERE '${KEYCOL}' = %i;",
> $2,$3,$4,$5,$6,$7,$8,$9,$10,$**1}' > "$SQLTMP"
>
> could actually be enough.
>
> Moritz
>



-- 
Ismael G.
Ingeniero de Caminos (UPM). Ingénieur des Ponts et Chaussées (ENPC).
PhD researcher @ Urban & Land Planning Department @ ETSICCP UPM
www.caminos.upm.es +34 91 336 67 83
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-user/attachments/20120418/9ddc3f11/attachment.html


More information about the grass-user mailing list