[GRASS-SVN] r70853 - grass/trunk/imagery/i.ortho.photo/i.ortho.elev
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Apr 9 09:37:13 PDT 2017
Author: ychemin
Date: 2017-04-09 09:37:13 -0700 (Sun, 09 Apr 2017)
New Revision: 70853
Modified:
grass/trunk/imagery/i.ortho.photo/i.ortho.elev/main.c
Log:
More information can be added to the ELEVATION file
Modified: grass/trunk/imagery/i.ortho.photo/i.ortho.elev/main.c
===================================================================
--- grass/trunk/imagery/i.ortho.photo/i.ortho.elev/main.c 2017-04-08 20:05:19 UTC (rev 70852)
+++ grass/trunk/imagery/i.ortho.photo/i.ortho.elev/main.c 2017-04-09 16:37:13 UTC (rev 70853)
@@ -39,7 +39,8 @@
{
struct GModule *module;
- struct Option *group_opt, *elev_opt;
+ struct Option *group_opt, *loc_opt, *mapset_opt, *elev_opt;
+ struct Option *math_opt, *unit_opt, *nd_opt;
struct Flag *list_flag, *print_flag;
char location[GMAPSET_MAX];
@@ -48,7 +49,7 @@
char *elev_layer;
char *mapset_elev;
- char *tl;
+ char *location_elev;
char *math_exp;
char *units;
char *nd;
@@ -69,16 +70,37 @@
group_opt->description =
_("Name of imagery group for ortho-rectification");
+ loc_opt = G_define_standard_option(G_OPT_M_LOCATION);
+ loc_opt->required = NO;
+ loc_opt->description =
+ _("Name of the target location");
+
+ mapset_opt = G_define_standard_option(G_OPT_M_MAPSET);
+ mapset_opt->required = NO;
+ mapset_opt->description =
+ _("Name of the target mapset");
+
elev_opt = G_define_standard_option(G_OPT_R_ELEV);
elev_opt->required = NO;
elev_opt->description =
_("Name of elevation map to use for ortho-rectification");
- list_flag = G_define_flag();
- list_flag->key = 'l';
- list_flag->description =
- _("List available raster maps in target mapset and exit");
+ math_opt = G_define_standard_option(G_OPT_M_NULL_VALUE);
+ math_opt->key = "math_expression";
+ math_opt->required = NO;
+ math_opt->description =
+ _("Math expression to convert to real elevation");
+ unit_opt = G_define_standard_option(G_OPT_M_UNITS);
+ unit_opt->required = NO;
+ unit_opt->description =
+ _("Unit of the elevation map");
+
+ nd_opt = G_define_standard_option(G_OPT_M_NULL_VALUE);
+ nd_opt->required = NO;
+ nd_opt->description =
+ _("No data value");
+
print_flag = G_define_flag();
print_flag->key = 'p';
print_flag->description =
@@ -89,92 +111,108 @@
elev_layer = (char *)G_malloc(GNAME_MAX * sizeof(char));
mapset_elev = (char *)G_malloc(GMAPSET_MAX * sizeof(char));
- tl = (char *)G_malloc(80 * sizeof(char));
+ location_elev = (char *)G_malloc(80 * sizeof(char));
math_exp = (char *)G_malloc(80 * sizeof(char));
units = (char *)G_malloc(80 * sizeof(char));
nd = (char *)G_malloc(80 * sizeof(char));
*elev_layer = 0;
*mapset_elev = 0;
- *tl = 0;
+ *location_elev = 0;
*math_exp = 0;
*units = 0;
*nd = 0;
strcpy(group, group_opt->answer);
-
- G_suppress_warnings(1);
+ if(loc_opt->answer)
+ strcpy(location_elev, loc_opt->answer);
+ if(mapset_opt->answer)
+ strcpy(mapset_elev, mapset_opt->answer);
+ if(elev_opt->answer)
+ strcpy(elev_layer, elev_opt->answer);
+ if(math_opt->answer)
+ strcpy(math_exp, math_opt->answer);
+ if(unit_opt->answer)
+ strcpy(units, unit_opt->answer);
+ if(nd_opt->answer)
+ strcpy(nd, nd_opt->answer);
+
if (!I_get_target(group, location, mapset)) {
G_fatal_error(_("Please select a target for group [%s] first"), group);
}
- G_suppress_warnings(0);
sprintf(buf, "%s/%s", G_gisdbase(), location);
if (access(buf, 0) != 0) {
G_fatal_error(_("Target location [%s] not found\n"), location);
}
if (print_flag->answer) {
- I_get_group_elev(group, elev_layer, mapset_elev, tl, math_exp, units, nd);
-
- exit(EXIT_SUCCESS);
+ if(!I_get_group_elev(group, elev_layer, mapset_elev, location_elev, math_exp, units, nd)){
+ G_fatal_error(_("Cannot find default elevation map for target in group [%s]"),group);
+ } else {
+ G_message("map:\t\t\t%s",elev_layer);
+ G_message("mapset:\t\t\t%s",mapset_elev);
+ G_message("location:\t\t%s",location_elev);
+ G_message("math expression:\t%s",math_exp);
+ G_message("units:\t\t\t%s",units);
+ G_message("nodata value:\t\t%s",nd);
+ exit(EXIT_SUCCESS);
+ }
}
-
+ /*Creating a Target environment*/
G_create_alt_env();
+ /*Set an alternate Location */
G_setenv_nogisrc("LOCATION_NAME", location);
-
+ /*Check for permissions in mapset */
stat = G_mapset_permissions(mapset);
+ /*We have permissions on the mapset */
if (stat > 0) {
+ /*Set the alternate mapset */
G_setenv_nogisrc("MAPSET", mapset);
+ /*Make an alternate search path */
G_create_alt_search_path();
+ /*Switch from current to alternate environment */
G_switch_env();
+ /*Switch to alternate search path */
G_switch_search_path();
+ /*?*/
which_env = 0;
-
+ /*Select the target environment */
select_target_env();
-
- if (list_flag->answer) {
- /* list raster maps in target location */
-
+ /*Start working on the Target mapset */
+ if (!elev_opt->answer) {
/* select current location */
select_current_env();
+ G_fatal_error(_("Elevation map name is missing. Please set '%s' option"),
+ elev_opt->key);
}
- else {
- if (!elev_opt->answer) {
- /* select current location */
- select_current_env();
- G_fatal_error(_("Elevation map name is missing. Please set '%s' option"),
- elev_opt->key);
- }
- /* elevation map exists in target ? */
-
- if (G_find_raster2(elev_opt->answer, mapset) == NULL) {
- /* select current location */
- select_current_env();
- G_fatal_error(_("Raster map <%s> not found"), elev_opt->answer);
- }
+ /* elevation map exists in target ? */
+ if (G_find_raster2(elev_opt->answer, mapset) == NULL) {
+ /* select current location */
+ select_current_env();
+ G_fatal_error(_("Raster map <%s> not found"), elev_opt->answer);
+ }
- I_get_group_elev(group, elev_layer, mapset_elev, tl, math_exp, units, nd);
- overwrite = G_getenv_nofatal("OVERWRITE") != NULL;
+ I_get_group_elev(group, elev_layer, mapset_elev, location_elev, math_exp, units, nd);
+ overwrite = G_getenv_nofatal("OVERWRITE") != NULL;
- if (!overwrite && *elev_layer) {
- G_warning(_("Elevation for group <%s> is already set to <%s>"),
- group, elev_layer);
- }
-
- I_put_group_elev(group, elev_opt->answer, mapset_elev, tl,
- math_exp, units, nd);
- /* select current location */
- select_current_env();
+ if (!overwrite && *elev_layer) {
+ G_warning(_("Elevation for group <%s> is already set to <%s>"),
+ group, elev_layer);
}
+ /*Modify ELEVATION file in source GROUP */
+ I_put_group_elev(group,elev_layer,mapset_elev,location_elev, math_exp, units, nd);
+ /* select current location */
+ select_current_env();
- exit(EXIT_SUCCESS);
+ }else{
+ G_fatal_error(_("Mapset [%s] in target location [%s] - %s "),
+ mapset, location,
+ stat == 0 ? _("permission denied\n") : _("not found\n"));
}
- G_fatal_error(_("Mapset [%s] in target location [%s] - %s "),
- mapset, location,
- stat == 0 ? _("permission denied\n") : _("not found\n"));
+ return(EXIT_SUCCESS);
}
More information about the grass-commit
mailing list