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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Oct 28 00:40:49 PDT 2014


Author: mmetz
Date: 2014-10-28 00:40:49 -0700 (Tue, 28 Oct 2014)
New Revision: 62428

Modified:
   grass/trunk/vector/v.to.rast/do_areas.c
   grass/trunk/vector/v.to.rast/do_lines.c
   grass/trunk/vector/v.to.rast/local.h
   grass/trunk/vector/v.to.rast/main.c
   grass/trunk/vector/v.to.rast/raster.c
   grass/trunk/vector/v.to.rast/vect2rast.c
Log:
v.to.rast: replace custom cell type with raster cell type; use size_t

Modified: grass/trunk/vector/v.to.rast/do_areas.c
===================================================================
--- grass/trunk/vector/v.to.rast/do_areas.c	2014-10-28 03:59:28 UTC (rev 62427)
+++ grass/trunk/vector/v.to.rast/do_areas.c	2014-10-28 07:40:49 UTC (rev 62428)
@@ -68,7 +68,7 @@
 		set_cat(cat);
 	    }
 	    else {
-		if (value_type == USE_CELL)
+		if (value_type == CELL_TYPE)
 		    set_cat((int)value);
 		else
 		    set_dcat(value);

Modified: grass/trunk/vector/v.to.rast/do_lines.c
===================================================================
--- grass/trunk/vector/v.to.rast/do_lines.c	2014-10-28 03:59:28 UTC (rev 62427)
+++ grass/trunk/vector/v.to.rast/do_lines.c	2014-10-28 07:40:49 UTC (rev 62428)
@@ -77,7 +77,7 @@
 	    set_cat(cat);
 	}
 	else if (use == USE_VAL) {
-	    if (value_type == USE_CELL)
+	    if (value_type == CELL_TYPE)
 		set_cat((int)value);
 	    else
 		set_dcat(value);

Modified: grass/trunk/vector/v.to.rast/local.h
===================================================================
--- grass/trunk/vector/v.to.rast/local.h	2014-10-28 03:59:28 UTC (rev 62427)
+++ grass/trunk/vector/v.to.rast/local.h	2014-10-28 07:40:49 UTC (rev 62428)
@@ -14,10 +14,6 @@
 #define SETNULL(x)  Rast_set_c_null_value (x, 1)
 #define SETDNULL(x) Rast_set_d_null_value (x, 1)
 
-/* cell type */
-#define USE_CELL  1
-#define USE_DCELL 2
-
 /* value type */
 #define USE_ATTR  1
 #define USE_CAT   2

Modified: grass/trunk/vector/v.to.rast/main.c
===================================================================
--- grass/trunk/vector/v.to.rast/main.c	2014-10-28 03:59:28 UTC (rev 62427)
+++ grass/trunk/vector/v.to.rast/main.c	2014-10-28 07:40:49 UTC (rev 62428)
@@ -164,7 +164,7 @@
     }
 
     value = atof(val_opt->answer);
