[GRASS-user] Problems with v.what.rast

Dear all,

I’m having some trouble copying the values from a raster image (Dartmoor1) to a series of vector points (Contour_points - created from a contour vector map). When I try to use v.what.rast I get the following error:

v.what.rast vector=Contour_points@PERMANENT raster=dartmoor1@PERMANENT layer=1 column=level
More points (644858) of category 1, value set to ‘NULL’
1 categories loaded from table
1 categories loaded from vector
0 categories from vector missing in table
1 duplicate categories in vector
1 records updated
0 update errors

I think that this is an attribute table issue. I have followed the instructions in Example B http://grass.itc.it/grass62/manuals/html62_user/v.what.rast.html but get the following message

v.to.db map=Contour_points option=cat
Reading features…
Updating database…
1 categories read from vector map (layer 1)
1 records selected from table (layer 1)
1 categories read from vector map exist in selection from table
0 records updated/inserted (layer 1)
Record (cat 1) already exists (not inserted)

I have also tried creating and attaching a new table but get the same result for v.what.vect. Any ideas welcome, thanks for reading!

Rebecca

Dear all,

I’m having some trouble copying the values from a raster image (Dartmoor1) to a series of vector points (Contour_points - created from a contour vector map). When I try to use v.what.rast I get the following error:

v.what.rast vector=Contour_points@PERMANENT raster=dartmoor1@PERMANENT layer=1 column=level
More points (644858) of category 1, value set to ‘NULL’
1 categories loaded from table
1 categories loaded from vector
0 categories from vector missing in table
1 duplicate categories in vector
1 records updated
0 update errors

Looks like all the points in Contour_points have the same cat value. Check this with:
v.category Contour_points opt=report

You can add new separate cat values for each point like this:
v.category Contour_points opt=del out=Contour_points_tmp
v.category Contour_points_tmp opt=add out=Contour_points_cats
(get rid of the tmp vector: g.remove vect=Contour_points_tmp)

Now check:
v.category Contour_points_cats opt=report

Next setup a column for the rast values:
v.db.addcol Contour_points_cats col=“rast_value double”
(Is your raster an integer or float raster??)
And now you should be able to get the raster values into the points attrib table with:

v.what.rast Contour_points_cats rast=Dartmoor1 col=rast_value

