[GRASS-SVN] r62227 - in grass/branches/releasebranch_7_0: . vector/v.to.rast

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Oct 9 07:54:32 PDT 2014


Author: neteler
Date: 2014-10-09 07:54:32 -0700 (Thu, 09 Oct 2014)
New Revision: 62227

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/vector/v.to.rast/main.c
   grass/branches/releasebranch_7_0/vector/v.to.rast/raster.c
   grass/branches/releasebranch_7_0/vector/v.to.rast/vect2rast.c
Log:
v.to.rast: change rows option to memory option (trunk, r61909)


Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Deleted: svn:mergeinfo
   - /grass/trunk:60289,60696,61269,61380,61420,61422,61480,61500,61764,61793,61808,61829,61831,61840,61851-61854,61858,61888,61891,61905,61907,61913-61914,61916,61918,61920-61921,61938,61967-61968,61975,61980,61986,61993,62005,62035,62046,62060-62061,62095,62099,62114,62122,62128,62130-62131,62148,62170,62174,62200,62210

Modified: grass/branches/releasebranch_7_0/vector/v.to.rast/main.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.to.rast/main.c	2014-10-09 14:54:21 UTC (rev 62226)
+++ grass/branches/releasebranch_7_0/vector/v.to.rast/main.c	2014-10-09 14:54:32 UTC (rev 62227)
@@ -30,11 +30,11 @@
 int main(int argc, char *argv[])
 {
     struct GModule *module;
-    struct Option *input, *output, *rows, *col, *use_opt, *val_opt,
+    struct Option *input, *output, *memory, *col, *use_opt, *val_opt,
 		  *field_opt, *type_opt, *where_opt, *cats_opt,
 	          *rgbcol_opt, *label_opt;
     struct Flag *dense_flag;
-    int nrows, use, value_type, type;
+    int cache_mb, use, value_type, type;
     double value;
     char *desc;
 
@@ -107,13 +107,14 @@
     val_opt->answer = "1";
     val_opt->description = _("Raster value (for use=val)");
     
-    rows = G_define_option();
-    rows->key = "rows";
-    rows->type = TYPE_INTEGER;
-    rows->required = NO;
-    rows->multiple = NO;
-    rows->answer = "4096";
-    rows->description = _("Number of rows to hold in memory");
+    memory = G_define_option();
+    memory->key = "memory";
+    memory->type = TYPE_INTEGER;
+    memory->required = NO;
+    memory->multiple = NO;
+    memory->answer = "300";
+    memory->label = _("Cache size (MiB)");
+    memory->description = _("Cache size for raster rows");
 
     dense_flag = G_define_flag();
     dense_flag->key = 'd';
@@ -125,8 +126,14 @@
 	exit(EXIT_FAILURE);
 
     type = Vect_option_to_types(type_opt);
-    nrows = atoi(rows->answer);
 
+    cache_mb = atoi(memory->answer);
+    if (cache_mb < 1) {
+	G_warning(_("Cache size must be at least 1 MiB, changing %d to 1"),
+	          cache_mb);
+	cache_mb = 1;
+    }
+
     switch (use_opt->answer[0]) {
     case 'a':
 	use = USE_ATTR;
@@ -160,7 +167,7 @@
     value_type = (strchr(val_opt->answer, '.')) ? USE_DCELL : USE_CELL;
 
     if (vect_to_rast(input->answer, output->answer, field_opt->answer,
-		     col->answer, nrows, use, value, value_type,
+		     col->answer, cache_mb, use, value, value_type,
 		     rgbcol_opt->answer, label_opt->answer, type,
 		     where_opt->answer, cats_opt->answer, dense_flag->answer)) {
 	exit(EXIT_FAILURE);

Modified: grass/branches/releasebranch_7_0/vector/v.to.rast/raster.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.to.rast/raster.c	2014-10-09 14:54:21 UTC (rev 62226)
+++ grass/branches/releasebranch_7_0/vector/v.to.rast/raster.c	2014-10-09 14:54:32 UTC (rev 62227)
@@ -33,9 +33,10 @@
 static int (*dot) (int, int);
 
 
-int begin_rasterization(int nrows, int f, int do_dense)
+int begin_rasterization(int cache_mb, int f, int do_dense)
 {
-    int i, size;
+    int i, size, nrows;
+    double row_mb;
     int pages;
 
     dense = (do_dense != 0);
@@ -45,13 +46,30 @@
 
     format = f;
 
+    G_get_set_window(&region);
+    G_get_set_window(&page);
+
+    switch (format) {
+    case USE_CELL:
+	row_mb = (double) region.cols * (sizeof(char) + sizeof(CELL)) /
+		 (1 << 20);
+	break;
+
+    case USE_DCELL:
+	row_mb = (double) region.cols * (sizeof(char) + sizeof(DCELL)) /
+	         (1 << 20);
+	dot = dcell_dot;
+	break;
+    }
+
+    nrows = cache_mb / row_mb;
+    if (nrows < 1)
+	nrows = 1;
+
     max_rows = nrows;
     if (max_rows <= 0)
 	max_rows = 512;
 
-    G_get_set_window(&region);
-    G_get_set_window(&page);
-
     pages = (region.rows + max_rows - 1) / max_rows;
 
     if (max_rows > region.rows)

Modified: grass/branches/releasebranch_7_0/vector/v.to.rast/vect2rast.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.to.rast/vect2rast.c	2014-10-09 14:54:21 UTC (rev 62226)
+++ grass/branches/releasebranch_7_0/vector/v.to.rast/vect2rast.c	2014-10-09 14:54:32 UTC (rev 62227)
@@ -8,7 +8,7 @@
 
 
 int vect_to_rast(const char *vector_map, const char *raster_map, const char *field_name,
-		 const char *column, int nrows, int use, double value,
+		 const char *column, int cache_mb, int use, double value,
 		 int value_type, const char *rgbcolumn, const char *labelcolumn,
 		 int ftype, char *where, char *cats, int dense)
 {
@@ -143,7 +143,7 @@
     }
 
     nlines = 1;
-    npasses = begin_rasterization(nrows, format, dense);
+    npasses = begin_rasterization(cache_mb, format, dense);
     pass = 0;
 
     nareas_all = Vect_get_num_areas(&Map);
@@ -224,7 +224,8 @@
 		  column);
 
     if (nareas_all > 0)
-	G_message(_("Converted areas: %d of %d"), nareas, nareas_all);
+	G_message(_("Converted areas: %d of %d"), nareas,
+	          nareas_all - Vect_get_num_primitives(&Map, GV_CENTROID));
     if (nplines_all > 0)
 	G_message(_("Converted points/lines: %d of %d"), nlines, nplines_all);
 



More information about the grass-commit mailing list