-    value_type = (strchr(val_opt->answer, '.')) ? USE_DCELL : USE_CELL;
+    value_type = (strchr(val_opt->answer, '.')) ? DCELL_TYPE : CELL_TYPE;
 
     if (vect_to_rast(input->answer, output->answer, field_opt->answer,
 		     col->answer, cache_mb, use, value, value_type,

Modified: grass/trunk/vector/v.to.rast/raster.c
===================================================================
--- grass/trunk/vector/v.to.rast/raster.c	2014-10-28 03:59:28 UTC (rev 62427)
+++ grass/trunk/vector/v.to.rast/raster.c	2014-10-28 07:40:49 UTC (rev 62428)
@@ -1,7 +1,6 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/vector.h>
-#include <grass/glocale.h>
 #include "local.h"
 
 
@@ -36,9 +35,10 @@
 
 int begin_rasterization(int cache_mb, int f, int do_dense)
 {
-    int i, size, nrows;
+    int i;
     double row_mb;
     int pages;
+    size_t size;
 
     dense = (do_dense != 0);
 
@@ -50,35 +50,23 @@
     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;
+    row_mb = (double) region.cols * (sizeof(char) + Rast_cell_size(f)) /
+	     (1 << 20);
 
-    case USE_DCELL:
-	row_mb = (double) region.cols * (sizeof(char) + sizeof(DCELL)) /
-	         (1 << 20);
-	dot = dcell_dot;
-	break;
-    }
+    max_rows = cache_mb / row_mb;
+    if (max_rows < 1)
+	max_rows = 4;
 
-    nrows = cache_mb / row_mb;
-    if (nrows < 1)
-	nrows = 1;
-
-    max_rows = nrows;
-    if (max_rows <= 0)
-	max_rows = 512;
-
     pages = (region.rows + max_rows - 1) / max_rows;
 
     if (max_rows > region.rows)
 	max_rows = region.rows;
 
-    size = max_rows * region.cols;
+    G_debug(0, "%d of %d rows are cached", max_rows, region.rows);
+
+    size = (size_t) max_rows * region.cols;
     switch (format) {
-    case USE_CELL:
+    case CELL_TYPE:
 	raster.cell =
 	    (CELL **) G_calloc(max_rows * sizeof(char), sizeof(CELL *));
 	raster.cell[0] = (CELL *) G_calloc(size * sizeof(char), sizeof(CELL));
@@ -87,7 +75,7 @@
 	dot = cell_dot;
 	break;
 
-    case USE_DCELL:
+    case DCELL_TYPE:
 	raster.dcell =
 	    (DCELL **) G_calloc(max_rows * sizeof(char), sizeof(DCELL *));
 	raster.dcell[0] =
@@ -127,12 +115,12 @@
 
     /* zero the raster */
     switch (format) {
-    case USE_CELL:
+    case CELL_TYPE:
 	for (i = 0; i < nrows; i++)
 	    for (j = 0; j < ncols; j++)
 		raster.cell[i][j] = 0;
 	break;
-    case USE_DCELL:
+    case DCELL_TYPE:
 	for (i = 0; i < nrows; i++)
 	    for (j = 0; j < ncols; j++)
 		raster.dcell[i][j] = 0;
@@ -165,14 +153,14 @@
     for (i = 0; i < page.rows; i++, at_row++) {
 	G_percent(i, page.rows, 2);
 	switch (format) {
-	case USE_CELL:
+	case CELL_TYPE:
 	    cell = raster.cell[i];
 
 	    /* insert the NULL values */
 	    Rast_insert_c_null_values(cell, null_flags[i], page.cols);
 	    Rast_put_c_row(fd, cell);
 	    break;
-	case USE_DCELL:
+	case DCELL_TYPE:
 	    dcell = raster.dcell[i];
 
 	    /* insert the NULL values */

Modified: grass/trunk/vector/v.to.rast/vect2rast.c
===================================================================
--- grass/trunk/vector/v.to.rast/vect2rast.c	2014-10-28 03:59:28 UTC (rev 62427)
+++ grass/trunk/vector/v.to.rast/vect2rast.c	2014-10-28 07:40:49 UTC (rev 62428)
@@ -95,10 +95,10 @@
 	
 	switch (ctype) {
 	case DB_C_TYPE_INT:
-	    format = USE_CELL;
+	    format = CELL_TYPE;
 	    break;
 	case DB_C_TYPE_DOUBLE:
-	    format = USE_DCELL;
+	    format = DCELL_TYPE;
 	    break;
 	default:
 	    G_fatal_error(_("Unable to use column <%s>"), column);
@@ -106,33 +106,23 @@
 	}
 	break;
     case USE_CAT:
-	format = USE_CELL;
+	format = CELL_TYPE;
 	break;
     case USE_VAL:
 	format = value_type;
 	break;
     case USE_Z:
-	format = USE_DCELL;
+	format = DCELL_TYPE;
 	is_fp = 1;
 	break;
     case USE_D:
-	format = USE_DCELL;
+	format = DCELL_TYPE;
 	break;
     default:
 	G_fatal_error(_("Unknown use type: %d"), use);
     }
 
-    switch (format) {
-    case USE_CELL:
-	fd = Rast_open_c_new(raster_map);
-	break;
-    case USE_DCELL:
-	fd = Rast_open_new(raster_map, DCELL_TYPE);
-	break;
-    default:
-	G_fatal_error(_("Unknown raster map type"));
-	break;
-    }
+    fd = Rast_open_new(raster_map, format);
 
     Points = Vect_new_line_struct();
 



More information about the grass-commit mailing list