main.c 3.7 KB

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