浏览代码

v.to.rast: do not create raster categories if vector categories are used as cell values because 1. Rast_set_cat() is terribly slow for many categories, 2. this information is redundant (1: 1 etc is not informative)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@74203 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 6 年之前
父节点
当前提交
8a1cd940eb
共有 1 个文件被更改,包括 16 次插入7 次删除
  1. 16 7
      vector/v.to.rast/support.c

+ 16 - 7
vector/v.to.rast/support.c

@@ -226,7 +226,10 @@ static int cmp_labels_i(const void *a, const void *b)
     struct My_labels_rule *al = (struct My_labels_rule *) a;
     struct My_labels_rule *bl = (struct My_labels_rule *) b;
 
-    return (al->i - bl->i);
+    if (al->i < bl->i)
+	return -1;
+
+    return (al->i > bl->i);
 }
 
 /* add labels to raster cells */
@@ -587,13 +590,20 @@ int update_labels(const char *rast_name, const char *vector_map, int field,
 		}			/* for each value in database */
 	    }
 	    else  {
-		fd = Rast_open_old(rast_name, G_mapset());
+		Rast_set_cats_title("Rasterized vector map from categories", &rast_cats);
 
-		rowbuf = Rast_allocate_buf(map_type);
+		/* Rast_set_cat() is terribly slow for many categories,
+		 * and the added labels are not really informative:
+		 * 1:Category 1
+		 * 2:Category 2
+		 * ...
+		 * 100000:Category 100000
+		 * -> skip */
 
+#if 0
+		fd = Rast_open_old(rast_name, G_mapset());
+		rowbuf = Rast_allocate_buf(map_type);
 		Rast_init_cell_stats(&stats);
-		Rast_set_cats_title("Rasterized vector map from categories", &rast_cats);
-
 		rows = Rast_window_rows();
 
 		for (row = 0; row < rows; row++) {
@@ -609,9 +619,9 @@ int update_labels(const char *rast_name, const char *vector_map, int field,
 		    sprintf(msg, "Category %d", n);
 		    Rast_set_cat(&n, &n, msg, &rast_cats, map_type);
 		}
-
 		Rast_close(fd);
 		G_free(rowbuf);
+#endif
 	    }
 	}
 	break;
@@ -619,7 +629,6 @@ int update_labels(const char *rast_name, const char *vector_map, int field,
 	{
 	    DCELL fmin, fmax;
 	    RASTER_MAP_TYPE map_type;
-	    int i;
 	    char msg[64];
 
 	    map_type = Rast_map_type(rast_name, G_mapset());