main.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /****************************************************************************
  2. *
  3. * MODULE: d.rhumbline
  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 the rhumbline joining two user-specified points
  12. * COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
  13. *
  14. * This program is free software under the GNU General Public
  15. * License (>=v2). Read the file COPYING that comes with GRASS
  16. * for details.
  17. *
  18. *****************************************************************************/
  19. /* TODO: implement G_rhumbline_distance() in libgis
  20. */
  21. #include <stdlib.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 = 0;
  30. double lon1, lat1, lon2, lat2;
  31. struct GModule *module;
  32. struct
  33. {
  34. struct Option *lcolor, *tcolor, *coor;
  35. } parm;
  36. G_gisinit(argv[0]);
  37. module = G_define_module();
  38. G_add_keyword(_("display"));
  39. G_add_keyword(_("distance"));
  40. G_add_keyword(_("rhumbline"));
  41. module->description =
  42. _("Displays the rhumbline joining two longitude/latitude coordinates.");
  43. parm.coor = G_define_standard_option(G_OPT_M_COORDS);
  44. parm.coor->key_desc = "lon1,lat1,lon2,lat2";
  45. parm.coor->required = YES;
  46. parm.coor->description = _("Starting and ending coordinates");
  47. parm.lcolor = G_define_standard_option(G_OPT_C_FG);
  48. parm.lcolor->key = "line_color";
  49. parm.lcolor->label = _("Line color");
  50. #ifdef CAN_DO_DISTANCES
  51. parm.tcolor = G_define_option(G_OPT_M_COORDS);
  52. parm.tcolor->key = "text_color";
  53. parm.tcolor->label = _("Text color");
  54. #endif
  55. if (G_parser(argc, argv))
  56. exit(EXIT_FAILURE);
  57. if (G_projection() != PROJECTION_LL)
  58. G_fatal_error(_("Location is not %s"),
  59. 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. if (D_open_driver() != 0)
  71. G_fatal_error(_("No graphics device selected. "
  72. "Use d.mon to select graphics device."));
  73. line_color = D_translate_color(parm.lcolor->answer);
  74. if (!line_color)
  75. line_color = D_translate_color(parm.lcolor->answer =
  76. DEFAULT_FG_COLOR);
  77. #ifdef CAN_DO_DISTANCES
  78. if (strcmp(parm.lcolor->answer, DEFAULT_FG_COLOR) == 0)
  79. deftcolor = "red";
  80. else
  81. deftcolor = DEFAULT_FG_COLOR;
  82. if (parm.tcolor->answer == NULL)
  83. parm.tcolor->answer = deftcolor;
  84. text_color = D_translate_color(parm.tcolor->answer);
  85. if (!text_color)
  86. text_color = D_translate_color(deftcolor);
  87. #endif
  88. plot(lon1, lat1, lon2, lat2, line_color, text_color);
  89. D_save_command(G_recreate_command());
  90. D_close_driver();
  91. exit(EXIT_SUCCESS);
  92. }