main.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. module->description =
  41. _("Displays the rhumbline joining two longitude/latitude coordinates.");
  42. parm.coor = G_define_option();
  43. parm.coor->key = "coor";
  44. parm.coor->key_desc = "lon1,lat1,lon2,lat2";
  45. parm.coor->type = TYPE_STRING;
  46. parm.coor->required = YES;
  47. parm.coor->description = _("Starting and ending coordinates");
  48. parm.lcolor = G_define_option();
  49. parm.lcolor->key = "lcolor";
  50. parm.lcolor->type = TYPE_STRING;
  51. parm.lcolor->required = NO;
  52. parm.lcolor->description = _("Line color");
  53. parm.lcolor->gisprompt = "old_color,color,color";
  54. parm.lcolor->answer = DEFAULT_FG_COLOR;
  55. #ifdef CAN_DO_DISTANCES
  56. parm.tcolor = G_define_option();
  57. parm.tcolor->key = "tcolor";
  58. parm.tcolor->type = TYPE_STRING;
  59. parm.tcolor->required = NO;
  60. parm.tcolor->description = _("Text color");
  61. parm.tcolor->gisprompt = "old_color,color,color";
  62. #endif
  63. if (G_parser(argc, argv))
  64. exit(EXIT_FAILURE);
  65. if (G_projection() != PROJECTION_LL)
  66. G_fatal_error(_("Location is not %s"),
  67. 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. #ifdef CAN_DO_DISTANCES
  86. if (strcmp(parm.lcolor->answer, DEFAULT_FG_COLOR) == 0)
  87. deftcolor = "red";
  88. else
  89. deftcolor = DEFAULT_FG_COLOR;
  90. if (parm.tcolor->answer == NULL)
  91. parm.tcolor->answer = deftcolor;
  92. text_color = D_translate_color(parm.tcolor->answer);
  93. if (!text_color)
  94. text_color = D_translate_color(deftcolor);
  95. #endif
  96. plot(lon1, lat1, lon2, lat2, line_color, text_color);
  97. D_save_command(G_recreate_command());
  98. D_close_driver();
  99. exit(EXIT_SUCCESS);
  100. }