zcoor.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /* Points - no nodes registered */
  28. while (TRUE) {
  29. ltype = Vect_read_next_line(Map, Points, NULL);
  30. if (ltype == -1) {
  31. G_warning(_("Unable to read vector map"));
  32. return 1;
  33. }
  34. else if (ltype == -2) {
  35. break;
  36. }
  37. if ((ltype != GV_POINT) && (ltype & type))
  38. continue;
  39. sprintf(text, "%.2f", Points->z[0]);
  40. show_label(&Points->x[0], &Points->y[0], lattr, text);
  41. }
  42. Vect_destroy_line_struct(Points);
  43. if (Vect_level(Map) < 2) {
  44. /* no topology */
  45. return 0;
  46. }
  47. num = Vect_get_num_nodes(Map);
  48. G_debug(1, "n_nodes = %d", num);
  49. /* Nodes */
  50. for (el = 1; el <= num; el++) {
  51. if (!Vect_node_alive(Map, el))
  52. continue;
  53. Vect_get_node_coor(Map, el, &xl, &yl, &zl);
  54. G_debug(3, "node = %d", el);
  55. sprintf(text, "%.2f", zl);
  56. show_label(&xl, &yl, lattr, text);
  57. }
  58. return 0;
  59. }