Opened 6 years ago

Closed 6 years ago

#3604 closed defect (fixed)

errors running r.category.trim

Reported by: Alister Owned by: pvanbosgeo
Priority: normal Milestone:
Component: Addons Version: 7.4.0
Keywords: r.category.trim Cc:
CPU: Unspecified Platform: MSWindows 2K

Description

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

Attachments (1)

example.pack (1.8 KB ) - added by Alister 6 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by pvanbosgeo, 6 years ago

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?

by Alister, 6 years ago

Attachment: example.pack added

comment:2 by Alister, 6 years ago

Attached.

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

comment:3 by pvanbosgeo, 6 years ago

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.

comment:4 by pvanbosgeo, 6 years ago

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

comment:5 by Alister, 6 years ago

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.

Version 0, edited 6 years ago by Alister (next)

in reply to:  5 comment:6 by neteler, 6 years ago

Keywords: r.category.trim added
Platform: UnspecifiedMSWindows 2K

Replying to 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).

comment:7 by pvanbosgeo, 6 years ago

Resolution: fixed
Status: assignedclosed

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.

Note: See TracTickets for help on using tickets.