[GRASS-SVN] r74203 - grass/trunk/vector/v.to.rast

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 9 10:38:22 PST 2019


Author: mmetz
Date: 2019-03-09 10:38:22 -0800 (Sat, 09 Mar 2019)
New Revision: 74203

Modified:
   grass/trunk/vector/v.to.rast/support.c
Log:
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)

Modified: grass/trunk/vector/v.to.rast/support.c
===================================================================
--- grass/trunk/vector/v.to.rast/support.c	2019-03-09 16:36:51 UTC (rev 74202)
+++ grass/trunk/vector/v.to.rast/support.c	2019-03-09 18:38:22 UTC (rev 74203)
@@ -226,7 +226,10 @@
     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 @@
 		}			/* for each value in database */
 	    }
 	    else  {
+		Rast_set_cats_title("Rasterized vector map from categories", &rast_cats);
+
+		/* 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 @@
 		    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 @@
 	{
 	    DCELL fmin, fmax;
 	    RASTER_MAP_TYPE map_type;
-	    int i;
 	    char msg[64];
 
 	    map_type = Rast_map_type(rast_name, G_mapset());



More information about the grass-commit mailing list