When linking external raster maps with r.external, I have to manually
create a corresponding cats file, otherwise a number of modules, e.g.
d.rast do not work properly. Is there any reason why no corresponding
cats file is produced?
This patch for trunk works for me:
--->
Index: main.c
--- main.c (revision 46815)
+++ main.c (working copy)
@@ -461,6 +461,7 @@
const char *title, int flip)
{
struct History history;
+ struct Categories cats;
Rast_put_cellhd(output, cellhd);
@@ -491,6 +492,8 @@
Rast_write_history(output, &history);
Rast_write_colors(output, G_mapset(), &info->colors);
+ Rast_init_cats(NULL, &cats);
+ Rast_write_cats((char *)output, &cats);
if (title)
Rast_put_cell_title(output, title);
<---
Markus M
Markus Metz wrote:
When linking external raster maps with r.external, I have to manually
create a corresponding cats file, otherwise a number of modules, e.g.
d.rast do not work properly. Is there any reason why no corresponding
cats file is produced?
IMHO, modules should not be required to explicitly write a cats file.
GRASS 4.x is ancient history, and raster maps are no longer inherently
category-based.
Raster modules should only write a cats file if they actually have
something meaningful to put in it.
Either Rast_read_cats() should silently return an empty category
structure if no cats file is present, or Rast_close() should
automatically generate an empty cats file if no cats file was
explicitly written.
I'm inclined towards the former, unless there might be cases where the
distinction between "no category list" and "empty category list" would
matter.
--
Glynn Clements <glynn@gclements.plus.com>
On Wed, Jun 29, 2011 at 12:23 AM, Glynn Clements
<glynn@gclements.plus.com> wrote:
Markus Metz wrote:
When linking external raster maps with r.external, I have to manually
create a corresponding cats file, otherwise a number of modules, e.g.
d.rast do not work properly. Is there any reason why no corresponding
cats file is produced?
IMHO, modules should not be required to explicitly write a cats file.
GRASS 4.x is ancient history, and raster maps are no longer inherently
category-based.
I think this is true for all modules creating regular raster maps
because a cats file is automatically generated by the library when a
new raster map is closed. r.external does not use Rast_close() and
creates all the support files itself, but not the cats file.
Raster modules should only write a cats file if they actually have
something meaningful to put in it.
Either Rast_read_cats() should silently return an empty category
structure if no cats file is present, or Rast_close() should
automatically generate an empty cats file if no cats file was
explicitly written.
This is what Rast_close() does, but r.external does not call
Rast_close(). Maybe it should?
Markus M
I'm inclined towards the former, unless there might be cases where the
distinction between "no category list" and "empty category list" would
matter.
--
Glynn Clements <glynn@gclements.plus.com>
On Wed, Jun 29, 2011 at 11:21 AM, Markus Metz
<markus.metz.giswork@googlemail.com> wrote:
On Wed, Jun 29, 2011 at 12:23 AM, Glynn Clements
<glynn@gclements.plus.com> wrote:
Markus Metz wrote:
When linking external raster maps with r.external, I have to manually
create a corresponding cats file, otherwise a number of modules, e.g.
d.rast do not work properly. Is there any reason why no corresponding
cats file is produced?
IMHO, modules should not be required to explicitly write a cats file.
GRASS 4.x is ancient history, and raster maps are no longer inherently
category-based.
I think this is true for all modules creating regular raster maps
because a cats file is automatically generated by the library when a
new raster map is closed. r.external does not use Rast_close() and
creates all the support files itself, but not the cats file.
Raster modules should only write a cats file if they actually have
something meaningful to put in it.
Either Rast_read_cats() should silently return an empty category
structure if no cats file is present, or Rast_close() should
automatically generate an empty cats file if no cats file was
explicitly written.
This is what Rast_close() does, but r.external does not call
Rast_close(). Maybe it should?
r.external can not use Rast_close() because it never opens a raster
map with Rast_open_new(), thus the module has to do itself what
Rast_close() does for all other modules that create a new raster map?
Markus M
I'm inclined towards the former, unless there might be cases where the
distinction between "no category list" and "empty category list" would
matter.
--
Glynn Clements <glynn@gclements.plus.com>
Markus Metz wrote:
> IMHO, modules should not be required to explicitly write a cats file.
> GRASS 4.x is ancient history, and raster maps are no longer inherently
> category-based.
I think this is true for all modules creating regular raster maps
because a cats file is automatically generated by the library when a
new raster map is closed. r.external does not use Rast_close() and
creates all the support files itself, but not the cats file.
Good point. In which case, I consider that your patch is the correct
solution.
--
Glynn Clements <glynn@gclements.plus.com>
On Fri, Jul 1, 2011 at 1:51 AM, Glynn Clements <glynn@gclements.plus.com> wrote:
Markus Metz wrote:
> IMHO, modules should not be required to explicitly write a cats file.
> GRASS 4.x is ancient history, and raster maps are no longer inherently
> category-based.
I think this is true for all modules creating regular raster maps
because a cats file is automatically generated by the library when a
new raster map is closed. r.external does not use Rast_close() and
creates all the support files itself, but not the cats file.
Good point. In which case, I consider that your patch is the correct
solution.
OK. Fixed in all branches (tested for over a year by now ;-))
Markus M