main.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /****************************************************************************
  2. *
  3. * MODULE: r.transect
  4. * AUTHOR(S): Michael Shapiro (CERL) (original contributor),
  5. * Markus Neteler <neteler itc.it>,
  6. * Bernhard Reiter <bernhard intevation.de>,
  7. * Glynn Clements <glynn gclements.plus.com>,
  8. * Hamish Bowman <hamish_b yahoo.com>,
  9. * Jan-Oliver Wagner <jan intevation.de>
  10. * PURPOSE: This program outputs, in ASCII, the values in a raster map
  11. * which lie along one or more user-defined transect lines.
  12. * The transects are described by their starting coordinates,
  13. * azimuth, and distance.
  14. * COPYRIGHT: (C) 1999-2006,2009 by the GRASS Development Team
  15. *
  16. * This program is free software under the GNU General Public
  17. * License (>=v2). Read the file COPYING that comes with GRASS
  18. * for details.
  19. *
  20. *****************************************************************************/
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <grass/gis.h>
  24. #include "local_proto.h"
  25. #include <grass/glocale.h>
  26. #include <grass/spawn.h>
  27. static int profile(int coords, const char *map, const char *nulls, char **line)
  28. {
  29. double e1, n1, e2, n2;
  30. char buf[1024], profile[1024];
  31. const char *argv[7];
  32. int argc = 0;
  33. int n;
  34. int projection;
  35. projection = G_projection();
  36. argv[argc++] = "r.profile";
  37. if (coords)
  38. argv[argc++] = "-g";
  39. sprintf(buf, "input=%s", map);
  40. argv[argc++] = G_store(buf);
  41. argv[argc++] = "output=-";
  42. sprintf(buf, "null=%s", nulls);
  43. argv[argc++] = G_store(buf);
  44. strcpy(profile, "profile=");
  45. for (n = 0; line[n]; n += 4) {
  46. int err = parse_line("line", &line[n], &e1, &n1, &e2, &n2, projection);
  47. if (err) {
  48. G_usage();
  49. exit(EXIT_FAILURE);
  50. }
  51. if (n > 0)
  52. strcat(profile, ",");
  53. G_format_easting(e1, buf, projection);
  54. strcat(profile, buf);
  55. G_format_northing(n1, buf, projection);
  56. strcat(profile, ",");
  57. strcat(profile, buf);
  58. G_format_easting(e2, buf, projection);
  59. strcat(profile, ",");
  60. strcat(profile, buf);
  61. G_format_northing(n2, buf, projection);
  62. strcat(profile, ",");
  63. strcat(profile, buf);
  64. }
  65. argv[argc++] = profile;
  66. argv[argc++] = NULL;
  67. G_verbose_message(_("End coordinate: %.15g, %.15g"), e2, n2);
  68. return G_vspawn_ex(argv[0], argv);
  69. }
  70. int main(int argc, char *argv[])
  71. {
  72. struct GModule *module;
  73. struct
  74. {
  75. struct Option *map;
  76. struct Option *line;
  77. struct Option *null_str;
  78. } parms;
  79. struct Flag *coord;
  80. G_gisinit(argv[0]);
  81. module = G_define_module();
  82. G_add_keyword(_("raster"));
  83. G_add_keyword(_("transect"));
  84. module->description =
  85. _("Outputs raster map layer values lying along "
  86. "user defined transect line(s).");
  87. parms.map = G_define_standard_option(G_OPT_R_MAP);
  88. parms.map->description = _("Raster map to be queried");
  89. parms.line = G_define_option();
  90. parms.line->key = "line";
  91. parms.line->key_desc = "east,north,azimuth,distance";
  92. parms.line->type = TYPE_STRING;
  93. parms.line->description = _("Transect definition");
  94. parms.line->required = YES;
  95. parms.line->multiple = YES;
  96. parms.null_str = G_define_standard_option(G_OPT_M_NULL_VALUE);
  97. parms.null_str->answer = "*";
  98. coord = G_define_flag();
  99. coord->key = 'g';
  100. coord->description =
  101. _("Output easting and northing in first two columns of four column output");
  102. if (G_parser(argc, argv))
  103. exit(EXIT_FAILURE);
  104. return profile(coord->answer,
  105. parms.map->answer,
  106. parms.null_str->answer,
  107. parms.line->answers) != 0;
  108. }