[GRASS-SVN] r50691 - in grass/trunk: include include/defs lib/gis
lib/python lib/raster3d
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 6 08:22:34 EST 2012
Author: huhabla
Date: 2012-02-06 05:22:34 -0800 (Mon, 06 Feb 2012)
New Revision: 50691
Modified:
grass/trunk/include/datetime.h
grass/trunk/include/defs/gis.h
grass/trunk/include/defs/raster3d.h
grass/trunk/include/gis.h
grass/trunk/include/raster3d.h
grass/trunk/lib/gis/units.c
grass/trunk/lib/python/raster3d.py
grass/trunk/lib/raster3d/close.c
grass/trunk/lib/raster3d/defaults.c
grass/trunk/lib/raster3d/header.c
grass/trunk/lib/raster3d/headerinfo.c
grass/trunk/lib/raster3d/open.c
grass/trunk/lib/raster3d/raster3d_intern.h
grass/trunk/lib/raster3d/raster3dlib.dox
Log:
Added vertical unit to raster3d map header structure. Temporal units are
integrated into libgis.
Modified: grass/trunk/include/datetime.h
===================================================================
--- grass/trunk/include/datetime.h 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/include/datetime.h 2012-02-06 13:22:34 UTC (rev 50691)
@@ -4,13 +4,15 @@
#define DATETIME_ABSOLUTE 1
#define DATETIME_RELATIVE 2
-/* ranges - the values must start at 1 and increase */
-#define DATETIME_YEAR 1
-#define DATETIME_MONTH 2
-#define DATETIME_DAY 3
-#define DATETIME_HOUR 4
-#define DATETIME_MINUTE 5
-#define DATETIME_SECOND 6
+/* ranges - the values must start at 101 and increase
+ * to make sure they do not interfere with the spatial
+ * units in gis.h */
+#define DATETIME_YEAR 101
+#define DATETIME_MONTH 102
+#define DATETIME_DAY 103
+#define DATETIME_HOUR 104
+#define DATETIME_MINUTE 105
+#define DATETIME_SECOND 106
typedef struct DateTime
{
Modified: grass/trunk/include/defs/gis.h
===================================================================
--- grass/trunk/include/defs/gis.h 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/include/defs/gis.h 2012-02-06 13:22:34 UTC (rev 50691)
@@ -647,6 +647,8 @@
double G_units_to_meters_factor_sq(int);
const char *G_get_units_name(int, int, int);
int G_units(const char *);
+int G_is_units_type_spatial(int);
+int G_is_units_type_temporal(int);
/* user_config.c */
#ifndef __MINGW32__
Modified: grass/trunk/include/defs/raster3d.h
===================================================================
--- grass/trunk/include/defs/raster3d.h 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/include/defs/raster3d.h 2012-02-06 13:22:34 UTC (rev 50691)
@@ -55,29 +55,29 @@
int Rast3d_fpcompress_read_xdr_floats(int, char *, int, int, int, char *);
int Rast3d_fpcompress_read_xdr_doubles(int, char *, int, int, int, char *);
-/* g3dalloc.c */
+/* alloc.c */
void *Rast3d_malloc(int);
void *Rast3d_realloc(void *, int);
void Rast3d_free(void *);
-/* g3dcache.c */
+/* cache.c */
int Rast3d_init_cache(RASTER3D_Map *, int);
int Rast3d_dispose_cache(RASTER3D_Map *);
int Rast3d_flush_all_tiles(RASTER3D_Map *);
-/* g3dcats.c */
+/* cats.c */
int Rast3d_write_cats(const char *, struct Categories *);
int Rast3d_read_cats(const char *, const char *, struct Categories *);
-/* g3dclose.c */
+/* close.c */
int Rast3d_close(RASTER3D_Map *);
-/* g3dcolor.c */
+/* color.c */
int Rast3d_remove_color(const char *);
int Rast3d_read_colors(const char *, const char *, struct Colors *);
int Rast3d_write_colors(const char *, const char *, struct Colors *);
-/* g3ddefaults.c */
+/* defaults.c */
void Rast3d_set_compression_mode(int, int, int, int);
void Rast3d_get_compression_mode(int *, int *, int *, int *);
void Rast3d_set_cache_size(int);
@@ -89,14 +89,13 @@
void Rast3d_set_tile_dimension(int, int, int);
void Rast3d_get_tile_dimension(int *, int *, int *);
void Rast3d_set_error_fun(void (*)(const char *));
-void Rast3d_set_unit(const char *);
void Rast3d_init_defaults(void);
-/* g3ddoubleio.c */
+/* doubleio.c */
int Rast3d_write_doubles(int, int, const double *, int);
int Rast3d_read_doubles(int, int, double *, int);
-/* g3derror.c */
+/* error.c */
void Rast3d_skip_error(const char *);
void Rast3d_print_error(const char *);
void Rast3d_fatal_error(const char *, ...) __attribute__ ((format(printf, 1, 2)))
@@ -104,7 +103,7 @@
void Rast3d_fatal_error_noargs(const char *) __attribute__ ((noreturn));
void Rast3d_error(const char *, ...) __attribute__ ((format(printf, 1, 2)));
-/* g3dfpxdr.c */
+/* fpxdr.c */
int Rast3d_is_xdr_null_num(const void *, int);
int Rast3d_is_xdr_null_float(const float *);
int Rast3d_is_xdr_null_double(const double *);
@@ -117,15 +116,15 @@
int Rast3d_init_copy_from_xdr(RASTER3D_Map *, int);
int Rast3d_copy_from_xdr(int, void *);
-/* g3dhistory.c */
+/* history.c */
int Rast3d_write_history(const char *, struct History *);
int Rast3d_read_history(const char *, const char *, struct History *);
-/* g3dintio.c */
+/* intio.c */
int Rast3d_write_ints(int, int, const int *, int);
int Rast3d_read_ints(int, int, int *, int);
-/* g3dkeys.c */
+/* keys.c */
int Rast3d_key_get_int(struct Key_Value *, const char *, int *);
int Rast3d_key_get_double(struct Key_Value *, const char *, double *);
int Rast3d_key_get_string(struct Key_Value *, const char *, char **);
@@ -136,14 +135,14 @@
int Rast3d_key_set_string(struct Key_Value *, const char *, char *const *);
int Rast3d_key_set_value(struct Key_Value *, const char *, const char *,
const char *, int, int, const int *);
-/* g3dlong.c */
+/* long.c */
int Rast3d_long_encode(long *, unsigned char *, int);
void Rast3d_long_decode(unsigned char *, long *, int, int);
-/* g3dmapset.c */
+/* mapset.c */
void Rast3d_make_mapset_map_directory(const char *);
-/* g3dmask.c */
+/* mask.c */
int Rast3d_mask_close(void);
int Rast3d_mask_file_exists(void);
int Rast3d_mask_open_old(void);
@@ -165,7 +164,7 @@
DCELL Rast3d_mask_match_d_interval(DCELL, d_Interval *);
void Rast3d_parse_vallist(char **, d_Mask **);
-/* g3dmisc.c */
+/* misc.c */
int Rast3d_g3d_type2cell_type(int);
void Rast3d_copy_float2Double(const float *, int, double *, int, int);
void Rast3d_copy_double2Float(const double *, int, float *, int, int);
@@ -173,26 +172,26 @@
int Rast3d_length(int);
int Rast3d_extern_length(int);
-/* g3dnull.c */
+/* null.c */
int Rast3d_is_null_value_num(const void *, int);
void Rast3d_set_null_value(void *, int, int);
-/* g3dopen2.c */
+/* open2.c */
void *Rast3d_open_new_param(const char *, int , int, RASTER3D_Region *, int, int, int, int, int, int, int);
-/* g3dopen.c */
+/* open.c */
void *Rast3d_open_cell_old_no_header(const char *, const char *);
void *Rast3d_open_cell_old(const char *, const char *, RASTER3D_Region *, int, int);
void *Rast3d_open_cell_new(const char *, int, int, RASTER3D_Region *);
void *Rast3d_open_new_opt_tile_size(const char *, int , RASTER3D_Region * , int , int );
-/* g3dparam.c */
+/* param.c */
void Rast3d_set_standard3d_input_params(void);
int Rast3d_get_standard3d_params(int *, int *, int *, int *, int *, int *, int *,
int *, int *, int *, int *, int *);
void Rast3d_set_window_params(void);
char *Rast3d_get_window_params(void);
-/* g3drange.c */
+/* range.c */
void Rast3d_range_update_from_tile(RASTER3D_Map *, const void *, int, int, int, int,
int, int, int, int);
int Rast3d_read_range(const char *, const char *, struct FPRange *);
@@ -201,7 +200,7 @@
int Rast3d_range_write(RASTER3D_Map *);
int Rast3d_range_init(RASTER3D_Map *);
-/* g3dregion.c */
+/* region.c */
void Rast3d_get_region_value(RASTER3D_Map *, double, double, double, void *, int);
void Rast3d_adjust_region(RASTER3D_Region *);
void Rast3d_region_copy(RASTER3D_Region *, RASTER3D_Region *);
@@ -215,13 +214,13 @@
void Rast3d_location2coord(RASTER3D_Region *, double, double, double, int *, int *, int *);
void Rast3d_location2coord2(RASTER3D_Region *, double, double, double, int *, int *, int *);
void Rast3d_coord2location(RASTER3D_Region *, double, double, double, double *, double *, double *);
-/* g3dresample.c */
+/* resample.c */
void Rast3d_nearest_neighbor(RASTER3D_Map *, int, int, int, void *, int);
void Rast3d_set_resampling_fun(RASTER3D_Map *, void (*)());
void Rast3d_get_resampling_fun(RASTER3D_Map *, void (**)());
void Rast3d_get_nearest_neighbor_fun_ptr(void (**)());
-/* g3dvolume.c */
+/* volume.c */
void Rast3d_get_volume_a(void *, double[2][2][2][3], int, int, int, void *, int);
void Rast3d_get_volume(void *, double, double, double, double, double, double,
double, double, double, double, double, double, int, int,
@@ -230,7 +229,7 @@
double, int, int, int, void *, int);
void Rast3d_make_aligned_volume_file(void *, const char *, double, double, double,
double, double, double, int, int, int);
-/* g3dwindow.c */
+/* window.c */
void Rast3d_get_value(RASTER3D_Map *, int, int, int, void *, int);
float Rast3d_get_float(RASTER3D_Map *, int, int, int);
double Rast3d_get_double(RASTER3D_Map *, int, int, int);
@@ -242,7 +241,7 @@
void Rast3d_set_window_map(RASTER3D_Map *, RASTER3D_Region *);
void Rast3d_get_window(RASTER3D_Region *);
-/* g3dwindowio.c */
+/* windowio.c */
void Rast3d_use_window_params(void);
int Rast3d_read_window(RASTER3D_Region *, const char *);
@@ -256,17 +255,18 @@
int Rast3d_read_header(RASTER3D_Map *, int *, int *, double *, double *, double *,
double *, double *, double *, int *, int *, int *,
double *, double *, double *, int *, int *, int *, int *,
- int *, int *, int *, int *, int *, int *, int *, char **);
+ int *, int *, int *, int *, int *, int *, int *, char **, int *);
int Rast3d_write_header(RASTER3D_Map *, int, int, double, double, double, double,
double, double, int, int, int, double, double, double,
int, int, int, int, int, int, int, int, int, int, int,
- char *);
+ char *, int);
+int Rast3d_rewrite_header(RASTER3D_Map * map);
int Rast3d_cache_size_encode(int, int);
int Rast3d__compute_cache_size(RASTER3D_Map *, int);
int Rast3d_fill_header(RASTER3D_Map *, int, int, int, int, int, int, int, int, int,
int, int, int, int, int, int, int, double, double, double,
double, double, double, int, int, int, double, double,
- double, char *);
+ double, char *, int);
/* headerinfo.c */
void Rast3d_get_coords_map(RASTER3D_Map *, int *, int *, int *);
void Rast3d_get_coords_map_window(RASTER3D_Map *, int *, int *, int *);
@@ -282,6 +282,12 @@
int Rast3d_tile_use_cache_map(RASTER3D_Map *);
void Rast3d_print_header(RASTER3D_Map *);
void Rast3d_get_region_struct_map(RASTER3D_Map *, RASTER3D_Region *);
+const char* Rast3d_get_unit(RASTER3D_Map * map);
+int Rast3d_get_vertical_unit2(RASTER3D_Map * map);
+const char* Rast3d_get_vertical_unit(RASTER3D_Map * map);
+void Rast3d_set_unit(RASTER3D_Map * map, const char *);
+void Rast3d_set_vertical_unit(RASTER3D_Map * map, const char *);
+void Rast3d_set_vertical_unit2(RASTER3D_Map * map, int);
/* index.c */
int Rast3d_flush_index(RASTER3D_Map *);
Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/include/gis.h 2012-02-06 13:22:34 UTC (rev 50691)
@@ -74,6 +74,13 @@
#define U_FEET 6
#define U_RADIANS 7
#define U_DEGREES 8
+/* Temporal units from the datetime library */
+#define U_YEARS DATETIME_YEAR
+#define U_MONTHS DATETIME_MONTH
+#define U_DAYS DATETIME_DAY
+#define U_HOURS DATETIME_HOUR
+#define U_MINUTES DATETIME_MINUTE
+#define U_SECONDS DATETIME_SECOND
#define PROJECTION_XY 0
#define PROJECTION_UTM 1
Modified: grass/trunk/include/raster3d.h
===================================================================
--- grass/trunk/include/raster3d.h 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/include/raster3d.h 2012-02-06 13:22:34 UTC (rev 50691)
@@ -90,7 +90,8 @@
resample_fn *resampleFun;
/* units */
- char *unit;
+ char* unit; /* space (U_METER, ...) */
+ int vertical_unit; /* space or time (U_METER, ..., U_YEAR, ...) */
/* dimension of a single tile in "cells" */
int tileX, tileY, tileZ;
Modified: grass/trunk/lib/gis/units.c
===================================================================
--- grass/trunk/lib/gis/units.c 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/lib/gis/units.c 2012-02-06 13:22:34 UTC (rev 50691)
@@ -10,6 +10,7 @@
\author Original author CERL
\author Adopted for libgis by Martin Landa <landa.martin gmail.com> (2010)
+ \author Temporal units and unit type check from Soeren gebbert <soerengebbert googlemail.com> (2012)
*/
#include <string.h>
@@ -113,6 +114,62 @@
return 1.0;
}
+/** \brief Check if the unit is of spatial type
+
+ \param units units code from gis.h
+
+ \return 1 if True, 0 otherwise
+ */
+
+int G_is_units_type_spatial(int units)
+{
+ switch (units) {
+ case U_METERS:
+ return 1;
+ case U_KILOMETERS:
+ return 1;
+ case U_HECTARES:
+ return 1;
+ case U_ACRES:
+ return 1;
+ case U_MILES:
+ return 1;
+ case U_FEET:
+ return 1;
+ case U_RADIANS:
+ return 1;
+ case U_DEGREES:
+ return 1;
+ }
+ return 0;
+}
+
+/** \brief Check if the unit is of temporal type
+
+ \param units units code from gis.h
+
+ \return 1 if True, 0 otherwise
+ */
+
+int G_is_units_type_temporal(int units)
+{
+ switch (units) {
+ case U_YEARS:
+ return 1;
+ case U_MONTHS:
+ return 1;
+ case U_DAYS:
+ return 1;
+ case U_HOURS:
+ return 1;
+ case U_MINUTES:
+ return 1;
+ case U_SECONDS:
+ return 1;
+ }
+ return 0;
+}
+
/*!
\brief Get localized units name
@@ -190,8 +247,31 @@
return plural ? _("square degrees") : _("square degree");
else
return plural ? _("degrees") : _("degree");
+ break;
+
+ case U_YEARS:
+ return plural ? _("year") : _("years");
break;
-
+
+ case U_MONTHS:
+ return plural ? _("month") : _("months");
+ break;
+
+ case U_DAYS:
+ return plural ? _("day") : _("days");
+ break;
+
+ case U_HOURS:
+ return plural ? _("hour") : _("hours");
+ break;
+
+ case U_MINUTES:
+ return plural ? _("minute") : _("minutes");
+ break;
+
+ case U_SECONDS:
+ return plural ? _("second") : _("seconds");
+ break;
}
return NULL;
@@ -207,6 +287,9 @@
- U_HECTARES
- U_MILES
- U_FEET
+ - ...
+ - U_YEARS
+ - ...
\param units_name units name (singular or plural form)
@@ -240,6 +323,24 @@
else if (strcasecmp(units_name, "degree") == 0 ||
strcasecmp(units_name, "degrees") == 0)
return U_DEGREES;
+ else if (strcasecmp(units_name, "year") == 0 ||
+ strcasecmp(units_name, "years") == 0)
+ return U_YEARS;
+ else if (strcasecmp(units_name, "month") == 0 ||
+ strcasecmp(units_name, "months") == 0)
+ return U_MONTHS;
+ else if (strcasecmp(units_name, "day") == 0 ||
+ strcasecmp(units_name, "days") == 0)
+ return U_DAYS;
+ else if (strcasecmp(units_name, "hour") == 0 ||
+ strcasecmp(units_name, "hours") == 0)
+ return U_HOURS;
+ else if (strcasecmp(units_name, "minute") == 0 ||
+ strcasecmp(units_name, "minutes") == 0)
+ return U_MINUTES;
+ else if (strcasecmp(units_name, "secons") == 0 ||
+ strcasecmp(units_name, "seconds") == 0)
+ return U_SECONDS;
return U_UNKNOWN;
}
Modified: grass/trunk/lib/python/raster3d.py
===================================================================
--- grass/trunk/lib/python/raster3d.py 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/lib/python/raster3d.py 2012-02-06 13:22:34 UTC (rev 50691)
@@ -54,7 +54,7 @@
else:
return float(s)
- s = read_command('r3.info', flags = 'rstgip', map = map)
+ s = read_command('r3.info', flags='rg', map=map)
kv = parse_key_val(s)
for k in ['min', 'max']:
kv[k] = float_or_null(kv[k])
Modified: grass/trunk/lib/raster3d/close.c
===================================================================
--- grass/trunk/lib/raster3d/close.c 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/lib/raster3d/close.c 2012-02-06 13:22:34 UTC (rev 50691)
@@ -187,12 +187,11 @@
map->type,
map->compression, map->useRle, map->useLzw,
map->precision, map->offset, map->useXdr,
- map->hasIndex, map->unit)) {
+ map->hasIndex, map->unit, map->vertical_unit)) {
G_warning(_("Unable to write header for 3D raster map <%s>"), map->fileName);
return 0;
}
- Rast3d_free(map->unit);
Rast3d_free(map);
return 1;
Modified: grass/trunk/lib/raster3d/defaults.c
===================================================================
--- grass/trunk/lib/raster3d/defaults.c 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/lib/raster3d/defaults.c 2012-02-06 13:22:34 UTC (rev 50691)
@@ -19,6 +19,7 @@
#define RASTER3D_TILE_Z_DEFAULT 8
#define RASTER3D_ERROR_FUN_DEFAULT Rast3d_skip_error
#define RASTER3D_UNIT_DEFAULT "none"
+#define RASTER3D_VERTICAL_UNIT_DEFAULT U_UNKNOWN
/*---------------------------------------------------------------------------*/
@@ -62,6 +63,7 @@
{ RASTER3D_NO_DEFAULT, RASTER3D_NO_DEFAULT, RASTER3D_NO_DEFAULT };
void (*g3d_error_fun) (const char *) = NULL;
char *g3d_unit_default = NULL;
+int g3d_vertical_unit_default = U_UNDEFINED;
/*---------------------------------------------------------------------------*/
@@ -318,25 +320,7 @@
/*!
* \brief
*
- * set G3d unit
- *
- * \param unit
- * \return void
- */
-
-void Rast3d_set_unit(const char *unit)
-{
- Rast3d_free(g3d_unit_default);
- g3d_unit_default = G_store(unit);
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-/*!
- * \brief
- *
- * Initializes the default values described
+ * Initializes the default values described
* in RASTER3D Defaults. Applications have to use this function only if they need to
* query the default values before the first file (either old or new) has been
* opened.
@@ -538,8 +522,10 @@
}
}
- if (g3d_unit_default == NULL)
- g3d_unit_default = G_store(RASTER3D_UNIT_DEFAULT);
+ if(g3d_unit_default == NULL)
+ g3d_unit_default = G_store(RASTER3D_UNIT_DEFAULT);
+ if(g3d_vertical_unit_default == U_UNDEFINED)
+ g3d_vertical_unit_default = RASTER3D_VERTICAL_UNIT_DEFAULT;
windowName = Rast3d_get_window_params();
if (windowName == NULL) {
Modified: grass/trunk/lib/raster3d/header.c
===================================================================
--- grass/trunk/lib/raster3d/header.c 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/lib/raster3d/header.c 2012-02-06 13:22:34 UTC (rev 50691)
@@ -5,6 +5,7 @@
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <grass/raster3d.h>
+#include <grass/glocale.h>
#include "raster3d_intern.h"
/*---------------------------------------------------------------------------*/
@@ -28,6 +29,7 @@
#define RASTER3D_HEADER_USEXDR "useXdr"
#define RASTER3D_HEADER_HASINDEX "hasIndex"
#define RASTER3D_HEADER_UNIT "Units"
+#define RASTER3D_HEADER_VERTICAL_UNIT "VerticalUnits"
/*---------------------------------------------------------------------------*/
@@ -39,7 +41,7 @@
double *tb_res, int *tileX, int *tileY, int *tileZ,
int *type, int *compression, int *useRle, int *useLzw,
int *precision, int *dataOffset, int *useXdr,
- int *hasIndex, char **unit)
+ int *hasIndex, char **unit, int *vertical_unit)
{
int returnVal;
int (*headerInt) (), (*headerDouble) (), (*headerValue) ();
@@ -98,11 +100,16 @@
returnVal &= headerValue(headerKeys, RASTER3D_HEADER_HASINDEX,
"0", "1", 0, 1, hasIndex);
returnVal &= headerString(headerKeys, RASTER3D_HEADER_UNIT, unit);
+ /* New format and API changes */
+ if(!headerInt(headerKeys, RASTER3D_HEADER_VERTICAL_UNIT, vertical_unit))
+ G_warning("You are using an old raster3d data format, the vertical unit is undefined. "
+ "Please use r3.support to define the vertical unit to avoid this warning.");
+
if (returnVal)
return 1;
- Rast3d_error("Rast3d_readWriteHeader: error writing header");
+ Rast3d_error("Rast3d_readWriteHeader: error reading/writing header");
return 0;
}
@@ -115,7 +122,7 @@
double *ew_res, double *ns_res, double *tb_res, int *tileX,
int *tileY, int *tileZ, int *type, int *compression,
int *useRle, int *useLzw, int *precision, int *dataOffset,
- int *useXdr, int *hasIndex, char **unit)
+ int *useXdr, int *hasIndex, char **unit, int *vertical_unit)
{
struct Key_Value *headerKeys;
char path[GPATH_MAX];
@@ -135,7 +142,7 @@
ew_res, ns_res, tb_res,
tileX, tileY, tileZ,
type, compression, useRle, useLzw, precision,
- dataOffset, useXdr, hasIndex, unit)) {
+ dataOffset, useXdr, hasIndex, unit, vertical_unit)) {
Rast3d_error("Rast3d_read_header: error extracting header key(s) of file %s",
path);
return 0;
@@ -153,7 +160,7 @@
int cols, int depths, double ew_res, double ns_res,
double tb_res, int tileX, int tileY, int tileZ, int type,
int compression, int useRle, int useLzw, int precision,
- int dataOffset, int useXdr, int hasIndex, char *unit)
+ int dataOffset, int useXdr, int hasIndex, char *unit, int vertical_unit)
{
struct Key_Value *headerKeys;
char path[GPATH_MAX];
@@ -168,7 +175,7 @@
&tileX, &tileY, &tileZ,
&type, &compression, &useRle, &useLzw,
&precision, &dataOffset, &useXdr, &hasIndex,
- &unit)) {
+ &unit, &vertical_unit)) {
Rast3d_error("Rast3d_write_header: error adding header key(s) for file %s",
path);
return 0;
@@ -182,7 +189,31 @@
return 1;
}
+/*---------------------------------------------------------------------------*/
+int
+Rast3d_rewrite_header(RASTER3D_Map * map)
+{
+ if (!Rast3d_write_header(map,
+ map->region.proj, map->region.zone,
+ map->region.north, map->region.south,
+ map->region.east, map->region.west,
+ map->region.top, map->region.bottom,
+ map->region.rows, map->region.cols,
+ map->region.depths,
+ map->region.ew_res, map->region.ns_res,
+ map->region.tb_res,
+ map->tileX, map->tileY, map->tileZ,
+ map->type,
+ map->compression, map->useRle, map->useLzw,
+ map->precision, map->offset, map->useXdr,
+ map->hasIndex, map->unit, map->vertical_unit)) {
+ G_warning(_("Unable to write header for 3D raster map <%s>"), map->fileName);
+ return 0;
+ }
+ return 1;
+}
+
/*---------------------------------------------------------------------------*/
@@ -272,7 +303,7 @@
int tileY, int tileZ, int proj, int zone, double north,
double south, double east, double west, double top,
double bottom, int rows, int cols, int depths, double ew_res,
- double ns_res, double tb_res, char *unit)
+ double ns_res, double tb_res, char *unit, int vertical_unit)
{
if (!RASTER3D_VALID_OPERATION(operation))
Rast3d_fatal_error("Rast3d_fill_header: operation not valid\n");
@@ -280,6 +311,7 @@
map->operation = operation;
map->unit = G_store(unit);
+ map->vertical_unit = vertical_unit;
map->region.proj = proj;
map->region.zone = zone;
Modified: grass/trunk/lib/raster3d/headerinfo.c
===================================================================
--- grass/trunk/lib/raster3d/headerinfo.c 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/lib/raster3d/headerinfo.c 2012-02-06 13:22:34 UTC (rev 50691)
@@ -165,10 +165,113 @@
/*---------------------------------------------------------------------------*/
+/*!
+ * \brief
+ *
+ * Set the data unit defintiong
+ *
+ * \param map
+ * \param unit
+ * \return void
+ */
+void Rast3d_set_unit(RASTER3D_Map * map, const char *unit)
+{
+ map->unit = G_store(unit);
+}
+
+/*---------------------------------------------------------------------------*/
+
/*!
* \brief
*
+ * set Vertical unit from integer value defined in gis.h (U_METERS, ...)
+ *
+ * \param map
+ * \param unit
+ * \return void
+ */
+
+void Rast3d_set_vertical_unit2(RASTER3D_Map * map, int vertical_unit)
+{
+ map->vertical_unit = vertical_unit;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief
+ *
+ * set Vertical unit from string
+ *
+ * \param map
+ * \param unit
+ * \return void
+ */
+
+void Rast3d_set_vertical_unit(RASTER3D_Map * map, const char *vertical_unit)
+{
+ map->vertical_unit = G_units(vertical_unit);
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief
+ *
+ * Return the data unit definition of <em>map</em>.
+ *
+ * \param map
+ * \return int
+ */
+
+const char* Rast3d_get_unit(RASTER3D_Map * map)
+{
+ return map->unit;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief
+ *
+ * Returns the vertical unit of <em>map</em> as integer. Units are defined in gis.h.
+ *
+ * Vertical units may have temporal type
+ *
+ * \param map
+ * \return int
+ */
+
+int Rast3d_get_vertical_unit2(RASTER3D_Map * map)
+{
+ return map->vertical_unit;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*!
+ * \brief
+ *
+ * Return the name of the unit of <em>map</em>. Units are defined in gis.h.
+ *
+ * Vertical units may have temporal type
+ *
+ * \param map
+ * \return int
+ */
+
+const char* Rast3d_get_vertical_unit(RASTER3D_Map * map)
+{
+ return G_get_units_name(map->vertical_unit, 1, 0);
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*!
+ * \brief
+ *
* Returns the type with which tiles of <em>map</em> are stored on file.
*
* \param map
@@ -232,8 +335,8 @@
printf("File %s open for %sing:\n", map->fileName,
(map->operation == RASTER3D_WRITE_DATA ? "writ" :
(map->operation == RASTER3D_READ_DATA ? "read" : "unknown")));
- printf(" Fd = %d, Unit %s, Type: %s, ", map->data_fd,
- map->unit,
+ printf(" Fd = %d, Unit %s, Vertical Unit %s, Type: %s, ", map->data_fd,
+ map->unit, G_get_units_name(map->vertical_unit, 1, 0),
(map->type == FCELL_TYPE ? "float" :
(map->type == DCELL_TYPE ? "double" : "unknown")));
printf("Type intern: %s\n",
Modified: grass/trunk/lib/raster3d/open.c
===================================================================
--- grass/trunk/lib/raster3d/open.c 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/lib/raster3d/open.c 2012-02-06 13:22:34 UTC (rev 50691)
@@ -84,6 +84,7 @@
double ew_res, ns_res, tb_res;
int nofHeaderBytes, dataOffset, useXdr, hasIndex;
char *ltmp, *unit;
+ int vertical_unit;
double north, south, east, west, top, bottom;
map = Rast3d_open_cell_old_no_header(name, mapset);
@@ -104,7 +105,7 @@
&ew_res, &ns_res, &tb_res,
&tileX, &tileY, &tileZ,
&type, &compression, &useRle, &useLzw,
- &precision, &dataOffset, &useXdr, &hasIndex, &unit)) {
+ &precision, &dataOffset, &useXdr, &hasIndex, &unit, &vertical_unit)) {
Rast3d_error(_("Rast3d_open_cell_old: error in Rast3d_read_header"));
return 0;
}
@@ -164,7 +165,7 @@
nofHeaderBytes, tileX, tileY, tileZ,
proj, zone,
north, south, east, west, top, bottom,
- rows, cols, depths, ew_res, ns_res, tb_res, unit)) {
+ rows, cols, depths, ew_res, ns_res, tb_res, unit, vertical_unit)) {
Rast3d_error(_("Rast3d_open_cell_old: error in Rast3d_fill_header"));
return (void *)NULL;
}
@@ -308,7 +309,7 @@
region->west, region->top, region->bottom,
region->rows, region->cols, region->depths,
region->ew_res, region->ns_res, region->tb_res,
- g3d_unit_default)) {
+ g3d_unit_default, g3d_vertical_unit_default)) {
Rast3d_error(_("Rast3d_open_cell_new: error in Rast3d_fill_header"));
return (void *)NULL;
}
Modified: grass/trunk/lib/raster3d/raster3d_intern.h
===================================================================
--- grass/trunk/lib/raster3d/raster3d_intern.h 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/lib/raster3d/raster3d_intern.h 2012-02-06 13:22:34 UTC (rev 50691)
@@ -55,7 +55,8 @@
extern int g3d_file_type; /* FCELL_TYPE or DCELL_TYPE */
extern int g3d_tile_dimension[3];
extern void (*g3d_error_fun) (const char *);
-extern char *g3d_unit_default;
+extern char *g3d_unit_default; /* The unit description of the map data */
+extern int g3d_vertical_unit_default; /* spatial or temporal units from gis.h, U_METERS; ..., U_YEARS, ... */
extern RASTER3D_Region g3d_window;
Modified: grass/trunk/lib/raster3d/raster3dlib.dox
===================================================================
--- grass/trunk/lib/raster3d/raster3dlib.dox 2012-02-06 11:15:55 UTC (rev 50690)
+++ grass/trunk/lib/raster3d/raster3dlib.dox 2012-02-06 13:22:34 UTC (rev 50691)
@@ -232,6 +232,7 @@
useXdr: 1
hasIndex: 1
Units: none
+VerticalUnits: 1
\endverbatim
<P>
@@ -600,17 +601,25 @@
\section Setting_the_Units Setting the Units
-<P>
-Default <TT>"none"</TT>.
+The data untis of a map can be described using a string.
+The vertical units are defined in gis.h and can be spatial or temporal.
<P>
No environment variable.
<P>
-void Rast3d_setUnit (unit)
- char *unit;
-
+void Rast3d_set_unit (map, unit)
+ RASTER3d_Map; /* the map */
+ char *unit; /* The data unit description */
<P>
+void Rast3d_set_vertical_unit (map, unit)
+ RASTER3d_Map; /* the map */
+ char *unit; /* Use the standard from units.c in lib/gis */
+<P>
+void Rast3d_set_vertical_unit2 (map, unit)
+ RASTER3d_Map; /* the map */
+ int unit; /* defined in gis.h */
+<P>
\section Error_Handling Error Handling: Setting the error function
More information about the grass-commit
mailing list