[GRASS-user] problem in v.drape command

hello

when I entered this command, I received following error message:

~~~~~~~~~~~~
GRASS 6.3.cvs (bartin):~ > v.drape in=jeo3 out=jeo3d2 rast=eldene type=face --overwrite
defaulting to nearest neighbor sampling
WARNING: The vector 'jeo3d2' already exists and will be overwritten.
WARNING: [eldene in orkun] - read request for row -1 is outside region
ERROR: problem reading raster cell file
[Raster MASK present]
~~~~~~~~~~~~~

can you tell me what the problem may be ?

regards

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

temiz wrote on 07/09/2007 07:26 PM:

hello

when I entered this command, I received following error message:

~~~~~~~~~~~~
GRASS 6.3.cvs (bartin):~ > v.drape in=jeo3 out=jeo3d2 rast=eldene
type=face --overwrite
defaulting to nearest neighbor sampling
WARNING: The vector 'jeo3d2' already exists and will be overwritten.
WARNING: [eldene in orkun] - read request for row -1 is outside region
ERROR: problem reading raster cell file
[Raster MASK present]
~~~~~~~~~~~~~

can you tell me what the problem may be ?

The problem is that the vector map is bigger than the raster map.
You need to use

g.region rast=dem
v.in.region box
v.overlay ... with box and your vector map to restrict the vector map to
the DEM size
v.drape ... with the reduced vector map.

Markus

------------------
ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
ITC -> since 1 March 2007 Fondazione Bruno Kessler
------------------

Is this a place where the error message could be made clearer? For example,
could it add possible sources of the problem such as the one Markus
indicated, or are there too many possibilities for ways to do it wrong?

Jerry

-----Original Message-----
From: grassuser-bounces@grass.itc.it [mailto:grassuser-bounces@grass.itc.it]
On Behalf Of Markus Neteler
Sent: Monday, July 09, 2007 8:43 AM
To: grassuser@grass.itc.it
Subject: Re: [GRASS-user] problem in v.drape command

temiz wrote on 07/09/2007 07:26 PM:

hello

when I entered this command, I received following error message:

~~~~~~~~~~~~
GRASS 6.3.cvs (bartin):~ > v.drape in=jeo3 out=jeo3d2 rast=eldene
type=face --overwrite
defaulting to nearest neighbor sampling
WARNING: The vector 'jeo3d2' already exists and will be overwritten.
WARNING: [eldene in orkun] - read request for row -1 is outside region
ERROR: problem reading raster cell file
[Raster MASK present]
~~~~~~~~~~~~~

can you tell me what the problem may be ?

The problem is that the vector map is bigger than the raster map.
You need to use

g.region rast=dem
v.in.region box
v.overlay ... with box and your vector map to restrict the vector map to
the DEM size
v.drape ... with the reduced vector map.

Markus

------------------
ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
ITC -> since 1 March 2007 Fondazione Bruno Kessler
------------------

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser

Jerry Nelson wrote on 07/09/2007 04:18 PM:

Is this a place where the error message could be made clearer? For example,
could it add possible sources of the problem such as the one Markus
indicated, or are there too many possibilities for ways to do it wrong?

Jerry,

