main.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /****************************************************************************
  2. *
  3. * MODULE: d.geodesic
  4. * AUTHOR(S): Michael Shapiro (CERL) (original contributor)
  5. * Markus Neteler <neteler itc.it>,
  6. * Bernhard Reiter <bernhard intevation.de>,
  7. * Eric G. Miller <egm2 jps.net>,
  8. * Glynn Clements <glynn gclements.plus.com>,
  9. * Hamish Bowman <hamish_b yahoo.com>,
  10. * Jan-Oliver Wagner <jan intevation.de>
  11. * PURPOSE: displays a geodesic line in the active frame on the user's
  12. * graphics monitor
  13. * COPYRIGHT: (C) 1999-2006 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. #include <stdlib.h>
  21. #include <string.h>
  22. #include <grass/gis.h>
  23. #include <grass/display.h>
  24. #include <grass/glocale.h>
  25. #include "local_proto.h"
  26. int main(int argc, char *argv[])
  27. {
  28. int line_color;
  29. int text_color;
  30. double lon1, lat1, lon2, lat2;
  31. char *deftcolor;
  32. struct GModule *module;
  33. struct
  34. {
  35. struct Option *lcolor, *tcolor, *coor;
  36. } parm;
  37. G_gisinit(argv[0]);
  38. module = G_define_module();
  39. G_add_keyword(_("display"));
  40. G_add_keyword(_("distance"));
  41. module->description =
  42. _("Displays a geodesic line, tracing the shortest distance "
  43. "between two geographic points along a great circle, in "
  44. "a longitude/latitude data set.");
  45. parm.coor = G_define_standard_option(G_OPT_M_COORDS);
  46. parm.coor->key_desc = "lon1,lat1,lon2,lat2";
  47. parm.coor->required = YES;
  48. parm.coor->description = _("Starting and ending coordinates");
  49. parm.lcolor = G_define_standard_option(G_OPT_C_FG);
  50. parm.lcolor->key = "line_color";
  51. parm.lcolor->label = _("Line color");
  52. parm.tcolor = G_define_standard_option(G_OPT_C_FG);
  53. parm.tcolor->key = "text_color";
  54. parm.tcolor->label = _("Text color or \"none\"");
  55. parm.tcolor->answer = NULL;
  56. if (G_parser(argc, argv))
  57. exit(EXIT_FAILURE);
  58. if (G_projection() != PROJECTION_LL)
  59. G_fatal_error(_("Location is not %s"), G__projection_name(PROJECTION_LL));
  60. if (parm.coor->answers[0] == NULL)
  61. G_fatal_error(_("No coordinates given"));
  62. if (!G_scan_easting(parm.coor->answers[0], &lon1, G_projection()))
  63. G_fatal_error(_("%s - illegal longitude"), parm.coor->answers[0]);
  64. if (!G_scan_northing(parm.coor->answers[1], &lat1, G_projection()))
  65. G_fatal_error(_("%s - illegal longitude"), parm.coor->answers[1]);
  66. if (!G_scan_easting(parm.coor->answers[2], &lon2, G_projection()))
  67. G_fatal_error(_("%s - illegal longitude"), parm.coor->answers[2]);
  68. if (!G_scan_northing(parm.coor->answers[3], &lat2, G_projection()))
  69. G_fatal_error(_("%s - illegal longitude"), parm.coor->answers[3]);
  70. D_open_driver();
  71. line_color = D_translate_color(parm.lcolor->answer);
  72. if (!line_color)
  73. line_color = D_translate_color(parm.lcolor->answer =
  74. DEFAULT_FG_COLOR);
  75. if (strcmp(parm.lcolor->answer, DEFAULT_FG_COLOR) == 0)
  76. deftcolor = "red";
  77. else
  78. deftcolor = DEFAULT_FG_COLOR;
  79. if (parm.tcolor->answer == NULL)
  80. text_color = D_translate_color(deftcolor);
  81. else if (strcmp(parm.tcolor->answer, "none") == 0)
  82. text_color = -1;
  83. else
  84. text_color = D_translate_color(parm.tcolor->answer);
  85. plot(lon1, lat1, lon2, lat2, line_color, text_color);
  86. D_save_command(G_recreate_command());
  87. D_close_driver();
  88. exit(EXIT_SUCCESS);
  89. }