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

« back to all changes in this revision

Viewing changes to raster/r.proj.seg/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:
87
87
      row, col,                 /* counters                     */
88
88
      irows, icols,             /* original rows, cols          */
89
89
      orows, ocols, have_colors,        /* Input map has a colour table */
90
 
      overwrite;                /* Overwrite                    */
 
90
      overwrite,                /* Overwrite                    */
 
91
      curr_proj;                /* output projection (see gis.h) */
91
92
 
92
93
    void *obuffer,              /* buffer that holds one output row     */
93
94
     *obufptr;                  /* column ptr in output buffer  */
100
101
      row_idx,                  /* row index in input matrix    */
101
102
      onorth, osouth,           /* save original border coords  */
102
103
      oeast, owest, inorth, isouth, ieast, iwest;
 
104
    char north_str[30], south_str[30], east_str[30], west_str[30];
103
105
 
104
106
    struct Colors colr;         /* Input map colour table       */
105
107
    struct History history;
114
116
    struct GModule *module;
115
117
 
116
118
    struct Flag *list,          /* list files in source location */
117
 
     *nocrop;                   /* don't crop output map        */
 
119
     *nocrop,                   /* don't crop output map        */
 
120
     *print_bounds,             /* print output bounds and exit */
 
121
     *gprint_bounds;            /* same but print shell style   */
118
122
 
119
123
    struct Option *imapset,     /* name of input mapset         */
120
124
     *inmap,                    /* name of input layer          */
132
136
    G_gisinit(argv[0]);
133
137
 
134
138
    module = G_define_module();
135
 
    module->keywords = _("raster, projection");
136
 
    module->description =
 
139
    module->keywords = _("raster, projection, transformation");
 
140
     module->description =
137
141
        _("Re-projects a raster map from one location to the current location.");
138
142
 
139
143
    inmap = G_define_standard_option(G_OPT_R_INPUT);
140
144
    inmap->description = _("Name of input raster map to re-project");
141
145
    inmap->required = NO;
142
 
 
 
146
    inmap->guisection = _("Source");
 
147
    
143
148
    inlocation = G_define_option();
144
149
    inlocation->key = "location";
145
150
    inlocation->type = TYPE_STRING;
146
151
    inlocation->required = YES;
147
 
    inlocation->description = _("Location of input raster map");
 
152
    inlocation->description = _("Location containing input raster map");
 
153
    inlocation->gisprompt = "old,location,location";
 
154
    inlocation->key_desc = "name";
148
155
 
149
156
    imapset = G_define_option();
150
157
    imapset->key = "mapset";
151
158
    imapset->type = TYPE_STRING;
152
159
    imapset->required = NO;
153
 
    imapset->description = _("Mapset of input raster map");
 
160
    imapset->description = _("Mapset containing input raster map");
 
161
    imapset->gisprompt = "old,mapset,mapset";
 
162
    imapset->key_desc = "name";
 
163
    imapset->guisection = _("Source");
154
164
 
155
165
    indbase = G_define_option();
156
166
    indbase->key = "dbase";
157
167
    indbase->type = TYPE_STRING;
158
168
    indbase->required = NO;
159
169
    indbase->description = _("Path to GRASS database of input location");
 
170
    indbase->gisprompt = "old,dbase,dbase";
 
171
    indbase->key_desc = "path";
 
172
    indbase->guisection = _("Source");
160
173
 
161
174
    outmap = G_define_standard_option(G_OPT_R_OUTPUT);
162
175
    outmap->required = NO;
163
176
    outmap->description = _("Name for output raster map (default: input)");
164
 
 
 
177
    outmap->guisection = _("Target");
 
178
    
165
179
    ipolname = make_ipol_list();
166
180
 
167
181
    interpol = G_define_option();
171
185
    interpol->answer = "nearest";
172
186
    interpol->options = ipolname;
173
187
    interpol->description = _("Interpolation method to use");
 
188
    interpol->guisection = _("Target");
174
189
 
175
190
    memory = G_define_option();
176
191
    memory->key = "memory";
183
198
    res->type = TYPE_DOUBLE;
184
199
    res->required = NO;
185
200
    res->description = _("Resolution of output map");
 
201
    res->guisection = _("Target");
186
202
 
187
203
    list = G_define_flag();
188
204
    list->key = 'l';
192
208
    nocrop->key = 'n';
193
209
    nocrop->description = _("Do not perform region cropping optimization");
194
210
 
 
211
    print_bounds = G_define_flag();
 
212
    print_bounds->key = 'p';
 
213
    print_bounds->description =
 
214
        _("Print input map's bounds in the current projection and exit");
 
215
    print_bounds->guisection = _("Target");
 
216
    
 
217
    gprint_bounds = G_define_flag();
 
218
    gprint_bounds->key = 'g';
 
219
    gprint_bounds->description =
 
220
        _("Print input map's bounds in the current projection and exit (shell style)");
 
221
    gprint_bounds->guisection = _("Target");
 
222
 
195
223
    /* The parser checks if the map already exists in current mapset,
196
224
       we switch out the check and do it
197
225
       in the module after the parser */
200
228
    if (G_parser(argc, argv))
201
229
        exit(EXIT_FAILURE);
202
230
 
 
231
 
203
232
    /* get the method */
204
233
    for (method = 0; (ipolname = menu[method].name); method++)
205
234
        if (strcmp(ipolname, interpol->answer) == 0)
216
245
        G_fatal_error(_("option <%s>: <%s> exists."), "output", mapname);
217
246
 
218
247
    setname = imapset->answer ? imapset->answer : G_store(G_mapset());
219
 
 
220
 
    if (strcmp(inlocation->answer, G_location()) == 0)
