|
@@ -1,20 +1,20 @@
|
|
|
|
|
|
/****************************************************************************
|
|
/****************************************************************************
|
|
-*
|
|
|
|
-* MODULE: r.to.rast3elev
|
|
|
|
-*
|
|
|
|
-* AUTHOR(S): Original author
|
|
|
|
-* Soeren Gebbert soerengebbert@gmx.de
|
|
|
|
-* 07 08 2006 Berlin
|
|
|
|
-* PURPOSE: Creates a 3D volume map based on 2D elevation and value raster maps
|
|
|
|
-*
|
|
|
|
-* COPYRIGHT: (C) 2006 by the GRASS Development Team
|
|
|
|
-*
|
|
|
|
-* This program is free software under the GNU General Public
|
|
|
|
-* License (>=v2). Read the file COPYING that comes with GRASS
|
|
|
|
-* for details.
|
|
|
|
-*
|
|
|
|
-*****************************************************************************/
|
|
|
|
|
|
+ *
|
|
|
|
+ * MODULE: r.to.rast3elev
|
|
|
|
+ *
|
|
|
|
+ * AUTHOR(S): Original author
|
|
|
|
+ * Soeren Gebbert soerengebbert@gmx.de
|
|
|
|
+ * 07 08 2006 Berlin
|
|
|
|
+ * PURPOSE: Creates a 3D volume map based on 2D elevation and value raster maps
|
|
|
|
+ *
|
|
|
|
+ * COPYRIGHT: (C) 2006 by the GRASS Development Team
|
|
|
|
+ *
|
|
|
|
+ * This program is free software under the GNU General Public
|
|
|
|
+ * License (>=v2). Read the file COPYING that comes with GRASS
|
|
|
|
+ * for details.
|
|
|
|
+ *
|
|
|
|
+ *****************************************************************************/
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <string.h>
|
|
@@ -25,58 +25,58 @@
|
|
#include <grass/config.h>
|
|
#include <grass/config.h>
|
|
|
|
|
|
/*- params and global variables -----------------------------------------*/
|
|
/*- params and global variables -----------------------------------------*/
|
|
-typedef struct
|
|
|
|
-{
|
|
|
|
|
|
+typedef struct {
|
|
struct Option *input, *elev, *output, *upper, *lower, *tilesize;
|
|
struct Option *input, *elev, *output, *upper, *lower, *tilesize;
|
|
struct Flag *fillup, *filllow, *mask;
|
|
struct Flag *fillup, *filllow, *mask;
|
|
} paramType;
|
|
} paramType;
|
|
|
|
|
|
/*Data to be used */
|
|
/*Data to be used */
|
|
-typedef struct
|
|
|
|
-{
|
|
|
|
- int mapnum; /*The umber of input maps */
|
|
|
|
- int count; /*3d raster map access counter */
|
|
|
|
- void *map; /*The 3d voxel output map */
|
|
|
|
- int input; /*The current raster value map pointer */
|
|
|
|
- int elev; /*The current raster elevation map pointer */
|
|
|
|
|
|
+typedef struct {
|
|
|
|
+ int mapnum; /*The umber of input maps */
|
|
|
|
+ int count; /*3d raster map access counter */
|
|
|
|
+ void *map; /*The 3d voxel output map */
|
|
|
|
+ int input; /*The current raster value map pointer */
|
|
|
|
+ int elev; /*The current raster elevation map pointer */
|
|
int inputmaptype;
|
|
int inputmaptype;
|
|
int elevmaptype;
|
|
int elevmaptype;
|
|
- double upper; /*The upper value */
|
|
|
|
- double lower; /*The lower value */
|
|
|
|
- int useUpperVal; /*0 = use upper value, 1 = use map value to fill upper cells */
|
|
|
|
- int useLowerVal; /*0 = use lower value, 1 = use map value to fill lower cells */
|
|
|
|
|
|
+ double upper; /*The upper value */
|
|
|
|
+ double lower; /*The lower value */
|
|
|
|
+ int useUpperVal; /*0 = use upper value, 1 = use map value to fill upper cells */
|
|
|
|
+ int useLowerVal; /*0 = use lower value, 1 = use map value to fill lower cells */
|
|
} Database;
|
|
} Database;
|
|
|
|
|
|
-paramType param; /*params */
|
|
|
|
|
|
+paramType param; /*params */
|
|
|
|
|
|
/*- prototypes --------------------------------------------------------------*/
|
|
/*- prototypes --------------------------------------------------------------*/
|
|
-void fatal_error(Database db, char *errorMsg); /*Simple Error message */
|
|
|
|
-void set_params(); /*Fill the paramType structure */
|
|
|
|
-void elev_raster_to_g3d(Database db, G3D_Region region); /*Write the raster */
|
|
|
|
-int open_input_raster_map(const char *name); /*opens the outputmap */
|
|
|
|
-void close_input_raster_map(int fd); /*close the map */
|
|
|
|
|
|
+void fatal_error(Database db, char *errorMsg); /*Simple Error message */
|
|
|
|
+void set_params(); /*Fill the paramType structure */
|
|
|
|
+void elev_raster_to_g3d(Database db, G3D_Region region); /*Write the raster */
|
|
|
|
+int open_input_raster_map(const char *name); /*opens the outputmap */
|
|
|
|
+void close_input_raster_map(int fd); /*close the map */
|
|
double get_raster_value_as_double(int maptype, void *ptr, double nullval);
|
|
double get_raster_value_as_double(int maptype, void *ptr, double nullval);
|
|
-void check_input_maps(Database * db); /*Check input maps */
|
|
|
|
|
|
+void check_input_maps(Database * db); /*Check input maps */
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
/* Get the value of the current raster pointer as double ******************* */
|
|
/* Get the value of the current raster pointer as double ******************* */
|
|
|
|
+
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
double get_raster_value_as_double(int MapType, void *ptr, double nullval)
|
|
double get_raster_value_as_double(int MapType, void *ptr, double nullval)
|
|
{
|
|
{
|
|
if (Rast_is_null_value(ptr, MapType))
|
|
if (Rast_is_null_value(ptr, MapType))
|
|
- return nullval;
|
|
|
|
|
|
+ return nullval;
|
|
|
|
|
|
switch (MapType) {
|
|
switch (MapType) {
|
|
- case CELL_TYPE: return *(CELL *) ptr;
|
|
|
|
- case FCELL_TYPE: return *(FCELL *) ptr;
|
|
|
|
- case DCELL_TYPE: return *(DCELL *) ptr;
|
|
|
|
- default: return nullval;
|
|
|
|
|
|
+ case CELL_TYPE: return *(CELL *) ptr;
|
|
|
|
+ case FCELL_TYPE: return *(FCELL *) ptr;
|
|
|
|
+ case DCELL_TYPE: return *(DCELL *) ptr;
|
|
|
|
+ default: return nullval;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
/* Check the input maps **************************************************** */
|
|
/* Check the input maps **************************************************** */
|
|
|
|
+
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
void check_input_maps(Database * db)
|
|
void check_input_maps(Database * db)
|
|
{
|
|
{
|
|
@@ -87,16 +87,16 @@ void check_input_maps(Database * db)
|
|
|
|
|
|
/*Check elev maps */
|
|
/*Check elev maps */
|
|
if (param.elev->answers != NULL)
|
|
if (param.elev->answers != NULL)
|
|
- for (i = 0; param.elev->answers[i] != NULL; i++)
|
|
|
|
- elevcount++;
|
|
|
|
|
|
+ for (i = 0; param.elev->answers[i] != NULL; i++)
|
|
|
|
+ elevcount++;
|
|
|
|
|
|
/*Check input maps */
|
|
/*Check input maps */
|
|
if (param.input->answers != NULL)
|
|
if (param.input->answers != NULL)
|
|
- for (i = 0; param.input->answers[i] != NULL; i++)
|
|
|
|
- inputcount++;
|
|
|
|
|
|
+ for (i = 0; param.input->answers[i] != NULL; i++)
|
|
|
|
+ inputcount++;
|
|
|
|
|
|
if (elevcount != inputcount)
|
|
if (elevcount != inputcount)
|
|
- G_fatal_error(_("The number of input and elevation maps is not equal"));
|
|
|
|
|
|
+ G_fatal_error(_("The number of input and elevation maps is not equal"));
|
|
|
|
|
|
db->mapnum = inputcount;
|
|
db->mapnum = inputcount;
|
|
|
|
|
|
@@ -105,6 +105,7 @@ void check_input_maps(Database * db)
|
|
|
|
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
/* Open the raster input map *********************************************** */
|
|
/* Open the raster input map *********************************************** */
|
|
|
|
+
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
int open_input_raster_map(const char *name)
|
|
int open_input_raster_map(const char *name)
|
|
{
|
|
{
|
|
@@ -115,6 +116,7 @@ int open_input_raster_map(const char *name)
|
|
|
|
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
/* Close the raster input map ********************************************** */
|
|
/* Close the raster input map ********************************************** */
|
|
|
|
+
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
void close_input_raster_map(int fd)
|
|
void close_input_raster_map(int fd)
|
|
{
|
|
{
|
|
@@ -123,21 +125,22 @@ void close_input_raster_map(int fd)
|
|
|
|
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
/* Error handling ********************************************************** */
|
|
/* Error handling ********************************************************** */
|
|
|
|
+
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
void fatal_error(Database db, char *errorMsg)
|
|
void fatal_error(Database db, char *errorMsg)
|
|
{
|
|
{
|
|
/* Close files and exit */
|
|
/* Close files and exit */
|
|
if (db.map != NULL) {
|
|
if (db.map != NULL) {
|
|
- /* should unopen map here! but this functionality is not jet implemented */
|
|
|
|
- if (!G3d_closeCell(db.map))
|
|
|
|
- G3d_fatalError(_("Could not close the map"));
|
|
|
|
|
|
+ /* should unopen map here! but this functionality is not jet implemented */
|
|
|
|
+ if (!G3d_closeCell(db.map))
|
|
|
|
+ G3d_fatalError(_("Could not close the map"));
|
|
}
|
|
}
|
|
|
|
|
|
if (db.input)
|
|
if (db.input)
|
|
- close_input_raster_map(db.input);
|
|
|
|
|
|
+ close_input_raster_map(db.input);
|
|
|
|
|
|
if (db.elev)
|
|
if (db.elev)
|
|
- close_input_raster_map(db.elev);
|
|
|
|
|
|
+ close_input_raster_map(db.elev);
|
|
|
|
|
|
G3d_fatalError(errorMsg);
|
|
G3d_fatalError(errorMsg);
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
@@ -145,6 +148,7 @@ void fatal_error(Database db, char *errorMsg)
|
|
|
|
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
/* Set up the arguments **************************************************** */
|
|
/* Set up the arguments **************************************************** */
|
|
|
|
+
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
void set_params()
|
|
void set_params()
|
|
{
|
|
{
|
|
@@ -158,14 +162,14 @@ void set_params()
|
|
param.upper->type = TYPE_DOUBLE;
|
|
param.upper->type = TYPE_DOUBLE;
|
|
param.upper->required = NO;
|
|
param.upper->required = NO;
|
|
param.upper->description =
|
|
param.upper->description =
|
|
- _("The value to fill the upper cells, default is null");
|
|
|
|
|
|
+ _("The value to fill the upper cells, default is null");
|
|
|
|
|
|
param.lower = G_define_option();
|
|
param.lower = G_define_option();
|
|
param.lower->key = "lower";
|
|
param.lower->key = "lower";
|
|
param.lower->type = TYPE_DOUBLE;
|
|
param.lower->type = TYPE_DOUBLE;
|
|
param.lower->required = NO;
|
|
param.lower->required = NO;
|
|
param.lower->description =
|
|
param.lower->description =
|
|
- _("The value to fill the lower cells, default is null");
|
|
|
|
|
|
+ _("The value to fill the lower cells, default is null");
|
|
|
|
|
|
param.tilesize = G_define_option();
|
|
param.tilesize = G_define_option();
|
|
param.tilesize->description = _("The maximum tile size in kilo bytes. Default is 32KB.");
|
|
param.tilesize->description = _("The maximum tile size in kilo bytes. Default is 32KB.");
|
|
@@ -178,12 +182,12 @@ void set_params()
|
|
param.fillup = G_define_flag();
|
|
param.fillup = G_define_flag();
|
|
param.fillup->key = 'u';
|
|
param.fillup->key = 'u';
|
|
param.fillup->description =
|
|
param.fillup->description =
|
|
- _("Use the input map values to fill the upper cells");
|
|
|
|
|
|
+ _("Use the input map values to fill the upper cells");
|
|
|
|
|
|
param.filllow = G_define_flag();
|
|
param.filllow = G_define_flag();
|
|
param.filllow->key = 'l';
|
|
param.filllow->key = 'l';
|
|
param.filllow->description =
|
|
param.filllow->description =
|
|
- _("Use the input map values to fill the lower cells");
|
|
|
|
|
|
+ _("Use the input map values to fill the lower cells");
|
|
|
|
|
|
param.mask = G_define_flag();
|
|
param.mask = G_define_flag();
|
|
param.mask->key = 'm';
|
|
param.mask->key = 'm';
|
|
@@ -194,6 +198,7 @@ void set_params()
|
|
|
|
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
/* Write the raster maps into the G3D map *********************************** */
|
|
/* Write the raster maps into the G3D map *********************************** */
|
|
|
|
+
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
void elev_raster_to_g3d(Database db, G3D_Region region)
|
|
void elev_raster_to_g3d(Database db, G3D_Region region)
|
|
{
|
|
{
|
|
@@ -223,117 +228,113 @@ void elev_raster_to_g3d(Database db, G3D_Region region)
|
|
|
|
|
|
|
|
|
|
G_debug(3,
|
|
G_debug(3,
|
|
- "elev_raster_to_g3d: Writing 3D raster map with depths %i rows %i cols %i and count %i.",
|
|
|
|
- depths, rows, cols, db.count);
|
|
|
|
-
|
|
|
|
- /*The mainloop */
|
|
|
|
- /* Because we read raster rows from north to south, but the coordinate system
|
|
|
|
- of the g3d cube read from south to north we need to adjust the
|
|
|
|
- Cube coordinates row = rows - y - 1.
|
|
|
|
- */
|
|
|
|
- for (y = 0; y < rows; y++) {
|
|
|
|
- G_percent(y, rows - 1, 10);
|
|
|
|
-
|
|
|
|
- Rast_get_row(db.input, input_rast, y, db.inputmaptype);
|
|
|
|
- Rast_get_row(db.elev, elev_rast, y, db.elevmaptype);
|
|
|
|
-
|
|
|
|
- for (x = 0, input_ptr = input_rast, elev_ptr = elev_rast; x < cols;
|
|
|
|
- x++, input_ptr =
|
|
|
|
- G_incr_void_ptr(input_ptr, Rast_cell_size(db.inputmaptype)),
|
|
|
|
- elev_ptr =
|
|
|
|
- G_incr_void_ptr(elev_ptr, Rast_cell_size(db.elevmaptype))) {
|
|
|
|
-
|
|
|
|
- /*Get the elevation and the input map value */
|
|
|
|
- inval =
|
|
|
|
- get_raster_value_as_double(db.inputmaptype, input_ptr, null);
|
|
|
|
- height =
|
|
|
|
- get_raster_value_as_double(db.elevmaptype, elev_ptr, null);
|
|
|
|
-
|
|
|
|
- G_debug(4,
|
|
|
|
- "Caluclating position in 3d region -> height %g with value %g",
|
|
|
|
- height, inval);
|
|
|
|
-
|
|
|
|
- /* Calculate if the G3D cell is lower or upper the elevation map
|
|
|
|
- * and set the value.*/
|
|
|
|
- if (db.count == 0) {
|
|
|
|
- /*Use this method if the 3d raster map was not touched befor */
|
|
|
|
- for (z = 0; z < depths; z++) {
|
|
|
|
-
|
|
|
|
- /*Upper cells */
|
|
|
|
- if (height < (z * tbres + bottom)) {
|
|
|
|
- if (db.useUpperVal == 1)
|
|
|
|
- value = inval; /*Input map value */
|
|
|
|
- else
|
|
|
|
- value = db.upper;
|
|
|
|
- }
|
|
|
|
- /*lower cells */
|
|
|
|
- if (height > ((z + 1) * tbres + bottom)) {
|
|
|
|
- if (db.useLowerVal == 1)
|
|
|
|
- value = inval; /*Input map value */
|
|
|
|
- else
|
|
|
|
- value = db.lower;
|
|
|
|
- }
|
|
|
|
- /*If exactly at the border, fill upper AND lower cell */
|
|
|
|
- if (height >= (z * tbres + bottom) &&
|
|
|
|
- height <= ((z + 1) * tbres + bottom))
|
|
|
|
- value = inval;
|
|
|
|
- /*If the elevation is null, set the G3D value null */
|
|
|
|
- if (G3d_isNullValueNum(&height, DCELL_TYPE))
|
|
|
|
- value = null;
|
|
|
|
-
|
|
|
|
- /*Write the value to the 3D map */
|
|
|
|
- if (G3d_putDouble(db.map, x, rows - y - 1, z, value) < 0)
|
|
|
|
- fatal_error(db, _("Error writing G3D double data"));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- /*Use this method for every following 3d raster maps access */
|
|
|
|
- for (z = 0; z < depths; z++) {
|
|
|
|
- /*Upper cells */
|
|
|
|
- if (height < (z * tbres + bottom)) {
|
|
|
|
- if (db.useUpperVal == 1)
|
|
|
|
- value = inval; /*Input map value */
|
|
|
|
- else if (db.useUpperVal == 2)
|
|
|
|
- value = db.upper;
|
|
|
|
- else
|
|
|
|
- value = G3d_getDouble(db.map, x, rows - y - 1, z);
|
|
|
|
- }
|
|
|
|
- /*lower cells */
|
|
|
|
- if (height > ((z + 1) * tbres + bottom)) {
|
|
|
|
- if (db.useLowerVal == 1)
|
|
|
|
- value = inval; /*Input map value */
|
|
|
|
- else if (db.useLowerVal == 2)
|
|
|
|
- value = db.lower;
|
|
|
|
- else
|
|
|
|
- value = G3d_getDouble(db.map, x, rows - y - 1, z);
|
|
|
|
- }
|
|
|
|
- /*If exactly at the border, fill upper AND lower cell */
|
|
|
|
- if (height >= (z * tbres + bottom) &&
|
|
|
|
- height <= ((z + 1) * tbres + bottom))
|
|
|
|
- value = inval;
|
|
|
|
- /*If the elevation is null, set the G3D value null */
|
|
|
|
- if (G3d_isNullValueNum(&height, DCELL_TYPE))
|
|
|
|
- value = G3d_getDouble(db.map, x, rows - y - 1, z);
|
|
|
|
-
|
|
|
|
- /*Write the value to the 3D map */
|
|
|
|
- if (G3d_putDouble(db.map, x, rows - y - 1, z, value) < 0)
|
|
|
|
- fatal_error(db, _("Error writing G3D double data"));
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ "elev_raster_to_g3d: Writing 3D raster map with depths %i rows %i cols %i and count %i.",
|
|
|
|
+ depths, rows, cols, db.count);
|
|
|
|
+
|
|
|
|
+ /*The mainloop */
|
|
|
|
+ for (y = 0; y < rows; y++) { /* From north to south */
|
|
|
|
+ G_percent(y, rows - 1, 10);
|
|
|
|
+
|
|
|
|
+ Rast_get_row(db.input, input_rast, y, db.inputmaptype);
|
|
|
|
+ Rast_get_row(db.elev, elev_rast, y, db.elevmaptype);
|
|
|
|
+
|
|
|
|
+ for (x = 0, input_ptr = input_rast, elev_ptr = elev_rast; x < cols;
|
|
|
|
+ x++, input_ptr =
|
|
|
|
+ G_incr_void_ptr(input_ptr, Rast_cell_size(db.inputmaptype)),
|
|
|
|
+ elev_ptr =
|
|
|
|
+ G_incr_void_ptr(elev_ptr, Rast_cell_size(db.elevmaptype))) {
|
|
|
|
+
|
|
|
|
+ /*Get the elevation and the input map value */
|
|
|
|
+ inval =
|
|
|
|
+ get_raster_value_as_double(db.inputmaptype, input_ptr, null);
|
|
|
|
+ height =
|
|
|
|
+ get_raster_value_as_double(db.elevmaptype, elev_ptr, null);
|
|
|
|
+
|
|
|
|
+ G_debug(4,
|
|
|
|
+ "Caluclating position in 3d region -> height %g with value %g",
|
|
|
|
+ height, inval);
|
|
|
|
+
|
|
|
|
+ /* Calculate if the G3D cell is lower or upper the elevation map
|
|
|
|
+ * and set the value.*/
|
|
|
|
+ if (db.count == 0) {
|
|
|
|
+ /*Use this method if the 3d raster map was not touched befor */
|
|
|
|
+ for (z = 0; z < depths; z++) {
|
|
|
|
+
|
|
|
|
+ /*Upper cells */
|
|
|
|
+ if (height < (z * tbres + bottom)) {
|
|
|
|
+ if (db.useUpperVal == 1)
|
|
|
|
+ value = inval; /*Input map value */
|
|
|
|
+ else
|
|
|
|
+ value = db.upper;
|
|
|
|
+ }
|
|
|
|
+ /*lower cells */
|
|
|
|
+ if (height > ((z + 1) * tbres + bottom)) {
|
|
|
|
+ if (db.useLowerVal == 1)
|
|
|
|
+ value = inval; /*Input map value */
|
|
|
|
+ else
|
|
|
|
+ value = db.lower;
|
|
|
|
+ }
|
|
|
|
+ /*If exactly at the border, fill upper AND lower cell */
|
|
|
|
+ if (height >= (z * tbres + bottom) &&
|
|
|
|
+ height <= ((z + 1) * tbres + bottom))
|
|
|
|
+ value = inval;
|
|
|
|
+ /*If the elevation is null, set the G3D value null */
|
|
|
|
+ if (G3d_isNullValueNum(&height, DCELL_TYPE))
|
|
|
|
+ value = null;
|
|
|
|
+
|
|
|
|
+ /*Write the value to the 3D map */
|
|
|
|
+ if (G3d_putDouble(db.map, x, y, z, value) < 0)
|
|
|
|
+ fatal_error(db, _("Error writing G3D double data"));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ /*Use this method for every following 3d raster maps access */
|
|
|
|
+ for (z = 0; z < depths; z++) {
|
|
|
|
+ /*Upper cells */
|
|
|
|
+ if (height < (z * tbres + bottom)) {
|
|
|
|
+ if (db.useUpperVal == 1)
|
|
|
|
+ value = inval; /*Input map value */
|
|
|
|
+ else if (db.useUpperVal == 2)
|
|
|
|
+ value = db.upper;
|
|
|
|
+ else
|
|
|
|
+ value = G3d_getDouble(db.map, x, y, z);
|
|
|
|
+ }
|
|
|
|
+ /*lower cells */
|
|
|
|
+ if (height > ((z + 1) * tbres + bottom)) {
|
|
|
|
+ if (db.useLowerVal == 1)
|
|
|
|
+ value = inval; /*Input map value */
|
|
|
|
+ else if (db.useLowerVal == 2)
|
|
|
|
+ value = db.lower;
|
|
|
|
+ else
|
|
|
|
+ value = G3d_getDouble(db.map, x, y, z);
|
|
|
|
+ }
|
|
|
|
+ /*If exactly at the border, fill upper AND lower cell */
|
|
|
|
+ if (height >= (z * tbres + bottom) &&
|
|
|
|
+ height <= ((z + 1) * tbres + bottom))
|
|
|
|
+ value = inval;
|
|
|
|
+ /*If the elevation is null, set the G3D value null */
|
|
|
|
+ if (G3d_isNullValueNum(&height, DCELL_TYPE))
|
|
|
|
+ value = G3d_getDouble(db.map, x, y, z);
|
|
|
|
+
|
|
|
|
+ /*Write the value to the 3D map */
|
|
|
|
+ if (G3d_putDouble(db.map, x, y, z, value) < 0)
|
|
|
|
+ fatal_error(db, _("Error writing G3D double data"));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (input_rast)
|
|
if (input_rast)
|
|
- G_free(input_rast);
|
|
|
|
|
|
+ G_free(input_rast);
|
|
if (elev_rast)
|
|
if (elev_rast)
|
|
- G_free(elev_rast);
|
|
|
|
|
|
+ G_free(elev_rast);
|
|
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
/* Main function, open the raster maps and create the G3D raster maps ****** */
|
|
/* Main function, open the raster maps and create the G3D raster maps ****** */
|
|
|
|
+
|
|
/* ************************************************************************* */
|
|
/* ************************************************************************* */
|
|
int main(int argc, char *argv[])
|
|
int main(int argc, char *argv[])
|
|
{
|
|
{
|
|
@@ -362,14 +363,14 @@ int main(int argc, char *argv[])
|
|
G_add_keyword(_("voxel"));
|
|
G_add_keyword(_("voxel"));
|
|
G_add_keyword(_("conversion"));
|
|
G_add_keyword(_("conversion"));
|
|
module->description =
|
|
module->description =
|
|
- _("Creates a 3D volume map based on 2D elevation and value raster maps.");
|
|
|
|
|
|
+ _("Creates a 3D volume map based on 2D elevation and value raster maps.");
|
|
|
|
|
|
/* Get parameters from user */
|
|
/* Get parameters from user */
|
|
set_params();
|
|
set_params();
|
|
|
|
|
|
/* Have GRASS get inputs */
|
|
/* Have GRASS get inputs */
|
|
if (G_parser(argc, argv))
|
|
if (G_parser(argc, argv))
|
|
- exit(EXIT_FAILURE);
|
|
|
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
|
|
|
/*Check if maps exist */
|
|
/*Check if maps exist */
|
|
check_input_maps(&db);
|
|
check_input_maps(&db);
|
|
@@ -383,34 +384,32 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
/*Use the input map value to fill the upper cells */
|
|
/*Use the input map value to fill the upper cells */
|
|
if (param.fillup->answer) {
|
|
if (param.fillup->answer) {
|
|
- db.useUpperVal = 1;
|
|
|
|
|
|
+ db.useUpperVal = 1;
|
|
}
|
|
}
|
|
|
|
|
|
/*Use the input map value to fill the lower cells */
|
|
/*Use the input map value to fill the lower cells */
|
|
if (param.filllow->answer) {
|
|
if (param.filllow->answer) {
|
|
- db.useLowerVal = 1;
|
|
|
|
|
|
+ db.useLowerVal = 1;
|
|
}
|
|
}
|
|
|
|
|
|
/*Set the upper value */
|
|
/*Set the upper value */
|
|
if (param.upper->answer) {
|
|
if (param.upper->answer) {
|
|
- if (sscanf(param.upper->answer, "%lf", &db.upper))
|
|
|
|
- db.useUpperVal = 2;
|
|
|
|
- else
|
|
|
|
- G_fatal_error(_("The upper value is not valid"));
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- G3d_setNullValue(&db.upper, 1, DCELL_TYPE);
|
|
|
|
|
|
+ if (sscanf(param.upper->answer, "%lf", &db.upper))
|
|
|
|
+ db.useUpperVal = 2;
|
|
|
|
+ else
|
|
|
|
+ G_fatal_error(_("The upper value is not valid"));
|
|
|
|
+ } else {
|
|
|
|
+ G3d_setNullValue(&db.upper, 1, DCELL_TYPE);
|
|
}
|
|
}
|
|
|
|
|
|
/*Set the lower value */
|
|
/*Set the lower value */
|
|
if (param.lower->answer) {
|
|
if (param.lower->answer) {
|
|
- if (sscanf(param.lower->answer, "%lf", &db.lower))
|
|
|
|
- db.useLowerVal = 2;
|
|
|
|
- else
|
|
|
|
- G_fatal_error(_("The lower value is not valid"));
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- G3d_setNullValue(&db.lower, 1, DCELL_TYPE);
|
|
|
|
|
|
+ if (sscanf(param.lower->answer, "%lf", &db.lower))
|
|
|
|
+ db.useLowerVal = 2;
|
|
|
|
+ else
|
|
|
|
+ G_fatal_error(_("The lower value is not valid"));
|
|
|
|
+ } else {
|
|
|
|
+ G3d_setNullValue(&db.lower, 1, DCELL_TYPE);
|
|
}
|
|
}
|
|
|
|
|
|
/* Figure out the current g3d region */
|
|
/* Figure out the current g3d region */
|
|
@@ -425,13 +424,13 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
/*If not equal, set the 2D windows correct */
|
|
/*If not equal, set the 2D windows correct */
|
|
if (rows != region.rows || cols != region.cols) {
|
|
if (rows != region.rows || cols != region.cols) {
|
|
- G_message(_("The 2d and 3d region settings are different. I will use the g3d settings to adjust the 2d region."));
|
|
|
|
- G_get_set_window(&window2d);
|
|
|
|
- window2d.ns_res = region.ns_res;
|
|
|
|
- window2d.ew_res = region.ew_res;
|
|
|
|
- window2d.rows = region.rows;
|
|
|
|
- window2d.cols = region.cols;
|
|
|
|
- Rast_set_window(&window2d);
|
|
|
|
|
|
+ G_message(_("The 2d and 3d region settings are different. I will use the g3d settings to adjust the 2d region."));
|
|
|
|
+ G_get_set_window(&window2d);
|
|
|
|
+ window2d.ns_res = region.ns_res;
|
|
|
|
+ window2d.ew_res = region.ew_res;
|
|
|
|
+ window2d.rows = region.rows;
|
|
|
|
+ window2d.cols = region.cols;
|
|
|
|
+ Rast_set_window(&window2d);
|
|
}
|
|
}
|
|
|
|
|
|
G_debug(2, "Open 3d raster map %s", param.output->answer);
|
|
G_debug(2, "Open 3d raster map %s", param.output->answer);
|
|
@@ -441,18 +440,18 @@ int main(int argc, char *argv[])
|
|
db.map = G3d_openNewOptTileSize(param.output->answer, G3D_USE_CACHE_XY, ®ion, DCELL_TYPE, maxSize);
|
|
db.map = G3d_openNewOptTileSize(param.output->answer, G3D_USE_CACHE_XY, ®ion, DCELL_TYPE, maxSize);
|
|
|
|
|
|
if (db.map == NULL)
|
|
if (db.map == NULL)
|
|
- fatal_error(db, _("Error opening 3d raster map"));
|
|
|
|
|
|
+ fatal_error(db, _("Error opening 3d raster map"));
|
|
|
|
|
|
|
|
|
|
/*if requested set the Mask on */
|
|
/*if requested set the Mask on */
|
|
if (param.mask->answer) {
|
|
if (param.mask->answer) {
|
|
- if (G3d_maskFileExists()) {
|
|
|
|
- changemask = 0;
|
|
|
|
- if (G3d_maskIsOff(db.map)) {
|
|
|
|
- G3d_maskOn(db.map);
|
|
|
|
- changemask = 1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (G3d_maskFileExists()) {
|
|
|
|
+ changemask = 0;
|
|
|
|
+ if (G3d_maskIsOff(db.map)) {
|
|
|
|
+ G3d_maskOn(db.map);
|
|
|
|
+ changemask = 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
G_message(_("Creating 3D raster map"));
|
|
G_message(_("Creating 3D raster map"));
|
|
@@ -460,46 +459,46 @@ int main(int argc, char *argv[])
|
|
/*For each elevation - input map couple */
|
|
/*For each elevation - input map couple */
|
|
for (i = 0; i < db.mapnum; i++) {
|
|
for (i = 0; i < db.mapnum; i++) {
|
|
|
|
|
|
- G_debug(2, "Open input raster map %s", param.input->answers[i]);
|
|
|
|
|
|
+ G_debug(2, "Open input raster map %s", param.input->answers[i]);
|
|
|
|
|
|
- db.count = i;
|
|
|
|
- /*Open input map */
|
|
|
|
- name = param.input->answers[i];
|
|
|
|
- db.input = open_input_raster_map(name);
|
|
|
|
- db.inputmaptype = Rast_map_type(name, "");
|
|
|
|
|
|
+ db.count = i;
|
|
|
|
+ /*Open input map */
|
|
|
|
+ name = param.input->answers[i];
|
|
|
|
+ db.input = open_input_raster_map(name);
|
|
|
|
+ db.inputmaptype = Rast_map_type(name, "");
|
|
|
|
|
|
- G_debug(2, "Open elev raster map %s", param.elev->answers[i]);
|
|
|
|
|
|
+ G_debug(2, "Open elev raster map %s", param.elev->answers[i]);
|
|
|
|
|
|
- /*Open elev map */
|
|
|
|
- name = param.elev->answers[i];
|
|
|
|
- db.elev = open_input_raster_map(name);
|
|
|
|
- db.elevmaptype = Rast_map_type(name, "");
|
|
|
|
|
|
+ /*Open elev map */
|
|
|
|
+ name = param.elev->answers[i];
|
|
|
|
+ db.elev = open_input_raster_map(name);
|
|
|
|
+ db.elevmaptype = Rast_map_type(name, "");
|
|
|
|
|
|
- /****************************************/
|
|
|
|
- /*Write the data into the G3D Rastermap */
|
|
|
|
- elev_raster_to_g3d(db, region);
|
|
|
|
|
|
+ /****************************************/
|
|
|
|
+ /*Write the data into the G3D Rastermap */
|
|
|
|
+ elev_raster_to_g3d(db, region);
|
|
|
|
|
|
- /*****************************************/
|
|
|
|
|
|
+ /*****************************************/
|
|
|
|
|
|
- /* Close files */
|
|
|
|
- close_input_raster_map(db.input);
|
|
|
|
- close_input_raster_map(db.elev);
|
|
|
|
|
|
+ /* Close files */
|
|
|
|
+ close_input_raster_map(db.input);
|
|
|
|
+ close_input_raster_map(db.elev);
|
|
}
|
|
}
|
|
|
|
|
|
/*We set the Mask off, if it was off before */
|
|
/*We set the Mask off, if it was off before */
|
|
if (param.mask->answer) {
|
|
if (param.mask->answer) {
|
|
- if (G3d_maskFileExists())
|
|
|
|
- if (G3d_maskIsOn(db.map) && changemask)
|
|
|
|
- G3d_maskOff(db.map);
|
|
|
|
|
|
+ if (G3d_maskFileExists())
|
|
|
|
+ if (G3d_maskIsOn(db.map) && changemask)
|
|
|
|
+ G3d_maskOff(db.map);
|
|
}
|
|
}
|
|
|
|
|
|
G_debug(2, "Close 3d raster map");
|
|
G_debug(2, "Close 3d raster map");
|
|
|
|
|
|
/* Flush all tile */
|
|
/* Flush all tile */
|
|
if (!G3d_flushAllTiles(db.map))
|
|
if (!G3d_flushAllTiles(db.map))
|
|
- G3d_fatalError("Error flushing tiles with G3d_flushAllTiles");
|
|
|
|
|
|
+ G3d_fatalError("Error flushing tiles with G3d_flushAllTiles");
|
|
if (!G3d_closeCell(db.map))
|
|
if (!G3d_closeCell(db.map))
|
|
- G3d_fatalError(_("Error closing 3d raster map"));
|
|
|
|
|
|
+ G3d_fatalError(_("Error closing 3d raster map"));
|
|
|
|
|
|
G_debug(2, "\nDone\n");
|
|
G_debug(2, "\nDone\n");
|
|
|
|
|