123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- /****************************************************************************
- *
- * MODULE: r.transect
- * AUTHOR(S): Michael Shapiro (CERL) (original contributor),
- * Markus Neteler <neteler itc.it>,
- * Bernhard Reiter <bernhard intevation.de>,
- * Glynn Clements <glynn gclements.plus.com>,
- * Hamish Bowman <hamish_b yahoo.com>,
- * Jan-Oliver Wagner <jan intevation.de>
- * PURPOSE: This program outputs, in ASCII, the values in a raster map
- * which lie along one or more user-defined transect lines.
- * The transects are described by their starting coordinates,
- * azimuth, and distance.
- * COPYRIGHT: (C) 1999-2006,2009 by the GRASS Development Team
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
- #include <string.h>
- #include <stdlib.h>
- #include <grass/gis.h>
- #include "local_proto.h"
- #include <grass/glocale.h>
- #include <grass/spawn.h>
- static int profile(int coords, const char *map, const char *nulls, char **line)
- {
- double e1, n1, e2, n2;
- char buf[1024], profile[1024];
- const char *argv[7];
- int argc = 0;
- int n;
- int projection;
- projection = G_projection();
- argv[argc++] = "r.profile";
- if (coords)
- argv[argc++] = "-g";
- sprintf(buf, "input=%s", map);
- argv[argc++] = G_store(buf);
- argv[argc++] = "output=-";
- sprintf(buf, "null=%s", nulls);
- argv[argc++] = G_store(buf);
- strcpy(profile, "profile=");
- for (n = 0; line[n]; n += 4) {
- int err = parse_line("line", &line[n], &e1, &n1, &e2, &n2, projection);
- if (err) {
- G_usage();
- exit(EXIT_FAILURE);
- }
- if (n > 0)
- strcat(profile, ",");
- G_format_easting(e1, buf, projection);
- strcat(profile, buf);
- G_format_northing(n1, buf, projection);
- strcat(profile, ",");
- strcat(profile, buf);
- G_format_easting(e2, buf, projection);
- strcat(profile, ",");
- strcat(profile, buf);
- G_format_northing(n2, buf, projection);
- strcat(profile, ",");
- strcat(profile, buf);
- }
- argv[argc++] = profile;
- argv[argc++] = NULL;
- G_verbose_message(_("End coordinate: %.15g, %.15g"), e2, n2);
- return G_vspawn_ex(argv[0], argv);
- }
- int main(int argc, char *argv[])
- {
- struct GModule *module;
- struct
- {
- struct Option *map;
- struct Option *line;
- struct Option *null_str;
- } parms;
- struct Flag *coord;
- G_gisinit(argv[0]);
- module = G_define_module();
- G_add_keyword(_("raster"));
- G_add_keyword(_("transect"));
- module->description =
- _("Outputs raster map layer values lying along "
- "user defined transect line(s).");
- parms.map = G_define_standard_option(G_OPT_R_MAP);
- parms.map->description = _("Raster map to be queried");
- parms.line = G_define_option();
- parms.line->key = "line";
- parms.line->key_desc = "east,north,azimuth,distance";
- parms.line->type = TYPE_STRING;
- parms.line->description = _("Transect definition");
- parms.line->required = YES;
- parms.line->multiple = YES;
- parms.null_str = G_define_standard_option(G_OPT_M_NULL_VALUE);
- parms.null_str->answer = "*";
- coord = G_define_flag();
- coord->key = 'g';
- coord->description =
- _("Output easting and northing in first two columns of four column output");
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
- return profile(coord->answer,
- parms.map->answer,
- parms.null_str->answer,
- parms.line->answers) != 0;
- }
|