[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 07:20:04 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 mlennert):
Replying to [comment:1 marisn]:
> Comments in the code of r.mapcalc
(https://trac.osgeo.org/grass/browser/grass/trunk/raster/r.mapcalc/xcoor.c#L27):
>
> {{{
> x() easting at center of column
> y() northing at center of row
> }}}
>
> And the code itself:
>
> {{{
> x = Rast_col_to_easting(0.5, ¤t_region2);
> y = Rast_row_to_northing(current_row + 0.5, ¤t_region2);
> }}}
Yes, because in the programmer's manual, it says:
{{{
/*!
250 * \brief Column to easting.
251 *
252 * Converts a <i>col</i> relative to a <i>window</i> to an easting.
253 *
254 * <b>Note:</b> <i>col</i> is a <i>double</i>:
255 * - col+0.0 will return the easting for the western edge of the
column.
256 * - col+0.5 will return the easting for the center of the column.
257 * - col+1.0 will return the easting for the eastern edge of the
column.
258 *
259 * \param col column number
260 * \param[in] window pointer to Cell_head
261 *
262 * \return east coordinate
263 */
264 double Rast_col_to_easting(double col, const struct Cell_head
*window)
265 {
266 return window->west + col * window->ew_res;
267 }
}}}
And in the code of r.mapcalc, you can see
{{{
27 x = Rast_col_to_easting(0.5, ¤t_region2);
28
29 for (i = 0; i < columns; i++) {
30 res[i] = x;
31 x += current_region2.ew_res;
32 }
}}}
i.e. the first x is calculated for col = 0.5 and all others for
respectively one ew_res to the east, so always col + 0.5.
That is why I'm surprised to not get the same answer.
Maybe it is due more to r.univar than to r.mapcalc ?
--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3680#comment:2>
GRASS GIS <https://grass.osgeo.org>
More information about the grass-dev
mailing list