[GRASS-dev] [GRASS GIS] #2501: r.out.gdal -t creates offset values in raster table for integer grids with values beginning with 1

GRASS GIS trac at osgeo.org
Wed Nov 26 11:01:07 PST 2014


#2501: r.out.gdal -t creates offset values in raster table for integer grids with
values beginning with 1
--------------------------------------------------+-------------------------
 Reporter:  dnewcomb                              |       Owner:  grass-dev@…              
     Type:  defect                                |      Status:  new                      
 Priority:  normal                                |   Milestone:  7.0.0                    
Component:  Default                               |     Version:  svn-releasebranch70      
 Keywords:  r.out.gdal table attribute alignment  |    Platform:  Linux                    
      Cpu:  x86-64                                |  
--------------------------------------------------+-------------------------
 Exporting integer grids with values starting with 1 using r.out.gdal -t
 results in a raster attribute table with vertically shifted values in the
 last 3 columns.
 For example, if you have a raster with values of 1 to 5 with associated
 classes, you would expect a table that looks like this:
 OID Value MIN MAX CLASS
 1     1    1   1   flat
 2     2    2   2   summit
 3     3    3   3   ridge
 4     4    4   4   shoulder
 5     5    5   5   spur

 ( Should the OID start with 0?, not sure )

 In the current version of the software, the output table looks like this:
 OID Value MIN  MAX CLASS
 0    0     1    1    flat
 1    1     2    2    summit
 2    2     3    3    ridge
 3    3     4    4    shoulder
 4    4     5    5    spur
 5    5     0    0    ERROR

 See http://lists.osgeo.org/pipermail/grass-dev/2014-November/072021.html,

 The issue seems to be in lines 73 - 78 in r.out.gdal/attr.c:

         if (maptype == CELL_TYPE) {
           for (i = 0; i < cats.ncats; i++) {
             label = Rast_get_ith_c_cat(&cats, i, &CellMin, &CellMax);
                 GDALRATSetValueAsInt(hrat, i, 0, CellMin);
                 GDALRATSetValueAsInt(hrat, i, 1, CellMax);
                 GDALRATSetValueAsString(hrat, i, 2, label);

 With this current ugly hack I've got has the values aligned with the
 classes again, but there is an extra OID 0 line with 0 or blank values for
 the fields at the beginning of the table.

         if (maptype == CELL_TYPE) {
           for (i = 0; i < cats.ncats-1; i++) {
             label = Rast_get_ith_c_cat(&cats, i, &CellMin, &CellMax);
                 GDALRATSetValueAsInt(hrat, i+1, 0, CellMin);
                 GDALRATSetValueAsInt(hrat, i+1, 1, CellMax);
                 GDALRATSetValueAsString(hrat, i+1, 2, label);

 Sample output to this hack would be:
 OID Value MIN MAX CLASS
 0     0    0   0
 1     1    1   1   flat
 2     2    2   2   summit
 3     3    3   3   ridge
 4     4    4   4   shoulder
 5     5    5   5   spur

 This does not look quite right.

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/2501>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list