[GRASS-SVN] r61909 - grass/trunk/vector/v.to.rast
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Sep 13 12:07:26 PDT 2014
Author: mmetz
Date: 2014-09-13 12:07:26 -0700 (Sat, 13 Sep 2014)
New Revision: 61909
Modified:
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: change rows option to memory option
Modified: grass/trunk/vector/v.to.rast/main.c
===================================================================
--- grass/trunk/vector/v.to.rast/main.c 2014-09-13 19:05:16 UTC (rev 61908)
+++ grass/trunk/vector/v.to.rast/main.c 2014-09-13 19:07:26 UTC (rev 61909)
@@ -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, canging %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/trunk/vector/v.to.rast/raster.c
===================================================================
--- grass/trunk/vector/v.to.rast/raster.c 2014-09-13 19:05:16 UTC (rev 61908)
+++ grass/trunk/vector/v.to.rast/raster.c 2014-09-13 19:07:26 UTC (rev 61909)
@@ -34,9 +34,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);
@@ -46,13 +47,30 @@
format = f;
+ G_get_set_window(®ion);
+ 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(®ion);
- G_get_set_window(&page);
-
pages = (region.rows + max_rows - 1) / max_rows;
if (max_rows > region.rows)
@@ -61,8 +79,6 @@
size = max_rows * region.cols;
switch (format) {
case USE_CELL:
- G_important_message(_("Using at least %.1f GB of RAM (adjust with 'rows' parameter)"),
- (double)region.rows * nrows * sizeof(CELL *) /1024 /1024 /1024);
raster.cell =
(CELL **) G_calloc(max_rows * sizeof(char), sizeof(CELL *));
raster.cell[0] = (CELL *) G_calloc(size * sizeof(char), sizeof(CELL));
@@ -72,8 +88,6 @@
break;
case USE_DCELL:
- G_important_message(_("Using at least %.1f GB of RAM (adjust with 'rows' parameter)"),
- (double)region.rows * nrows * sizeof(DCELL *) /1024 /1024 /1024);
raster.dcell =
(DCELL **) G_calloc(max_rows * sizeof(char), sizeof(DCELL *));
raster.dcell[0] =
Modified: grass/trunk/vector/v.to.rast/vect2rast.c
===================================================================
--- grass/trunk/vector/v.to.rast/vect2rast.c 2014-09-13 19:05:16 UTC (rev 61908)
+++ grass/trunk/vector/v.to.rast/vect2rast.c 2014-09-13 19:07:26 UTC (rev 61909)
@@ -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)
{
@@ -144,7 +144,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);
@@ -225,7 +225,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