[GRASS5] G3D libraries notation

Hi
I am working on the g3d libraries to findout and fix some of the
problem.

here one source of confusion in the g3d libs:
the G3d_getValueRegion function (for example) is defined as:

   G3d_getValueRegion (map, row, col, depth, value, type);
                            \ /
but called as: \ /
                              \
                             / \
   G3d_getValueRegion (map, x, y, z, (char *)n1p, typeIntern)

the problem is that in matrix notation you work using "rows" and "cols",
while in cartesian notation "x" and then "y" are used.
The idea is to rewrite the functions, which now use the "x-y" notation,
to make them follow the "rows-cols" notation.

If anybody has some different idea or suggestion please let me known!

Alfonso Vitti

Departement of Civil and Environmental Engineering
University of Trento -Italy-

Hello

On Tue, 3 Dec 2002, Alfonso Vitti wrote:

The idea is to rewrite the functions, which now use the "x-y" notation,
to make them follow the "rows-cols" notation.

I think this is a very good idea. I know from working in image processing
that it is very easy to get confused between pixel co-ordinates, which are
discrete integer "rows-columns" values, and distance across or up the
image, which is a continuous floating point number and can be referred to
in "x-y" notation. I also always use 'columns' instead of 'cols' in my
code to avoid any possible confusion (however remote) with 'colours'.

Normally also "rows-columns" notation starts from the upper left corner of
the region, while "x-y" starts from the lower left. This is always a
terrible source of complicated code as the number of rows in the region
must be known to convert between row and y values. So it would be good to
standardise this if possible to have the same origin but I have no idea
what state the g3d code is in at the minute.

I don't know if the first element in GRASS raster row-column arrays is 0 or 1
(in MATLAB it is 1; in C it is 0). If the first cell in the region is (row=0,
column=0), then the corner of the region should be (x=-0.5, y=-0.5) or if the
first cell is (row=1, column=1) then the corner of the region will be
(x=0.5, y=0.5). Using this notation then the centre of each cell's "x-y"
co-ordinates will be the same as the "row-column" co-ordinates for the cell.
Having this offset of 0.5 in the "x-y" co-ordinates makes interpolation
calculations etc. quite simple and intuitive.

It is probably obvious that most of my experience with raster data has
been image processing in MATLAB and I haven't done any GRASS raster
programming, so all my ideas may not be suitable or consistent with
existing GRASS practice (this second reason is always the most important I
think). But I have thought a lot about this sort of thing and have come up
with some ideas for best practice.

To summarise, I think using "row-column" notation is good because it
forces programmers to think in terms of discrete integer values, which is
how the raster tile is read, and realise they need to do re-sampling and
interpolation if necessary to improve the accuracy of their calculations.

Sorry if I've missed the point but I hope this is useful and makes sense.
If you can point out a sample file in the GRASS source that has some of
the code with bugs I may have a chance to look at some of it and see if the
changes I suggest would be the same as yours.

Paul Kelly

Paul Kelly wrote:

I don't know if the first element in GRASS raster row-column arrays is 0 or 1
(in MATLAB it is 1; in C it is 0). If the first cell in the region is (row=0,
column=0), then the corner of the region should be (x=-0.5, y=-0.5) or if the
first cell is (row=1, column=1) then the corner of the region will be
(x=0.5, y=0.5). Using this notation then the centre of each cell's "x-y"
co-ordinates will be the same as the "row-column" co-ordinates for the cell.
Having this offset of 0.5 in the "x-y" co-ordinates makes interpolation
calculations etc. quite simple and intuitive.

I don't know about G3D, but for 2D GRASS rasters the index <0,0>
refers to the top-left (north-west) cell, while geographic coordinates
have north and east as the positive directions (i.e. the sense of the
geographic Y coordinate is opposite to that of cell rows).

The region corresponds to cell boundaries rather than centres, so:

1. ewres = (east-west)/cols, nsres = (north-south)/rows.

2. The top-left cell has index <0,0>, its top-left corner at
<west,north>, its bottom-right corner at <west+ewres,north-nsres> and
its centre at <west+ewres/2,north-nsres/2>.

3. The bottom-right cell has index <cols-1,rows-1>, its top-left
corner at <east-ewres,south+nsres>, its bottom-right corner at
<east,south> and its centre at <east-ewres/2,south+nsres/2>

4. An arbitrary cell with index <i,j> has its top-left corner at
<west+ewres*i,north-nsres*j>, its bottom-right corner at
<west+ewres*i+ewres,north-nsres*j-nsres> and its centre at
<west+ewres*i+ewres/2,north-nsres*j-nsres/2>

--
Glynn Clements <glynn.clements@virgin.net>