I agree that the error isn't helpful and stumbled myself over it several
times.
It is buried in the core of GRASS:
cd grass63/lib/gis/
grep 'is outside region' *
get_row.c: G_warning(_("[%s in %s] - read request for row %d is
outside region"),
get_row.c: G_warning(_("[%s in %s] - read request for row %d is
outside region"),

so I don't know how to link it to v.drape. At least, I have expanded the
manual page to

########## snip ##########
ERROR MESSAGES
If the following error message appears

WARNING: [demname in mapset] - read request for row -1 is outside region
ERROR: problem reading raster cell file

it indicates that the vector map is spatially larger than the raster
map. To avoid this problem, the vector map needs to be clipped to the
raster map extent, for example:

g.region rast=demname
v.in.region clipbox
v.overlay ain=clipbox bin=vectmap out=vectmap_clipped op=and
v.drape vectmap_clipped out=vectdrape rast=demname

Then /v.drape/ should perform the draping.
########## snip ##########

Hopefully helpful,
Markus

-----Original Message-----
From: grassuser-bounces@grass.itc.it [mailto:grassuser-bounces@grass.itc.it]
On Behalf Of Markus Neteler
Sent: Monday, July 09, 2007 8:43 AM
To: grassuser@grass.itc.it
Subject: Re: [GRASS-user] problem in v.drape command

temiz wrote on 07/09/2007 07:26 PM:
  

hello

when I entered this command, I received following error message:

~~~~~~~~~~~~
GRASS 6.3.cvs (bartin):~ > v.drape in=jeo3 out=jeo3d2 rast=eldene
type=face --overwrite
defaulting to nearest neighbor sampling
WARNING: The vector 'jeo3d2' already exists and will be overwritten.
WARNING: [eldene in orkun] - read request for row -1 is outside region
ERROR: problem reading raster cell file
[Raster MASK present]
~~~~~~~~~~~~~

can you tell me what the problem may be ?
    

The problem is that the vector map is bigger than the raster map.
You need to use

g.region rast=dem
v.in.region box
v.overlay ... with box and your vector map to restrict the vector map to
the DEM size
v.drape ... with the reduced vector map.

Markus

------------------
ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
ITC -> since 1 March 2007 Fondazione Bruno Kessler
------------------

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser

------------------
ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
ITC -> since 1 March 2007 Fondazione Bruno Kessler
------------------

Jerry and others,

The v.drape module was created by suggestion of Radim, and implemented by an
amateur (me). This bug is one of the last remaining issues in the code.
Although it is mentioned in the manual page, it would be good to do a simple
test of

if vector %in% current region or vector %in% raster bbox
then run
else error and exit

I am not sure how to implement this check, but if I get some feedback I will
submit a patch!

cheers,

dylan

On Monday 09 July 2007 07:18, Jerry Nelson wrote:

Is this a place where the error message could be made clearer? For example,
could it add possible sources of the problem such as the one Markus
indicated, or are there too many possibilities for ways to do it wrong?

Jerry

-----Original Message-----
From: grassuser-bounces@grass.itc.it
[mailto:grassuser-bounces@grass.itc.it] On Behalf Of Markus Neteler
Sent: Monday, July 09, 2007 8:43 AM
To: grassuser@grass.itc.it
Subject: Re: [GRASS-user] problem in v.drape command

temiz wrote on 07/09/2007 07:26 PM:
> hello
>
> when I entered this command, I received following error message:
>
> ~~~~~~~~~~~~
> GRASS 6.3.cvs (bartin):~ > v.drape in=jeo3 out=jeo3d2 rast=eldene
> type=face --overwrite
> defaulting to nearest neighbor sampling
> WARNING: The vector 'jeo3d2' already exists and will be overwritten.
> WARNING: [eldene in orkun] - read request for row -1 is outside region
> ERROR: problem reading raster cell file
> [Raster MASK present]
> ~~~~~~~~~~~~~
>
> can you tell me what the problem may be ?

The problem is that the vector map is bigger than the raster map.
You need to use

g.region rast=dem
v.in.region box
v.overlay ... with box and your vector map to restrict the vector map to
the DEM size
v.drape ... with the reduced vector map.

Markus

------------------
ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
ITC -> since 1 March 2007 Fondazione Bruno Kessler
------------------

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser

Dylan Beaudette wrote:

The v.drape module was created by suggestion of Radim, and implemented
by an amateur (me). This bug is one of the last remaining issues in
the code. Although it is mentioned in the manual page, it would be
good to do a simple test of

if vector %in% current region or vector %in% raster bbox
then run else error and exit

I am not sure how to implement this check, but if I get some feedback
I will submit a patch!

I think the libgis error is appropriate, but that v.drape should not be
trying to load a raster array i,j which is out of range. Perhaps in
these cases the Z value should be set to NULL (nan), or if that is
illegal either set to 0 (with warning) or G_fatal_error() out.

You can check in map is contained within the current region by reading
the map header info and the current region settings,

e.g. read current region into "window":

struct Cell_head window;
G_get_window(&window);

then you have doubles: window.north, .south, .east, .west, .top, .bottom

To read vector bounds:

struct Map_info Map;
BOUND_BOX box;

Vect_open_old_head (&Map, input->answer, mapset);
Vect_get_map_box (&Map, &box);

then you have doubles: box.N, box.S, box.E, box.W, box.T, box.B

compare:

if ( (box.N > window.north) || (box.S < window.south) ||
     (box.E > window.east) || (box.W < window.west) )
    G_warning("Vector exists outside of raster region");

...

Hamish

On Monday 09 July 2007 20:07, Hamish wrote:

Dylan Beaudette wrote:
> The v.drape module was created by suggestion of Radim, and implemented
> by an amateur (me). This bug is one of the last remaining issues in
> the code. Although it is mentioned in the manual page, it would be
> good to do a simple test of
>
> if vector %in% current region or vector %in% raster bbox
> then run else error and exit
>
> I am not sure how to implement this check, but if I get some feedback
> I will submit a patch!

I think the libgis error is appropriate, but that v.drape should not be
trying to load a raster array i,j which is out of range. Perhaps in
these cases the Z value should be set to NULL (nan), or if that is
illegal either set to 0 (with warning) or G_fatal_error() out.

You can check in map is contained within the current region by reading
the map header info and the current region settings,

e.g. read current region into "window":

struct Cell_head window;
G_get_window(&window);

then you have doubles: window.north, .south, .east, .west, .top, .bottom

To read vector bounds:

struct Map_info Map;
BOUND_BOX box;

Vect_open_old_head (&Map, input->answer, mapset);
Vect_get_map_box (&Map, &box);

then you have doubles: box.N, box.S, box.E, box.W, box.T, box.B

compare:

if ( (box.N > window.north) || (box.S < window.south) ||
     (box.E > window.east) || (box.W < window.west) )
    G_warning("Vector exists outside of raster region");

...

Hamish

Ok I will give it a shot, and post the patch when it is working!

cheers,

Dylan

PS: do you think that we should exit after issuing the warning? If so, is
there a G_ function to do that cleanly?

On Monday 09 July 2007 20:07, Hamish wrote:

Dylan Beaudette wrote:
> The v.drape module was created by suggestion of Radim, and implemented
> by an amateur (me). This bug is one of the last remaining issues in
> the code. Although it is mentioned in the manual page, it would be
> good to do a simple test of
>
> if vector %in% current region or vector %in% raster bbox
> then run else error and exit
>
> I am not sure how to implement this check, but if I get some feedback
> I will submit a patch!

I think the libgis error is appropriate, but that v.drape should not be
trying to load a raster array i,j which is out of range. Perhaps in
these cases the Z value should be set to NULL (nan), or if that is
illegal either set to 0 (with warning) or G_fatal_error() out.

You can check in map is contained within the current region by reading
the map header info and the current region settings,

e.g. read current region into "window":

struct Cell_head window;
G_get_window(&window);

then you have doubles: window.north, .south, .east, .west, .top, .bottom

To read vector bounds:

struct Map_info Map;
BOUND_BOX box;

Vect_open_old_head (&Map, input->answer, mapset);
Vect_get_map_box (&Map, &box);

then you have doubles: box.N, box.S, box.E, box.W, box.T, box.B

compare:

if ( (box.N > window.north) || (box.S < window.south) ||
     (box.E > window.east) || (box.W < window.west) )
    G_warning("Vector exists outside of raster region");

...

Hamish

A patch based on this suggestion is attached. I have tested and it appears to
work.

Dylan

(attachments)

v.drape-region-fix.patch (9.3 KB)

PS: do you think that we should exit after issuing the warning?

If vector z values can be assigned to NULL, I'd suggest G_warning(). If
0 I'd suggest don't write bad data and G_fatal_error() (which calls
exit(EXIT_FAILURE). But I've no experience with the module, so that's
just my 2c.

If so, is there a G_ function to do that cleanly?

just use G_fatal_error() without G_warning().

A patch based on this suggestion is attached. I have tested and it
appears to work.

AFAICT it looks ok, but it is very hard to read:

Please keep indentation and code patches separate. It makes it very hard
to see real changes in the .diff. See SUBMITTING rule #15. Also please
follow the suggested indent rules for new code. (indent level of 4,
tabstop of 8, max line length 80 chars)

indent codes explained:
http://grass.gdf-hannover.de/wiki/Development#Explanation_of_C_indentation_rules

thanks,
Hamish