support.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /****************************************************************************
  2. *
  3. * MODULE: r.buffer
  4. *
  5. * AUTHOR(S): Michael Shapiro - CERL
  6. *
  7. * PURPOSE: This program creates distance zones from non-zero
  8. * cells in a grid layer. Distances are specified in
  9. * meters (on the command-line). Window does not have to
  10. * have square cells. Works both for planimetric
  11. * (UTM, State Plane) and lat-long.
  12. *
  13. * COPYRIGHT: (C) 2005 by the GRASS Development Team
  14. *
  15. * This program is free software under the GNU General Public
  16. * License (>=v2). Read the file COPYING that comes with GRASS
  17. * for details.
  18. *
  19. ****************************************************************************/
  20. #include "distance.h"
  21. int make_support_files(char *output, char *units)
  22. {
  23. struct Categories pcats;
  24. CELL cat;
  25. char label[128];
  26. G_init_cats((CELL) 1, "Distance Zones", &pcats);
  27. G_set_cat(cat = 1, "distances calculated from these locations", &pcats);
  28. for (cat = 0; cat < ndist; cat++) {
  29. if (cat == 0)
  30. sprintf(label, "0-%s %s", distances[cat].label, units);
  31. else {
  32. /* improved next, but it would be perfect to achieve (example):
  33. * 0-100.55 meters
  34. * 100.56-233.33 meters
  35. *
  36. *now we get:
  37. * 0-100.55 meters
  38. * 100.55-233.33 meters
  39. *
  40. *but it's better that the original code. MN 1/2002
  41. */
  42. sprintf(label, "%s-%s %s", distances[cat - 1].label,
  43. distances[cat].label, units);
  44. }
  45. G_set_cat(cat + ZONE_INCR, label, &pcats);
  46. }
  47. G_write_cats(output, &pcats);
  48. G_free_cats(&pcats);
  49. return 0;
  50. }