[GRASS-dev] [GRASS GIS] #3679: Convert numeric raster category labels to numeric column in the output vector map's attribute table

#3679: Convert numeric raster category labels to numeric column in the output
vector map's attribute table
------------------------------+-------------------------
Reporter: Nikos Alexandris | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: minor | Milestone:
Component: Default | Version: unspecified
Keywords: r.to.vect | CPU: Unspecified
Platform: Unspecified |
------------------------------+-------------------------
Converting a raster which holds category labels to vector using
`r.to.vect`, i.e.
{{{
r.to.vect in=raster_map out=vector_map type=area
}}}

will add the columns `value` and `label`.
{{{
v.info -c vector_map
Displaying column types/names for database connection of layer <1>:
INTEGER|cat
INTEGER|value
CHARACTER|label
}}}

Since `r.mapcalc` supports for some math using numbers stored as category
labels (via the @ operator) and, as well, `r.stats.zonal` writes numeric
results as category labels via its `-r` flag, it would make sense to
support for the addition of a numeric (int or double) column type in the
output vector map's attribute table. Perhaps this could be done via a
flag.

I understand that this might bring a series of tests to perform before
attempting adding such a column in the output attribute table. Such as
"are all labels numeric?" and "should the output be 'int' or 'double'?".
Yet, it would help to streamline processes that involve such conversions.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3679&gt;
GRASS GIS <https://grass.osgeo.org>

#3679: Convert numeric raster category labels to numeric column in the output
vector map's attribute table
-------------------------------+-------------------------
  Reporter: Nikos Alexandris | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: minor | Milestone: 7.8.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.to.vect
       CPU: Unspecified | Platform: Unspecified
-------------------------------+-------------------------
Changes (by martinl):

* version: unspecified => svn-trunk
* component: Default => Raster
* milestone: => 7.8.0

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3679#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3679: Convert numeric raster category labels to numeric column in the output
vector map's attribute table
-------------------------------+-------------------------
  Reporter: Nikos Alexandris | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: minor | Milestone: 7.8.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.to.vect
       CPU: Unspecified | Platform: Unspecified
-------------------------------+-------------------------

Comment (by Nikos Alexandris):

An virtual example using maps from the
[https://grass.osgeo.org/sampledata/north_carolina/nc_basic_spm_grass7.tar.gz
nc_basic_spm_grass7.tar.gz] Location:

An integer version of the `elevation` map
{{{
r.info elevation_int -r
min=55
max=156
}}}
and the `geology` map
{{{
r.report geology -hn --q
+-----------------------------------------------------------------------------+
| Category Information
|
| #|description
|
|-----------------------------------------------------------------------------|
|217|CZfg
|
|262|CZlg
|
|270|CZig
|
|405|CZbg
|
|583|CZve
|
|720|CZam
|
|766|CZg
|
|862|CZam
|
|910|CZbg
|
|921|Km
|
|945|CZbg
|
|946|CZam
|
|948|CZam
|
+-----------------------------------------------------------------------------+
}}}

Compute the average elevation value
for each geology "type",
and store it as a category label
in the output raster map `elevation_of_geologies`
{{{
r.stats.zonal -r base=geology cover=elevation method=average
output=elevation_of_geologies
First pass
  100%
Generating reclass map
}}}

Report the new map's categories and labels,
in which case, these are
the geology "type"
and the average elevation
{{{
r.report -hn --q elevation_of_geologies
+-----------------------------------------------------------------------------+
| Category Information
|
| #|description
|
|-----------------------------------------------------------------------------|
|217|118.926884
|
|262|108.969823
|
|270|92.227103
|
|405|132.957558
|
|583|139.353428
|
|720|124.298955
|
|766|132.427368
|
|862|118.309800
|
|910|94.204611
|
|921|135.215935
|
|945|127.235592
|
|946|89.908638
|
|948|129.016971
|
+-----------------------------------------------------------------------------+
}}}

Convert the raster map `elevation_of_geologies`
into a vector map named `elevation_of_geologies_vector`,
via
{{{
r.to.vect elevation_of_geologies output=elevation_of_geologies_vector
type=area
Extracting areas...
  100%
Writing areas...
  100%
Building topology for vector map <elevation_of_geologies_vector@user1>...
Registering primitives...
49 primitives registered
1068 vertices registered
Building areas...
  100%
13 areas built
One isle built
Attaching islands...
  100%
Attaching centroids...
  100%
Number of nodes: 24
Number of primitives: 49
Number of points: 0
Number of lines: 0
Number of boundaries: 36
Number of centroids: 13
Number of areas: 13
Number of isles: 1
r.to.vect complete.
}}}
The new vector map has the following attributes:
{{{
v.info -c elevation_of_geologies_vector
Displaying column types/names for database connection of layer <1>:
INTEGER|cat
INTEGER|value
CHARACTER|label
}}}

It would be a convenience to actually have `r.to.vect` create a column of
type `INTEGER` or `DOUBLE PRECISION` for the "average elevation values",
according to the type of numbers that are stored as raster category
labels.

Something like an `-n` flag (`-n` Write raster category labels as numeric
values), i.e.
{{{
r.to.vect -n elevation_of_geologies output=elevation_of_geologies_vector
type=area
}}}

could produce a vector map for which `v.info -c
elevation_of_geologies_vector` will show something like:
{{{
INTEGER|cat
INTEGER|value
INTEGER|statistics
}}}
or
{{{
INTEGER|cat
INTEGER|value
DOUBLE PRECISION|statistics
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3679#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>