[GRASS-SVN] r72285 - grass/trunk/raster/r.cross
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 26 09:40:49 PST 2018
Author: mmetz
Date: 2018-02-26 09:40:49 -0800 (Mon, 26 Feb 2018)
New Revision: 72285
Modified:
grass/trunk/raster/r.cross/cats.c
grass/trunk/raster/r.cross/main.c
grass/trunk/raster/r.cross/r.cross.html
Log:
r.cross: code clean-up, explain NULL handling
Modified: grass/trunk/raster/r.cross/cats.c
===================================================================
--- grass/trunk/raster/r.cross/cats.c 2018-02-26 16:35:06 UTC (rev 72284)
+++ grass/trunk/raster/r.cross/cats.c 2018-02-26 17:40:49 UTC (rev 72285)
@@ -49,13 +49,19 @@
return 0;
}
-static char *get_label(CELL cat, struct Categories *labels)
+static char *get_label(CELL cat, struct Categories *lbls)
{
char *lbl;
static char temp[256];
- lbl = Rast_get_c_cat(&cat, labels);
- if (*lbl == 0)
- sprintf(lbl = temp, "category %ld", (long)cat);
+ if (Rast_is_c_null_value(&cat)) {
+ sprintf(lbl = temp, "NULL");
+ }
+ else {
+ lbl = Rast_get_c_cat(&cat, lbls);
+ if (*lbl == 0)
+ sprintf(lbl = temp, "category %d", cat);
+ }
+
return lbl;
}
Modified: grass/trunk/raster/r.cross/main.c
===================================================================
--- grass/trunk/raster/r.cross/main.c 2018-02-26 16:35:06 UTC (rev 72284)
+++ grass/trunk/raster/r.cross/main.c 2018-02-26 17:40:49 UTC (rev 72285)
@@ -44,8 +44,7 @@
const char *output;
const char *mapset;
int non_zero;
- struct Range range;
- CELL ncats, max_cats;
+ CELL ncats;
int primary;
struct Categories pcats;
struct Colors pcolr;
@@ -87,7 +86,7 @@
flag.z = G_define_flag();
flag.z->key = 'z';
- flag.z->description = _("Non-zero data only");
+ flag.z->description = _("Non-NULL data only");
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
@@ -106,13 +105,6 @@
G_fatal_error(_("Raster map <%s> not found"), name);
names[nfiles] = name;
fd[nfiles] = Rast_open_old(name, mapset);
- Rast_read_range(name, mapset, &range);
- ncats = range.max - range.min;
-
- if (nfiles == 0 || ncats > max_cats) {
- primary = nfiles;
- max_cats = ncats;
- }
}
if (nfiles <= 1)
@@ -130,6 +122,7 @@
Rast_init_cats(buf, &pcats);
/* first step is cross product, but un-ordered */
+ primary = 0;
result = cross(fd, non_zero, primary, outfd);
/* print message STEP mesage */
Modified: grass/trunk/raster/r.cross/r.cross.html
===================================================================
--- grass/trunk/raster/r.cross/r.cross.html 2018-02-26 16:35:06 UTC (rev 72284)
+++ grass/trunk/raster/r.cross/r.cross.html 2018-02-26 17:40:49 UTC (rev 72285)
@@ -14,17 +14,17 @@
and the name of a raster map layer to hold program <em>output</em>.
<p>
-With the <b>-z</b> flag zero data values are not crossed.
-This means that if a zero category value occurs in any input data layer,
-the combination is assigned to category zero in the resulting map layer,
-even if other data layers contain non-zero data.
-In the example given above, use of the <b>-z</b> option
+With the <b>-z</b> flag NULL values are not crossed.
+This means that if a NULL value occurs in any input data layer,
+this combination is ignored,
+even if other data layers contain non-NULL data.
+In the example given below, use of the <b>-z</b> option
would cause 3 categories to be generated instead of 5.
<p>
If the <b>-z</b> flag is not specified, then map layer combinations
-in which not all category values are zero will be assigned
-a unique category value in the resulting map layer.
+in which some values are NULL will be assigned
+a unique category value in the resulting output map.
<p>
Category values in the new <em>output</em> map layer will be the
@@ -39,8 +39,8 @@
<div class="code"><pre>
map1 map2
___________
- 0 1
- 0 2
+ NULL 1
+ NULL 2
1 1
1 2
2 4
@@ -52,11 +52,11 @@
<div class="code"><pre>
map1 map2 output
____________________
- 0 1 1
- 0 2 2
- 1 1 3
- 1 2 4
- 2 4 5
+ NULL 1 0
+ NULL 2 1
+ 1 1 2
+ 1 2 3
+ 2 4 4
</pre></div>
Note: The actual category value assigned to a particular combination
@@ -77,11 +77,11 @@
category category
value label
______________________________
- 1 layer1(0) layer2(1)
- 2 layer1(0) layer2(2)
- 3 layer1(1) layer2(1)
- 4 layer1(1) layer2(2)
- 5 layer1(2) layer2(4)
+ 0 layer1(0) layer2(1)
+ 1 layer1(0) layer2(2)
+ 2 layer1(1) layer2(1)
+ 3 layer1(1) layer2(2)
+ 4 layer1(2) layer2(4)
</pre></div>
A random color table is also generated for the <em>output</em> map layer.
More information about the grass-commit
mailing list