~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

Viewing changes to imagery/i.ortho.photo/photo.elev/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/****************************************************************************
3
 
 *
4
 
 * MODULE:       photo.elev
5
 
 * AUTHOR(S):    Mike Baba (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 the elevation model
13
 
 * COPYRIGHT:    (C) 1999-2008 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
 
/* read the target for the block and cast it into the alternate GRASS env */
22
 
#define MAIN
23
 
#include <stdlib.h>
24
 
#include <stdio.h>
25
 
#include <unistd.h>
26
 
#include <string.h>
27
 
#include <grass/gis.h>
28
 
#include <grass/imagery.h>
29
 
#include <grass/glocale.h>
30
 
#include "orthophoto.h"
31
 
#include "elev.h"
32
 
 
33
 
static int which_env;
34
 
 
35
 
char *elev_layer;
36
 
char *mapset_elev;
37
 
char *tl;
38
 
char *math_exp;
39
 
char *units;
40
 
char *nd;
41
 
 
42
 
int main(int argc, char *argv[])
43
 
{
44
 
 
45
 
    struct GModule *module;
46
 
    struct Option *group_opt;
47
 
 
48
 
    char location[GMAPSET_MAX];
49
 
    char mapset[GMAPSET_MAX];
50
 
    char group[GNAME_MAX];
51
 
 
52
 
    char buf[100];
53
 
    int stat;
54
 
 
55
 
 
56
 
    /* must run in a term window */
57
 
    G_putenv("GRASS_UI_TERM", "1");
58
 
 
59
 
    G_gisinit(argv[0]);
60
 
 
61
 
    module = G_define_module();
62
 
    module->keywords = _("imagery, orthorectify");
63
 
    module->description =
64
 
        _("Interactively select or modify the target elevation model.");
65
 
 
66
 
    group_opt = G_define_standard_option(G_OPT_I_GROUP);
67
 
    group_opt->description =
68
 
        _("Name of imagery group for ortho-rectification");
69
 
 
70
 
    if (G_parser(argc, argv))
71
 
        exit(EXIT_FAILURE);
72
 
 
73
 
    elev_layer = (char *)G_malloc(GNAME_MAX * sizeof(char));
74
 
    mapset_elev = (char *)G_malloc(GMAPSET_MAX * sizeof(char));
75
 
    tl = (char *)G_malloc(80 * sizeof(char));
76
 
    math_exp = (char *)G_malloc(80 * sizeof(char));
77
 
    units = (char *)G_malloc(80 * sizeof(char));
78
 
    nd = (char *)G_malloc(80 * sizeof(char));
79
 
 
80
 
    *elev_layer = 0;
81
 
    *mapset_elev = 0;
82
 
    *tl = 0;
83
 
    *math_exp = 0;
84
 
    *units = 0;
85
 
    *nd = 0;
86
 
 
87
 
    strcpy(group, group_opt->answer);
88
 
 
89
 
    G_suppress_warnings(1);
90
 
    if (!I_get_target(group, location, mapset)) {
91
 
        sprintf(buf, _("Target information for group [%s] missing\n"), group);
92
 
        goto error;
93
 
    }
94
 
 
95
 
    G_suppress_warnings(0);
96
 
    sprintf(buf, "%s/%s", G_gisdbase(), location);
97
 
    if (access(buf, 0) != 0) {
98
 
        sprintf(buf, _("Target location [%s] not found\n"), location);
99
 
        goto error;
100
 
    }
101
 
 
102
 
    I_get_group_elev(group, elev_layer, mapset_elev, tl, math_exp, units, nd);
103
 
    G__create_alt_env();
104
 
    G__setenv("LOCATION_NAME", location);
105
 
 
106
 
    stat = G__mapset_permissions(mapset);
107
 
    if (stat > 0) {
108
 
        G__setenv("MAPSET", mapset);
109
 
        G__create_alt_search_path();
110
 
        G__switch_env();
111
 
        G__switch_search_path();
112
 
        which_env = 0;
113
 
 
114
 
        /* get elevation layer raster map  in target location */
115
 
        select_target_env();
116
 
        ask_elev(group, location, mapset);
117
 
 
118
 
        /* select current location */
119
 
        select_current_env();
120
 
 
121
 
        I_put_group_elev(group, elev_layer, mapset_elev, tl,
122
 
                         math_exp, units, nd);
123
 
 
124
 
        exit(EXIT_SUCCESS);
125
 
    }
126
 
 
127
 
    sprintf(buf, _("Mapset [%s] in target location [%s] - "), mapset, location);
128
 
    strcat(buf, stat == 0 ? _("permission denied\n") : _("not found\n"));
129
 
 
130
 
  error:
131
 
    strcat(buf, _("Please select a target for group"));
132
 
    strcat(buf, group);
133
 
    G_suppress_warnings(0);
134
 
    G_fatal_error(buf);
135
 
}
136
 
 
137
 
 
138
 
int select_current_env(void)
139
 
{
140
 
    if (which_env != 0) {
141
 
        G__switch_env();
142
 
        G__switch_search_path();
143
 
        which_env = 0;
144
 
    }
145
 
 
146
 
    return 0;
147
 
}
148
 
 
149
 
int select_target_env(void)
150
 
{
151
 
    if (which_env != 1) {
152
 
        G__switch_env();
153
 
        G__switch_search_path();
154
 
        which_env = 1;
155
 
    }
156
 
 
157
 
    return 0;
158
 
}