main.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_option();
  46. parm.coor->key = "coor";
  47. parm.coor->key_desc = "lon1,lat1,lon2,lat2";
  48. parm.coor->type = TYPE_STRING;
  49. parm.coor->required = YES;
  50. parm.coor->description = _("Starting and ending coordinates");
  51. parm.lcolor = G_define_option();
  52. parm.lcolor->key = "lcolor";
  53. parm.lcolor->type = TYPE_STRING;
  54. parm.lcolor->required = NO;
  55. parm.lcolor->description = _("Line color");
  56. parm.lcolor->gisprompt = "old_color,color,color";
  57. parm.lcolor->answer = DEFAULT_FG_COLOR;
  58. parm.tcolor = G_define_option();
  59. parm.tcolor->key = "tcolor";
  60. parm.tcolor->type = TYPE_STRING;
  61. parm.tcolor->required = NO;
  62. parm.tcolor->description = _("Text color or \"none\"");
  63. parm.tcolor->gisprompt = "old_color,color,color";
  64. if (G_parser(argc, argv))
  65. exit(EXIT_FAILURE);
  66. if (G_projection() != PROJECTION_LL)
  67. G_fatal_error(_("Location is not %s"), G__projection_name(PROJECTION_LL));
  68. if (parm.coor->answers[0] == NULL)
  69. G_fatal_error(_("No coordinates given"));
  70. if (!G_scan_easting(parm.coor->answers[0], &lon1, G_projection()))
  71. G_fatal_error(_("%s - illegal longitude"), parm.coor->answers[0]);
  72. if (!G_scan_northing(parm.coor->answers[1], &lat1, G_projection()))
  73. G_fatal_error(_("%s - illegal longitude"), parm.coor->answers[1]);
  74. if (!G_scan_easting(parm.coor->answers[2], &lon2, G_projection()))
  75. G_fatal_error(_("%s - illegal longitude"), parm.coor->answers[2]);
  76. if (!G_scan_northing(parm.coor->answers[3], &lat2, G_projection()))
  77. G_fatal_error(_("%s - illegal longitude"), parm.coor->answers[3]);
  78. if (D_open_driver() != 0)
  79. G_fatal_error(_("No graphics device selected. "
  80. "Use d.mon to select graphics device."));
  81. line_color = D_translate_color(parm.lcolor->answer);
  82. if (!line_color)
  83. line_color = D_translate_color(parm.lcolor->answer =
  84. DEFAULT_FG_COLOR);
  85. if (strcmp(parm.lcolor->answer, DEFAULT_FG_COLOR) == 0)
  86. deftcolor = "red";
  87. else
  88. deftcolor = DEFAULT_FG_COLOR;
  89. if (parm.tcolor->answer == NULL)
  90. text_color = D_translate_color(deftcolor);
  91. else if (strcmp(parm.tcolor->answer, "none") == 0)
  92. text_color = -1;
  93. else
  94. text_color = D_translate_color(parm.tcolor->answer);
  95. plot(lon1, lat1, lon2, lat2, line_color, text_color);
  96. D_save_command(G_recreate_command());
  97. D_close_driver();
  98. exit(EXIT_SUCCESS);
  99. }