[GRASS-dev] G_get_raster_sample(): request outside region

Hello list!

I try to obtain the cell values of a raster map at the location of certain nodes of a vector map:

+++
struct Cell_head window;
G_get_window(&window);

...

Vect_get_node_coor( In, node, &x, &y, NULL );
z = G_get_raster_sample( fdrast, &window, NULL, x, y, 0, method );
+++

Running this code gives the following message:
WARNING: [rugg_dtmgrd in c716322] - read request for row 311730 is outside region
ERROR: problem reading raster cell file

Are the coordinates returned by Vect_get_node_coor() a valid argument for G_get_raster_sample() ?
Is my use of G_get_window() OK?

Any comment is welcome,
thanks,
Flo.

--
Florian Kindl
Institute of Geography
University of Innsbruck

Florian Kindl wrote:

I try to obtain the cell values of a raster map at the location of certain
nodes of a vector map:

+++
struct Cell_head window;
G_get_window(&window);

...

Vect_get_node_coor( In, node, &x, &y, NULL );
z = G_get_raster_sample( fdrast, &window, NULL, x, y, 0, method );
+++

Running this code gives the following message:
WARNING: [rugg_dtmgrd in c716322] - read request for row 311730 is outside region
ERROR: problem reading raster cell file

Are the coordinates returned by Vect_get_node_coor() a valid argument for
G_get_raster_sample() ?

Sometimes. The coordinates passed to the latter must lie within the
current region, but the coordinates returned from the former can lie
outside of the current region.

You will need to manually check the coordinates against the region,
e.g.:

  Vect_get_node_coor( In, node, &x, &y, NULL );
  
  if (x >= window.west && x < window.east && y >= window.south && y < window.north)
    z = G_get_raster_sample( fdrast, &window, NULL, x, y, 0, method );
  else
    ...

Is my use of G_get_window() OK?

Yes.

--
Glynn Clements <glynn@gclements.plus.com>

On 15.07.2006, at 03:42, Glynn Clements wrote:

Sometimes. The coordinates passed to the latter must lie within the
current region, but the coordinates returned from the former can lie
outside of the current region.

Glynn,
thank you very much for your response!

I think I understand what you are saying, but:
- my vectors lie completely within the raster.
- the error occurs when the region is set to the extent of the raster as well as when it is set to the extent of the vectors.

So, how can it be that Vect_get_node_coor() returns coordinates outside the current region?

And how can it be that the error occurs even though the node really lies within the current region:

+++

/* debug output of my program: */
window.north=270001.000000
window.south=265000.000000
window.west= -45000.000000
window.east= -39000.000000
coor node 1: -41729.635417,267224.854167

WARNING: [raster] - read request for row 311730 is outside region
ERROR: problem reading raster cell file

+++

thanks again,
-Flo.

Florian Kindl wrote:

> Sometimes. The coordinates passed to the latter must lie within the
> current region, but the coordinates returned from the former can lie
> outside of the current region.

I think I understand what you are saying, but:
- my vectors lie completely within the raster.
- the error occurs when the region is set to the extent of the raster
as well as when it is set to the extent of the vectors.

So, how can it be that Vect_get_node_coor() returns coordinates
outside the current region?

And how can it be that the error occurs even though the node really
lies within the current region:

+++

/* debug output of my program: */
window.north=270001.000000
window.south=265000.000000
window.west= -45000.000000
window.east= -39000.000000
coor node 1: -41729.635417,267224.854167

WARNING: [raster] - read request for row 311730 is outside region
ERROR: problem reading raster cell file

Note the order of the coordinates:

double G_get_raster_sample (int fd,
                struct Cell_head *window,
                struct Categories *cats,
                double north, double east,
                int usedesc, INTERP_TYPE itype)

Northing first, easting second; i.e. Y first, X second.

Why do I suspect that you have them the wrong way around? If you
subtract the easting (instead of the northing) from the north edge of
the region, you get:

270001.000000 - -41729.635417 = 311730.635417

Which looks suspiciously like the "row 311730" that it's complaning
about.

--
Glynn Clements <glynn@gclements.plus.com>

On Mon, 17 Jul 2006, Glynn Clements wrote:

Note the order of the coordinates:

Northing first, easting second; i.e. Y first, X second.

                                        ^^^^^^^^^^^^^^^^^^ (!)

That's it, of course!
Glynn, you're great - thank you very much!!

-Flo.