Opened 6 years ago

Last modified 4 years ago

#3679 new enhancement

Convert numeric raster category labels to numeric column in the output vector map's attribute table

Reported by: Nikos Alexandris Owned by: grass-dev@…
Priority: minor Milestone: 7.8.3
Component: Raster Version: svn-trunk
Keywords: r.to.vect Cc:
CPU: Unspecified Platform: Unspecified

Description

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.

Change History (6)

comment:1 by martinl, 6 years ago

Component: DefaultRaster
Milestone: 7.8.0
Version: unspecifiedsvn-trunk

comment:2 by Nikos Alexandris, 5 years ago

An virtual example using maps from the 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

comment:3 by neteler, 5 years ago

Milestone: 7.8.07.8.1

Ticket retargeted after milestone closed

comment:4 by neteler, 4 years ago

Milestone: 7.8.17.8.2

Ticket retargeted after milestone closed

comment:5 by neteler, 4 years ago

Milestone: 7.8.2

Ticket retargeted after milestone closed

comment:6 by neteler, 4 years ago

Milestone: 7.8.3
Note: See TracTickets for help on using tickets.