zcoor.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Print z coordinate value for each node */
  2. #include <grass/gis.h>
  3. #include <grass/vector.h>
  4. #include <grass/display.h>
  5. #include <grass/glocale.h>
  6. #include "local_proto.h"
  7. #include "plot.h"
  8. int display_zcoor(struct Map_info *Map, int type, LATTR *lattr)
  9. {
  10. int num, el, ltype;
  11. double xl, yl, zl;
  12. struct line_pnts *Points;
  13. char text[50];
  14. if (!Vect_is_3d(Map)) {
  15. G_warning(_("Vector map is not 3D. Unable to display z-coordinates."));
  16. return 1;
  17. }
  18. G_debug(1, "display zcoor:");
  19. Points = Vect_new_line_struct();
  20. D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
  21. D_text_size(lattr->size, lattr->size);
  22. if (lattr->font)
  23. D_font(lattr->font);
  24. if (lattr->enc)
  25. D_encoding(lattr->enc);
  26. Vect_rewind(Map);
  27. num = Vect_get_num_lines(Map);
  28. G_debug(1, "n_lines = %d", num);
  29. /* Points - no nodes registered */
  30. for (el = 1; el <= num; el++) {
  31. if (!Vect_line_alive(Map, el))
  32. continue;
  33. ltype = Vect_read_line(Map, Points, NULL, el);
  34. if ((ltype != GV_POINT) && (ltype & type))
  35. continue;
  36. G_debug(3, "point = %d", el);
  37. sprintf(text, "%.2f", Points->z[0]);
  38. show_label(&Points->x[0], &Points->y[0], lattr, text);
  39. }
  40. num = Vect_get_num_nodes(Map);
  41. G_debug(1, "n_nodes = %d", num);
  42. /* Nodes */
  43. for (el = 1; el <= num; el++) {
  44. if (!Vect_node_alive(Map, el))
  45. continue;
  46. Vect_get_node_coor(Map, el, &xl, &yl, &zl);
  47. G_debug(3, "node = %d", el);
  48. sprintf(text, "%.2f", zl);
  49. show_label(&xl, &yl, lattr, text);
  50. }
  51. Vect_destroy_line_struct(Points);
  52. return 0;
  53. }