plot.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #include <unistd.h>
  2. #include <grass/gis.h>
  3. #include <grass/vector.h>
  4. #include <grass/display.h>
  5. #include <grass/symbol.h>
  6. #include <grass/glocale.h>
  7. #include "vectpoints.h"
  8. #include "globals.h"
  9. #define SYM_SIZE 5
  10. #define SYM_NAME "basic/cross1"
  11. int plot(char *name, char *mapset, struct line_pnts *Points)
  12. {
  13. int line, nlines, ltype;
  14. struct Cell_head window;
  15. struct Map_info P_map;
  16. SYMBOL *Symb;
  17. RGBA_Color *linecolor_rgb, *fillcolor_rgb;
  18. struct color_rgb rgb;
  19. int ix, iy;
  20. Vect_set_open_level(2);
  21. Vect_set_fatal_error(GV_FATAL_RETURN);
  22. if (2 > Vect_open_old(&P_map, name, mapset)) {
  23. return -1;
  24. }
  25. G_get_set_window(&window);
  26. nlines = Vect_get_num_lines(&P_map);
  27. /* set line and fill color for vector point symbols */
  28. linecolor_rgb = G_malloc(sizeof(RGB_Color));
  29. fillcolor_rgb = G_malloc(sizeof(RGB_Color));
  30. rgb = G_standard_color_rgb(line_color);
  31. linecolor_rgb->r = rgb.r;
  32. linecolor_rgb->g = rgb.g;
  33. linecolor_rgb->b = rgb.b;
  34. linecolor_rgb->a = RGBA_COLOR_OPAQUE;
  35. fillcolor_rgb->a = RGBA_COLOR_NONE;
  36. for (line = 1; line <= nlines; line++) {
  37. ltype = Vect_read_line(&P_map, Points, NULL, line);
  38. if (ltype & GV_POINT) { /* GV_ singular: don't plot centroids, Points only */
  39. Symb = S_read(SYM_NAME);
  40. if (Symb == NULL) {
  41. G_warning(_("Cannot read symbol, cannot display points"));
  42. return (-1);
  43. }
  44. else
  45. S_stroke(Symb, SYM_SIZE, 0, 0);
  46. ix = (int)(D_u_to_d_col(Points->x[0]) + 0.5);
  47. iy = (int)(D_u_to_d_row(Points->y[0]) + 0.5);
  48. D_symbol(Symb, ix, iy, linecolor_rgb, fillcolor_rgb);
  49. }
  50. if (ltype & GV_LINES) { /* GV_ plural: both lines and boundaries */
  51. D_polyline(Points->x, Points->y, Points->n_points);
  52. }
  53. }
  54. Vect_close(&P_map);
  55. G_free(linecolor_rgb);
  56. G_free(fillcolor_rgb);
  57. return 0;
  58. }
  59. /* plot inverse coordinate transformation */
  60. int plot_warp(char *name, char *mapset, struct line_pnts *Points,
  61. double E[], double N[], int trans_order)
  62. {
  63. double *x, *y;
  64. int i, np;
  65. int line, nlines, ltype;
  66. struct Cell_head window;
  67. struct Map_info P_map;
  68. SYMBOL *Symb;
  69. RGBA_Color *linecolor_rgb, *fillcolor_rgb;
  70. struct color_rgb rgb;
  71. int ix, iy;
  72. Vect_set_open_level(2);
  73. Vect_set_fatal_error(GV_FATAL_RETURN);
  74. if (2 > Vect_open_old(&P_map, name, mapset)) {
  75. return -1;
  76. }
  77. G_get_set_window(&window);
  78. nlines = Vect_get_num_lines(&P_map);
  79. /* set line and fill color for vector point symbols */
  80. linecolor_rgb = G_malloc(sizeof(RGB_Color));
  81. fillcolor_rgb = G_malloc(sizeof(RGB_Color));
  82. rgb = G_standard_color_rgb(line_color);
  83. linecolor_rgb->r = rgb.r;
  84. linecolor_rgb->g = rgb.g;
  85. linecolor_rgb->b = rgb.b;
  86. linecolor_rgb->a = RGBA_COLOR_OPAQUE;
  87. fillcolor_rgb->a = RGBA_COLOR_NONE;
  88. for (line = 1; line <= nlines; line++) {
  89. ltype = Vect_read_line(&P_map, Points, NULL, line);
  90. if (ltype & GV_POINT) { /* GV_ singular: don't plot centroids, Points only */
  91. Symb = S_read(SYM_NAME);
  92. if (Symb == NULL) {
  93. G_warning(_("Cannot read symbol, cannot display points"));
  94. return (-1);
  95. }
  96. else
  97. S_stroke(Symb, SYM_SIZE, 0, 0);
  98. x = Points->x;
  99. y = Points->y;
  100. CRS_georef(x[0], y[0], &x[0], &y[0], E, N, trans_order);
  101. ix = (int)(D_u_to_d_col(x[0]) + 0.5);
  102. iy = (int)(D_u_to_d_row(y[0]) + 0.5);
  103. D_symbol(Symb, ix, iy, linecolor_rgb, fillcolor_rgb);
  104. }
  105. if (ltype & GV_LINES) { /* GV_ plural: both lines and boundaries */
  106. np = Points->n_points;
  107. x = Points->x;
  108. y = Points->y;
  109. for (i = 1; i < np; i++)
  110. CRS_georef(x[i], y[i], &x[i], &y[i], E, N, trans_order);
  111. D_polyline(x, y, np);
  112. }
  113. }
  114. Vect_close(&P_map);
  115. G_free(linecolor_rgb);
  116. G_free(fillcolor_rgb);
  117. return 0;
  118. }