legend.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <grass/gis.h>
  2. #include <grass/vector.h>
  3. #include "local_proto.h"
  4. void write_into_legfile(struct Map_info *Map, int type, const char *leglab, const char *name_map, const char *icon,
  5. const char *size, const char *color, const char *fcolor, const char *width, const char *icon_area,
  6. const char *icon_line, const char *size_column)
  7. {
  8. int nfeatures;
  9. FILE *fd;
  10. char *leg_file;
  11. char map[GNAME_MAX];
  12. char *ptr;
  13. strcpy(map, name_map);
  14. strtok_r(map, "@", &ptr);
  15. if (size_column)
  16. size = "-1";
  17. /* Write into legend file */
  18. leg_file = getenv("GRASS_LEGEND_FILE");
  19. if (leg_file) {
  20. fd = fopen(leg_file, "a");
  21. /* Point */
  22. if (type & GV_POINT){
  23. nfeatures = Vect_get_num_primitives(Map, GV_POINT);
  24. if (nfeatures > 0) {
  25. if (leglab)
  26. fprintf(fd, "%s|", leglab);
  27. else
  28. fprintf(fd, "%s|", map);
  29. fprintf(fd, "%s|%s|lf|%s|%s|%s", icon, size, color, fcolor, width);
  30. fprintf(fd, "|%s|%d\n", "point", nfeatures);
  31. }
  32. }
  33. /* Line */
  34. if (type & GV_LINE){
  35. nfeatures = Vect_get_num_primitives(Map, GV_LINE);
  36. if (nfeatures > 0){
  37. if (leglab)
  38. fprintf(fd, "%s|", leglab);
  39. else
  40. fprintf(fd, "%s|", map);
  41. fprintf(fd, "%s|%s|lf|%s|%s|%s", icon_line, size, color, fcolor, width);
  42. fprintf(fd, "|%s|%d\n", "line", nfeatures);
  43. }
  44. }
  45. /* Area */
  46. if (type & GV_AREA){
  47. nfeatures = Vect_get_num_primitives(Map, GV_BOUNDARY);
  48. if (nfeatures > 0) {
  49. if (leglab)
  50. fprintf(fd, "%s|", leglab);
  51. else
  52. fprintf(fd, "%s|", map);
  53. fprintf(fd, "%s|%s|lf|%s|%s|%s", icon_area, size, color, fcolor, width);
  54. fprintf(fd, "|%s|%d\n", "area", nfeatures);
  55. }
  56. }
  57. /* Centroid */
  58. if (type & GV_CENTROID){
  59. nfeatures = Vect_get_num_primitives(Map, GV_CENTROID);
  60. if (nfeatures > 0) {
  61. if (leglab)
  62. fprintf(fd, "%s|", leglab);
  63. else
  64. fprintf(fd, "%s|", map);
  65. fprintf(fd, "%s|%s|lf|%s|%s|%s", icon, size, color, fcolor, width);
  66. fprintf(fd, "|%s|%d\n", "centroid", nfeatures);
  67. }
  68. }
  69. fclose(fd);
  70. }
  71. }