dir.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <grass/gis.h>
  2. #include <grass/vector.h>
  3. #include <grass/display.h>
  4. #include <grass/glocale.h>
  5. #include "plot.h"
  6. /* arrow heads will be drawn at 25,50,75% of the line length */
  7. #define PERC_OF_LINE 25
  8. int display_dir(struct Map_info *Map, int type, struct cat_list *Clist,
  9. int chcat, int dsize)
  10. {
  11. int ltype;
  12. double len, x, y, angle, msize, dist;
  13. struct line_pnts *Points;
  14. struct line_cats *Cats;
  15. G_debug(1, "display direction:");
  16. msize = dsize * (D_d_to_u_col(2.0) - D_d_to_u_col(1.0)); /* do it better */
  17. Points = Vect_new_line_struct();
  18. Cats = Vect_new_cats_struct();
  19. Vect_rewind(Map);
  20. while (1) {
  21. ltype = Vect_read_next_line(Map, Points, Cats);
  22. switch (ltype) {
  23. case -1:
  24. G_fatal_error(_("Unable to read vector map"));
  25. case -2: /* EOF */
  26. return 0;
  27. }
  28. if (!(ltype & type))
  29. continue;
  30. if (!(ltype & (GV_LINES | GV_FACE)))
  31. continue;
  32. if (chcat) {
  33. int i, found = 0;
  34. for (i = 0; i < Cats->n_cats; i++) {
  35. if (Cats->field[i] == Clist->field &&
  36. Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
  37. found = 1;
  38. break;
  39. }
  40. }
  41. if (!found)
  42. continue;
  43. }
  44. else if (Clist->field > 0) {
  45. int i, found = 0;
  46. for (i = 0; i < Cats->n_cats; i++) {
  47. if (Cats->field[i] == Clist->field) {
  48. found = 1;
  49. break;
  50. }
  51. }
  52. /* lines with no category will be displayed */
  53. if (Cats->n_cats > 0 && !found)
  54. continue;
  55. }
  56. len = Vect_line_length(Points);
  57. for (dist = PERC_OF_LINE / 100.0; dist <= 1.0 - PERC_OF_LINE / 100.0;
  58. dist += PERC_OF_LINE / 100.0) {
  59. Vect_point_on_line(Points, len * dist, &x, &y, NULL, &angle,
  60. NULL);
  61. G_debug(4, "plot direction: %f, %f", x, y);
  62. D_plot_icon(x, y, G_ICON_ARROW, angle, msize);
  63. }
  64. }
  65. Vect_destroy_line_struct(Points);
  66. Vect_destroy_cats_struct(Cats);
  67. return 0; /* not reached */
  68. }