221
 
        G_fatal_error(_("You have to use a different location for input than the current"));
222
 
 
 
248
    if (strcmp(inlocation->answer, G_location()) == 0 &&
 
249
        (!indbase->answer || strcmp(indbase->answer, G_gisdbase()) == 0))
 
250
#if 0
 
251
        G_fatal_error(_("Input and output locations can not be the same"));
 
252
#else
 
253
        G_warning(_("Input and output locations are the same"));
 
254
#endif
223
255
    G_get_window(&outcellhd);
224
256
 
 
257
    if(gprint_bounds->answer && !print_bounds->answer)
 
258
        print_bounds->answer = gprint_bounds->answer;
 
259
    curr_proj = G_projection();
 
260
 
225
261
    /* Get projection info for output mapset */
226
262
    if ((out_proj_info = G_get_projinfo()) == NULL)
227
263
        G_fatal_error(_("Unable to get projection info of output raster map"));
246
282
 
247
283
    /* if requested, list the raster maps in source location - MN 5/2001 */
248
284
    if (list->answer) {
249
 
        if (isatty(0))          /* check if on command line */
250
 
            G_message(_("Checking location <%s>, mapset <%s>..."),
251
 
                      inlocation->answer, setname);
252
 
        G_list_element("cell", "raster", setname, 0);
253
 
        exit(EXIT_SUCCESS);     /* leave r.proj after listing */
 
285
        int i;
 
286
        char **list;
 
287
        G_verbose_message(_("Checking location <%s> mapset <%s>"),
 
288
                          inlocation->answer, imapset->answer);
 
289
        list = G_list(G_ELEMENT_RASTER, G__getenv("GISDBASE"),
 
290
                      G__getenv("LOCATION_NAME"), imapset->answer);
 
291
        for (i = 0; list[i]; i++) {
 
292
            fprintf(stdout, "%s\n", list[i]);
 
293
        }
 
294
        fflush(stdout);
 
295
        exit(EXIT_SUCCESS);     /* leave v.proj after listing */
254
296
    }
255
297
 
256
298
    if (!inmap->answer)
302
344
    orows = outcellhd.rows;
303
345
    ocols = outcellhd.cols;
304
346
 
 
347
 
 
348
    if (print_bounds->answer) {
 
349
        G_message(_("Input map <%s@%s> in location <%s>:"),
 
350
            inmap->answer, setname, inlocation->answer);
 
351
 
 
352
        if (pj_do_proj(&iwest, &isouth, &iproj, &oproj) < 0)
 
353
            G_fatal_error(_("Error in pj_do_proj (projection of input coordinate pair)"));
 
354
        if (pj_do_proj(&ieast, &inorth, &iproj, &oproj) < 0)
 
355
            G_fatal_error(_("Error in pj_do_proj (projection of input coordinate pair)"));
 
356
 
 
357
        G_format_northing(inorth, north_str, curr_proj);
 
358
        G_format_northing(isouth, south_str, curr_proj);
 
359
        G_format_easting(ieast, east_str, curr_proj);
 
360
        G_format_easting(iwest, west_str, curr_proj);
 
361
 
 
362
        if(gprint_bounds->answer) {
 
363
            fprintf(stdout, "n=%s s=%s w=%s e=%s rows=%d cols=%d\n",
 
364
                north_str, south_str, west_str, east_str, irows, icols);
 
365
        }
 
366
        else {
 
367
            fprintf(stdout, "Source cols: %d\n", icols);
 
368
            fprintf(stdout, "Source rows: %d\n", irows);
 
369
            fprintf(stdout, "Local north: %s\n",  north_str);
 
370
            fprintf(stdout, "Local south: %s\n", south_str);
 
371
            fprintf(stdout, "Local west: %s\n", west_str);
 
372
            fprintf(stdout, "Local east: %s\n", east_str);
 
373
        }
 
374
 
 
375
        /* somehow approximate local ewres, nsres ?? (use 'g.region -m' on lat/lon side) */
 
376
 
 
377
        exit(EXIT_SUCCESS);
 
378
    }
 
379
 
 
380
 
305
381
    /* Cut non-overlapping parts of input map */
306
382
    if (!nocrop->answer)
307
383
        bordwalk(&outcellhd, &incellhd, &oproj, &iproj);
358
434
    G_adjust_Cell_head(&outcellhd, 0, 0);
359
435
    G_set_window(&outcellhd);
360
436
 
361
 
    G_message("");
 
437
    G_message(" ");
362
438
    G_message(_("Input:"));
363
439
    G_message(_("Cols: %d (%d)"), incellhd.cols, icols);
364
440
    G_message(_("Rows: %d (%d)"), incellhd.rows, irows);
368
444
    G_message(_("East: %f (%f)"), incellhd.east, ieast);
369
445
    G_message(_("EW-res: %f"), incellhd.ew_res);
370
446
    G_message(_("NS-res: %f"), incellhd.ns_res);
371
 
    G_message("");
372
447
 
 
448
    G_message(" ");
373
449
    G_message(_("Output:"));
374
450
    G_message(_("Cols: %d (%d)"), outcellhd.cols, ocols);
375
451
    G_message(_("Rows: %d (%d)"), outcellhd.rows, orows);
379
455
    G_message(_("East: %f (%f)"), outcellhd.east, oeast);
380
456
    G_message(_("EW-res: %f"), outcellhd.ew_res);
381
457
    G_message(_("NS-res: %f"), outcellhd.ns_res);
382
 
    G_message("");
 
458
    G_message(" ");
383
459
 
384
460
    /* open and read the relevant parts of the input map and close it */
385
461
    G__switch_env();