[GRASS-user] Relationships of Raster & Vector Attribute Data

   The basin map output from r.watershed is called 'dem.basin'. When I query
a basin I see the easting and northing of the point where I clicked, and a
numeric site_name variable. I've not checked all polygons, but I assume each
is uniquely numbered.

   First question: where in the mapset's directory structure is this
site_name variable stored? I've looked in the subdirectories with a
dem.basin file and do not see them.

   Converting this raster map to a vector using r.to.vect with an output name
of 'basinv', creates a postgres table with three attribute columns: cat,
value, and label. The latter is blank for all rows. The value column,
however, has the same number repeated for different polygons.

   Second question: how are these value numbers created?

   Third question: why are there multiple values for different vector
polygons where there are distinct site_name numeric values in the raster
map?

TIA,

Rich

On Wed, May 2, 2012 at 6:21 PM, Rich Shepard <rshepard@appl-ecosys.com> wrote:

The basin map output from r.watershed is called 'dem.basin'. When I query
a basin I see the easting and northing of the point where I clicked, and a
numeric site_name variable. I've not checked all polygons, but I assume each
is uniquely numbered.

First question: where in the mapset's directory structure is this
site_name variable stored? I've looked in the subdirectories with a
dem.basin file and do not see them.

It is in the cats/ subdirectory. See the second drawing in
http://grass.osgeo.org/programming6/
for the structure.

Converting this raster map to a vector using r.to.vect with an output name
of 'basinv', creates a postgres table with three attribute columns: cat,
value, and label. The latter is blank for all rows. The value column,
however, has the same number repeated for different polygons.

Second question: how are these value numbers created?

They are created if the raster maps has category labels (see
r.category).

North Carolina example.

GRASS 6.4.3svn (nc_spm_08):~ > r.category zipcodes
27511 CARY
27513 CARY
27518 CARY
27529 GARNER
...
GRASS 6.4.3svn (nc_spm_08):~ > g.region rast=zipcodes -p
projection: 99 (Lambert Conformal Conic)
zone: 0
datum: nad83
ellipsoid: a=6378137 es=0.006694380022900787
north: 228500
south: 215000
west: 630000
east: 645000
nsres: 10
ewres: 10
rows: 1350
cols: 1500
cells: 2025000

GRASS 6.4.3svn (nc_spm_08):~ > r.to.vect in=zipcodes out=myzipcodes feature=area
Extracting areas...

...
r.to.vect complete.

GRASS 6.4.3svn (nc_spm_08):~ > v.db.select myzipcodes
cat|value|label
1|27513|CARY
2|27607|RALEIGH
3|27608|RALEIGH
4|27604|RALEIGH
5|27603|RALEIGH
...

Works nicely.

Third question: why are there multiple values for different vector
polygons where there are distinct site_name numeric values in the raster
map?

Maybe too late here, I don't get the last question.

Markus

On Thu, 3 May 2012, Markus Neteler wrote:

It is in the cats/ subdirectory.

Markus,

   Interesting:

# 166 categories
Watershed basins

0.00 0.00 0.00 0.00
dem.basin lines 1-4/4 (END)

They are created if the raster maps has category labels (see
r.category).

   dem.basin: even numbers 2-166.

GRASS 6.4.3svn (nc_spm_08):~ > v.db.select myzipcodes

v.db.select basinv
cat|value|label
2|126|
3|126|
4|110|
5|2|
6|2|
7|96|
8|122|
9|20|
10|98|
11|126|
12|60|
13|130|
14|4|
15|58|
16|108|
17|14|
18|120|
19|124|
20|120|

Maybe too late here, I don't get the last question.

   Notice above from basinv: cats 2 and 3 have same value (but r.category
shows only even number cats for the raster version, dem.basin). Also cats 18
and 20 have the same value. That's what I mean by my third question: why
more categories in the vector produced in r.to.vect than in the raster
source, and why duplicate values for different categories?

Rich

Markus

--
Richard B. Shepard, Ph.D. | Integrity - Credibility - Innovation
Applied Ecosystem Services, Inc. | Helping Ensure Our Clients' Futures
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

On Thu, May 3, 2012 at 12:49 AM, Rich Shepard <rshepard@appl-ecosys.com> wrote:

On Thu, 3 May 2012, Markus Neteler wrote:

It is in the cats/ subdirectory.

Markus,

Interesting:

# 166 categories
Watershed basins

0.00 0.00 0.00 0.00
dem.basin lines 1-4/4 (END)

They are created if the raster maps has category labels (see
r.category).

dem.basin: even numbers 2-166.

GRASS 6.4.3svn (nc_spm_08):~ > v.db.select myzipcodes

v.db.select basinv
cat|value|label
2|126|
3|126|
4|110|
5|2|
6|2|
7|96|
8|122|
9|20|
10|98|
11|126|
12|60|
13|130|
14|4|
15|58|
16|108|
17|14|
18|120|
19|124|
20|120|

Maybe too late here, I don't get the last question.

Notice above from basinv: cats 2 and 3 have same value (but r.category
shows only even number cats for the raster version, dem.basin). Also cats 18
and 20 have the same value. That's what I mean by my third question: why
more categories in the vector produced in r.to.vect than in the raster
source, and why duplicate values for different categories?

If you use r.to.vect without the -v flag, each area becomes a unique
category and the raster value is stored in the column value. If you
use r.to.vect with the -v flag, raster values are used as area
categories.

There are more areas than raster basins because e.g. the basin number 1 in

1 2 2 2
3 1 2 2
3 3 1 2
3 3 3 3

will be represented as 3 separate vector areas.

Markus M

On Fri, 4 May 2012, Markus Metz wrote:

If you use r.to.vect without the -v flag, each area becomes a unique
category and the raster value is stored in the column value. If you use
r.to.vect with the -v flag, raster values are used as area categories.

Markus,

   That makes sense. As long as each basin has a unique value that can be
used to refer to it, it does not matter whether that value is in the 'cat' or
'value' column of the table.

   What remains to be resolved is why those category numbers do not display.
The shape, cat, and attr are selected for display and the category numbers
are selected as labels.

Thanks,

Rich