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

GRASS GIS trac at osgeo.org
Sun Apr 28 14:21:13 PDT 2019


#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 at 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>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list