瀏覽代碼

r.cross: code clean-up, explain NULL handling

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@72285 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 7 年之前
父節點
當前提交
f7f3013af6
共有 3 個文件被更改,包括 32 次插入33 次删除
  1. 10 4
      raster/r.cross/cats.c
  2. 3 10
      raster/r.cross/main.c
  3. 19 19
      raster/r.cross/r.cross.html

+ 10 - 4
raster/r.cross/cats.c

@@ -49,13 +49,19 @@ int set_cat(CELL result, CELL * cat, struct Categories *pcats)
     return 0;
     return 0;
 }
 }
 
 
-static char *get_label(CELL cat, struct Categories *labels)
+static char *get_label(CELL cat, struct Categories *lbls)
 {
 {
     char *lbl;
     char *lbl;
     static char temp[256];
     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;
     return lbl;
 }
 }

+ 3 - 10
raster/r.cross/main.c

@@ -44,8 +44,7 @@ int main(int argc, char *argv[])
     const char *output;
     const char *output;
     const char *mapset;
     const char *mapset;
     int non_zero;
     int non_zero;
-    struct Range range;
-    CELL ncats, max_cats;
+    CELL ncats;
     int primary;
     int primary;
     struct Categories pcats;
     struct Categories pcats;
     struct Colors pcolr;
     struct Colors pcolr;
@@ -87,7 +86,7 @@ int main(int argc, char *argv[])
 
 
     flag.z = G_define_flag();
     flag.z = G_define_flag();
     flag.z->key = 'z';
     flag.z->key = 'z';
-    flag.z->description = _("Non-zero data only");
+    flag.z->description = _("Non-NULL data only");
 
 
     if (G_parser(argc, argv))
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 	exit(EXIT_FAILURE);
@@ -106,13 +105,6 @@ int main(int argc, char *argv[])
 	    G_fatal_error(_("Raster map <%s> not found"), name);
 	    G_fatal_error(_("Raster map <%s> not found"), name);
 	names[nfiles] = name;
 	names[nfiles] = name;
 	fd[nfiles] = Rast_open_old(name, mapset);
 	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)
     if (nfiles <= 1)
@@ -130,6 +122,7 @@ int main(int argc, char *argv[])
     Rast_init_cats(buf, &pcats);
     Rast_init_cats(buf, &pcats);
 
 
     /* first step is cross product, but un-ordered */
     /* first step is cross product, but un-ordered */
+    primary = 0;
     result = cross(fd, non_zero, primary, outfd);
     result = cross(fd, non_zero, primary, outfd);
 
 
     /* print message STEP mesage */
     /* print message STEP mesage */

+ 19 - 19
raster/r.cross/r.cross.html

@@ -14,17 +14,17 @@ the names of between 2-10 raster map layers be used as <em>input</em>,
 and the name of a raster map layer to hold program <em>output</em>.
 and the name of a raster map layer to hold program <em>output</em>.
 
 
 <p>
 <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. 
 would cause 3 categories to be generated instead of 5. 
 
 
 <p>
 <p>
 If the <b>-z</b> flag is not specified, then map layer combinations 
 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>
 <p>
 Category values in the new <em>output</em> map layer will be the
 Category values in the new <em>output</em> map layer will be the
@@ -39,8 +39,8 @@ the following combinations occur:
 <div class="code"><pre>
 <div class="code"><pre>
           map1   map2
           map1   map2
           ___________
           ___________
-           0      1
-           0      2
+          NULL    1
+          NULL    2
            1      1
            1      1
            1      2
            1      2
            2      4
            2      4
@@ -52,11 +52,11 @@ the following combinations occur:
 <div class="code"><pre>
 <div class="code"><pre>
           map1   map2   output
           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>
 </pre></div>
 
 
 Note: The actual category value assigned to a particular combination 
 Note: The actual category value assigned to a particular combination 
@@ -77,11 +77,11 @@ In the above example, the category labels would be:
           category   category
           category   category
           value      label
           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>
 </pre></div>
 
 
 A random color table is also generated for the <em>output</em> map layer. 
 A random color table is also generated for the <em>output</em> map layer.