[GRASS-dev] [GRASS GIS] #3680: [PATCH] r.object.geometry: add output of mean coordinates of objects - difference to r.mapcalc/r.univar output
GRASS GIS
trac at osgeo.org
Thu Oct 11 13:30:01 PDT 2018
#3680: [PATCH] r.object.geometry: add output of mean coordinates of objects -
difference to r.mapcalc/r.univar output
--------------------------+------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Addons | Version: unspecified
Resolution: | Keywords: r.object.geometry cell coordinates
CPU: Unspecified | Platform: Unspecified
--------------------------+------------------------------------------------
Comment (by mmetz):
Replying to [ticket:3680 mlennert]:
> For some applications it can be useful to obtain the mean coordinates of
raster objects. I would like to add this functionality to
r.object.geometry. For this I use the attached patch.
>
> However, when I use this to calculate mean coordinates of objects, I get
one unit of resolution difference between these results and the results of
the following r.mapcalc/r.univar call:
>
>
> {{{
> g.region rast=MyMap
> r.mapcalc "x = x()"
> r.univar -t x zones=MyMap
> }}}
>
> Here's some output for comparison:
>
>
> {{{
> r.mapcalc/r.univar r.object.geometry
>
> zone|mean cat|mean_x
> 1|270347.103514056 1|270347.353514
> 2|270355.499712833 2|270355.749713
> 3|270243.128030303 3|270243.378030
> 4|270270.053380443 4|270270.303380
> 5|270280.90239726 5|270281.152397
> 6|270277.778301887 6|270278.028302
> }}}
>
> The result of r.object.geometry is always shifted one resolution (0.25)
to the East.
the reason is that r.object.geometry pads the current region with one
column to the west and east, and the module iterates over columns with
{{{
for (col = 1; col <= ncols; col++) {
...
}}}
that also means that 0.5 needs to be subtracted:
{{{
obj_geos[cur - min].x += Rast_col_to_easting(col - 0.5,
&cellhd);
}}}
to get the real center for each column in the current region.
--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3680#comment:3>
GRASS GIS <https://grass.osgeo.org>
More information about the grass-dev
mailing list