···
-- 
Micha Silver
Arava Development Co. +972-52-3665918
[http://surfaces.co.il](http://surfaces.co.il)

Hi Micha

Thanks for your help. I followed your instructions to add add separate cat values for each point, so the results of v.category Contour_points_cats opt=report now looks like this
v.category Contour_points_cats opt=report
Layer: 2
type count min max
point 644858 1 644858
line 0 0 0
boundary 0 0 0
centroid 0 0 0
area 0 0 0
all 644858 1 644858
Layer/table: 1/Contour_points_cats
type count min max
point 644858 1 644858
line 0 0 0
boundary 0 0 0
centroid 0 0 0
area 0 0 0
all 644858 1 644858

I added a column v.db.addcol map=Contour_points_cats@PERMANENT layer=1 {columns=rast_value double precision} (as my raster is a float), then ran with error

v.what.rast vector=Contour_points_cats@PERMANENT raster=dartmoor1@PERMANENT layer=1 column=rast_value

No record for category 553 in table <Contour_points_cats>

No record for category 263 in table <Contour_points_cats>
No record for category 668 in table <Contour_points_cats>

essentially the “No Record” error was repeated lots of times and the tool stopped working.

I’m a bit stumped by this - any suggestions? (I have double checked my region to make sure it incorporates the whole area of interest)

cheers,
Rebecca

···
-- 
Micha Silver
Arava Development Co. +972-52-3665918
[http://surfaces.co.il](http://surfaces.co.il)

Hi,

2010/6/9 Rebecca Bennett <rabennett@ymail.com>:

I added a column v.db.addcol map=Contour_points_cats@PERMANENT layer=1
{columns=rast_value double precision} (as my raster is a float), then ran
with error

how did you get this command?

It should be

v.db.addcol map=Contour_points_cats@PERMANENT layer=1
columns="rast_value double precision"

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Hi Martin,

I tried the command that Micha suggested v.db.addcol map=Contour_points_cats@PERMANENT layer=1
columns=“rast_value double precision” but this age the following error

v.db.addcol Contour_points_cats col=rast_value DOUBLE PRECISION
Sorry is not a valid option
Sorry is not a valid option

So through the GUI I added a column to the attribute table which gave the command line out put
v.db.addcol map=Contour_points_cats@PERMANENT layer=1 {columns=rast_value double precision}

cheers!


From: Martin Landa landa.martin@gmail.com
To: Rebecca Bennett rabennett@ymail.com
Cc: Micha Silver micha@arava.co.il; grass-user@lists.osgeo.org
Sent: Wed, 9 June, 2010 9:37:14
Subject: Re: [GRASS-user] Re: Problems with v.what.rast

Hi,

2010/6/9 Rebecca Bennett <rabennett@ymail.com>:

I added a column v.db.addcol map=Contour_points_cats@PERMANENT layer=1
{columns=rast_value double precision} (as my raster is a float), then ran
with error

how did you get this command?

It should be

v.db.addcol map=Contour_points_cats@PERMANENT layer=1
columns=“rast_value double precision”

Martin


Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Hi,

2010/6/9 Rebecca Bennett <rabennett@ymail.com>:

I tried the command that Micha suggested v.db.addcol
map=Contour_points_cats@PERMANENT layer=1
columns="rast_value double precision" but this age the following error

v.db.addcol Contour_points_cats col=rast_value DOUBLE PRECISION
Sorry <DOUBLE> is not a valid option
Sorry <PRECISION> is not a valid option

the quotes are required, so `col="rast_value DOUBLE PRECISION"`.

So through the GUI I added a column to the attribute table which gave the
command line out put
v.db.addcol map=Contour_points_cats@PERMANENT layer=1 {columns=rast_value
double precision}

Which GUI (TCL/TK or wxGUI), which version of GRASS?

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Hi Martin,

I tried the command that Micha suggested v.db.addcol map=Contour_points_cats@PERMANENT layer=1
columns=“rast_value double precision” but this age the following error

The quotes " " around the “rast_value DOUBLE PRECISION” are necessary. Just to check can we see the output of
v.info -c Contour_points_cats

You might also check that the points are all within the raster region.
i.e.:
v.info -g Contour_points_cats
r.info -g Dartmoor1
g.region -p

···
-- 
Micha Silver
[http://www.surfaces.co.il/](http://www.surfaces.co.il/)
Arava Development Co.  +972-52-3665918

Hi all,

I have deleted the column I added and tried all command line permutations of
v.db.addcol map=Contour_points_cats@PERMANENT layer=1 col="rast_value DOUBLE PRECISION"
v.db.addcol map=Contour_points_cats@PERMANENT layer=1 columns="rast_value DOUBLE PRECISION"
that have so far been given in this thread, again with quotes and without. Unfortunately it does not recognise this command, which I why I used the GUI

The GUI is tcltk on GRASS 6.4

Micha - I have checked the points are within the raster (they were created from a contour map of the raster). The region is consistent with both the raster and vector

Thanks!

···
-- 
Micha Silver
[http://www.surfaces.co.il/](http://www.surfaces.co.il/)
Arava Development Co.  +972-52-3665918

Hi,

2010/6/9 Rebecca Bennett <rabennett@ymail.com>:

I have deleted the column I added and tried all command line permutations of
v.db.addcol map=Contour_points_cats@PERMANENT layer=1 `col="rast_value
DOUBLE PRECISION"`
v.db.addcol map=Contour_points_cats@PERMANENT layer=1 `columns="rast_value
DOUBLE PRECISION"`

ones more - the correct form is (without ``)

v.db.addcol map=Contour_points_cats@PERMANENT layer=1 col="rast_value
DOUBLE PRECISION"

Note that you can edit only vector maps from the current mapset.

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

[back to ML]

Hi,

2010/6/9 Rebecca Bennett <rabennett@ymail.com>:

Ubuntu Hardy, I was entering the commands in the Output section of the GUI,
but have now entered it into the bash terminal and it worked. I did not
realise that there were commands that were fussy about where they were
input... thanks for your patience.

so it's a TCL/TK GUI bug. Please fill the ticket in the GRASS trac.

Also please consider usage of wxGUI [1] which is also available in
GRASS 6.4. More advanced wxGUI can be found in GRASS 6.5.

g.gui wxpython

Martin

[1] http://grass.osgeo.org/wiki/WxGUI

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Good Morning,

So yesterday, with lots of help from Micha and Martin, I got a vector file with a new column using bash. However when I try to run v.what.rast I get the continuous error

v.what.rast vector=Contour_points_cats@PERMANENT raster=dartmoor1@PERMANENT layer=1 column=rast_value
“No record for category 553 in table <Contour_points_cats>
No record for category 263 in table <Contour_points_cats>
No record for category 668 in table <Contour_points_cats>” etc etc

then the tool crashes without writing any values to the vector. I have checked that all points are both within the region and the raster extent and that the column type is correct for my float raster. Does anyone have any suggestions as to what I might be doing wrong?

Many thanks for reading,
Rebecca

···
-- 
Micha Silver
[http://www.surfaces.co.il/](http://www.surfaces.co.il/)
Arava Development Co.  +972-52-3665918

Good Morning,

So yesterday, with lots of help from Micha and Martin, I got a vector file with a new column using bash. However when I try to run v.what.rast I get the continuous error

v.what.rast vector=Contour_points_cats@PERMANENT raster=dartmoor1@PERMANENT layer=1 column=rast_value
“No record for category 553 in table <Contour_points_cats>
No record for category 263 in table <Contour_points_cats>
No record for category 668 in table <Contour_points_cats>” etc etc

then the tool crashes without writing any values to the vector. I have checked that all points are both within the region and the raster extent and that the column type is correct for my float raster. Does anyone have any suggestions as to what I might be doing wrong?

I think I know what the problem might be. You’ll need to remove the database table, then recreate it. This step should make a new entry for each cat value in a new table. The “v.category opt=del” does wipe out the single category, but it doesn’t touch the old database table, which might be left with just the single row for cat=1 from your original Contour_points layer.

So what you’ll need is
v.db.droptable Contour_points_cats -f # -f=force
v.db.addtable Contour_points_cats col=“rast_val double precision”

Check with:

v.db.select Contour_points_cats

One line for each cat/point?

Now this should work

v.what.rast Contour_points_cats rast=dartmoor1 col=rast_val

Attached is a script I tested which does the whole procedure. It prompts you for the original point vector and raster, then creates a new vector (named “_cats”) with individual cats for each point, deletes then recreates its table and adds a “rast_val” column, then queries the raster for values.
Warning: the script overwrites the vector named _cats.
Warning 2: No checks for region, etc. Use at your own risk…
There’s lots of output, so you should be able to follow what’s going on.

Regards,
Micha

(attachments)

recat_points.zip (712 Bytes)

···
-- 
Micha Silver
[http://www.surfaces.co.il/](http://www.surfaces.co.il/)
Arava Development Co.  +972-52-3665918
  
-- 
Micha Silver
Arava Development Co. +972-52-3665918
[http://www.surfaces.co.il](http://www.surfaces.co.il)
 

Hi there,

Have had chance to run this script today and it works just fine on my data, thank you so much for your help

Rebecca

···
-- 
Micha Silver
[http://www.surfaces.co.il/](http://www.surfaces.co.il/)
Arava Development Co.  +972-52-3665918
  
-- 
Micha Silver
Arava Development Co. +972-52-3665918
[http://www.surfaces.co.il](http://www.surfaces.co.il)
 

On 12/06/2010 18:38, Rebecca Bennett wrote:

Hi there,

Have had chance to run this script today and it works just fine on my data, thank you so much for your help

Rebecca


That’s doubly good to hear. (Both your success and the thanks)

Micha