[GRASS-dev] [GRASS GIS] #3604: errors running r.category.trim

#3604: errors running r.category.trim
-------------------------+-------------------------
Reporter: Alister | Owner: pvanbosgeo
     Type: defect | Status: assigned
Priority: normal | Milestone:
Component: Addons | Version: 7.4.0
Keywords: | CPU: Unspecified
Platform: Unspecified |
-------------------------+-------------------------
Previously discussed at https://pvanb.wordpress.com/2015/10/31/grass-gis-
categorical-raster-layers-in-qgis/comment-page-1/#comment-12254

It works e.g. with the landuse layer from the North Carolina dataset.

But when I use my own rasters I’m getting errors like the one below:

{{{
r.category.trim input=test@Tata qgis=C:\Processing\test cat.txt
  Traceback (most recent call last):
  File “C:\Users\alistair\AppData\Roaming\GRASS7\addons/scri
  pts/r.category.trim.py”, line 197, in
  sys.exit(main(*gs.parser()))
  File “C:\Users\alistair\AppData\Roaming\GRASS7\addons/scri
  pts/r.category.trim.py”, line 123, in main
  CCAT = map(int, CCAT)
  ValueError: invalid literal for int() with base 10:
‘24.0862’
}}}

I'm pretty sure that it is an integer raster.
It was made with v.to.rast using an attr column that db.describe confirms
contains integers.

These are the categories:
{{{
r.category map=test@Tata
  24 cat2
  46 cat1
}}}

And if I load the raster into QGIS it describes it the same as the NC
landuse i.e. "Thirty two bit signed integer", and "No data value" =
-2147483648

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

#3604: errors running r.category.trim
--------------------------+-------------------------
  Reporter: Alister | Owner: pvanbosgeo
      Type: defect | Status: assigned
  Priority: normal | Milestone:
Component: Addons | Version: 7.4.0
Resolution: | Keywords:
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by pvanbosgeo):

Hi Alister, I can't find the problem; I also tried some of my own raster
layers without problems. Would it be possible to send a small test raster
layer so I can try out what goes wrong?

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

#3604: errors running r.category.trim
--------------------------+-------------------------
  Reporter: Alister | Owner: pvanbosgeo
      Type: defect | Status: assigned
  Priority: normal | Milestone:
Component: Addons | Version: 7.4.0
Resolution: | Keywords:
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------
Changes (by Alister):

* Attachment "example.pack" added.

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

#3604: errors running r.category.trim
--------------------------+-------------------------
  Reporter: Alister | Owner: pvanbosgeo
      Type: defect | Status: assigned
  Priority: normal | Milestone:
Component: Addons | Version: 7.4.0
Resolution: | Keywords:
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by Alister):

Attached.

Sorry, I meant to say that this is on Windows 10 (not an option in the
list of platforms).

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

#3604: errors running r.category.trim
--------------------------+-------------------------
  Reporter: Alister | Owner: pvanbosgeo
      Type: defect | Status: assigned
  Priority: normal | Milestone:
Component: Addons | Version: 7.4.0
Resolution: | Keywords:
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by pvanbosgeo):

I see where the problem lies. When converting a vector layer to raster, it
gets assigned a gradient color table. With your example file, run
r.colors.out.

{{{
r.colors.out map=example_vtorast@PERMANENT
}}}

This gives (I omitting the middle part)

{{{
24 68:1:84
24.0862 68:2:86
...
...
45.9138 251:231:35
46 253:231:37
nv 255:255:255
default 255:255:255
}}}

I.a.w., the categories in the color table are continuous. I would expect
that in case the values in the column used as categories in v.to.rast are
integer, the color table should be set accordingly. But as that is
evidently not the case now, I can try to find a workaround.

For now, you can either create a RGB column in the vector layer and use
that to assign colors (see v.to.rast) or set the colors using r.colors
using color rules or the interactive tool to set colors.

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

#3604: errors running r.category.trim
--------------------------+-------------------------
  Reporter: Alister | Owner: pvanbosgeo
      Type: defect | Status: assigned
  Priority: normal | Milestone:
Component: Addons | Version: 7.4.0
Resolution: | Keywords:
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by pvanbosgeo):

Hi Alister, I made a workaround, can you test (just reinstall the addon)?

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

#3604: errors running r.category.trim
--------------------------+-------------------------
  Reporter: Alister | Owner: pvanbosgeo
      Type: defect | Status: assigned
  Priority: normal | Milestone:
Component: Addons | Version: 7.4.0
Resolution: | Keywords:
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------

Comment (by Alister):

Yes it works now.

I'm not sure how you meant to reinstall the addon though - using
g.extension in the grass gui just reinstalls the old version, so I had to
manually get the changes from
https://trac.osgeo.org/grass/changeset?reponame=&new=72994%40grass-
addons%2Fgrass7%2Fraster%2Fr.category.trim%2Fr.category.trim.py&old=70756
%40grass-addons%2Fgrass7%2Fraster%2Fr.category.trim%2Fr.category.trim.py.

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

#3604: errors running r.category.trim
--------------------------+-----------------------------
  Reporter: Alister | Owner: pvanbosgeo
      Type: defect | Status: assigned
  Priority: normal | Milestone:
Component: Addons | Version: 7.4.0
Resolution: | Keywords: r.category.trim
       CPU: Unspecified | Platform: MSWindows 2K
--------------------------+-----------------------------
Changes (by neteler):

* keywords: => r.category.trim
* platform: Unspecified => MSWindows 2K

Comment:

Replying to [comment:5 Alister]:
> Yes it works now, thanks.
>
> I'm not sure how you meant to reinstall the addon though - using
g.extension in the grass gui just reinstalls the old version, [...]

FYI: Since you are on Windows g.extension fetches addons which are
generated daily (but not in real time) on the Windows-build host. This
happens AFAIK once a day, so give it a 24s to show up online. (in your
case here fine that you downloaded the update directly from trac since it
is the addon is written in Python not requiring true compilation).

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

#3604: errors running r.category.trim
--------------------------+-----------------------------
  Reporter: Alister | Owner: pvanbosgeo
      Type: defect | Status: closed
  Priority: normal | Milestone:
Component: Addons | Version: 7.4.0
Resolution: fixed | Keywords: r.category.trim
       CPU: Unspecified | Platform: MSWindows 2K
--------------------------+-----------------------------
Changes (by pvanbosgeo):

* status: assigned => closed
* resolution: => fixed

Comment:

Ah, yes, you are on Windows of course. Thanks Markus for clarifying. I am
closing this ticket as it seems to be solved. Please reopen if needed.

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