1 
2 /****************************************************************************
3  *
4  * MODULE:       i.photo.target
5  * AUTHOR(S):    Mike Baba,  DBA Systems, Inc. (original contributor)
6  *               Markus Neteler <neteler itc.it>,
7  *               Roberto Flor <flor itc.it>,
8  *               Bernhard Reiter <bernhard intevation.de>,
9  *               Glynn Clements <glynn gclements.plus.com>
10  *               Hamish Bowman
11  *
12  * PURPOSE:      Select target location and mapset
13  * COPYRIGHT:    (C) 1999-2017 by the GRASS Development Team
14  *
15  *               This program is free software under the GNU General Public
16  *               License (>=v2). Read the file COPYING that comes with GRASS
17  *               for details.
18  *
19  *****************************************************************************/
20 
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <grass/gis.h>
25 #include <grass/imagery.h>
26 #include <grass/glocale.h>
27 #include "orthophoto.h"
28 
main(int argc,char * argv[])29 int main(int argc, char *argv[])
30 {
31     struct GModule *module;
32     struct Option *group_opt;
33     struct Option *location_opt;
34     struct Option *mapset_opt;
35 
36     /* current location and mapset of that group */
37     char location[GMAPSET_MAX];
38     char mapset[GMAPSET_MAX];
39     char group[GNAME_MAX];
40     /* newly defined location and maspet */
41     char target_location[GMAPSET_MAX];
42     char target_mapset[GMAPSET_MAX];
43     int stat;
44     struct Cell_head target_window;
45 
46     G_gisinit(argv[0]);
47 
48     module = G_define_module();
49     G_add_keyword(_("imagery"));
50     G_add_keyword(_("orthorectify"));
51     module->description =
52 	_("Select or modify the imagery group target.");
53 
54     group_opt = G_define_standard_option(G_OPT_I_GROUP);
55     group_opt->description =
56 	_("Name of imagery group for ortho-rectification");
57 
58     location_opt = G_define_standard_option(G_OPT_M_LOCATION);
59     location_opt->key = "target_location";
60     location_opt->required = YES;
61     location_opt->description =
62 	_("Name of target location for ortho-rectification");
63 
64     mapset_opt = G_define_standard_option(G_OPT_M_MAPSET);
65     mapset_opt->key = "mapset_location";
66     mapset_opt->required = YES;
67     mapset_opt->description =
68 	_("Name of target mapset for ortho-rectification");
69 
70     if (G_parser(argc, argv))
71 	exit(EXIT_FAILURE);
72 
73 
74     strcpy(group, group_opt->answer);
75     strcpy(target_location, location_opt->answer);
76     strcpy(target_mapset, mapset_opt->answer);
77 
78     I_get_target(group, location, mapset);
79     G_create_alt_env();
80     G_setenv_nogisrc("LOCATION_NAME", target_location);
81     stat = G_mapset_permissions(target_mapset);
82     if (stat != 1) {
83 	G_fatal_error(_("Unable to access target location/mapset %s/%s"),
84 	              target_location, target_mapset);
85     }
86 
87     G_setenv_nogisrc("MAPSET", target_mapset);
88     G_get_window(&target_window);
89     if (target_window.proj == PROJECTION_XY)
90 	G_fatal_error(_("Target locations with XY (unreferenced) are not supported"));
91     else if (target_window.proj == PROJECTION_LL)
92 	G_fatal_error(_("Target locations with lon/lat are not supported"));
93 
94     G_switch_env();
95     I_put_target(group, target_location, target_mapset);
96 
97     G_message(_("Group [%s] targeted for location [%s], mapset [%s]"),
98 	    group, target_location, target_mapset);
99 
100     exit(EXIT_SUCCESS);
101 }
102