support.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 <grass/raster.h>
  21. #include "distance.h"
  22. int make_support_files(char *output, char *units)
  23. {
  24. struct Categories pcats;
  25. int i;
  26. CELL cat;
  27. char label[128];
  28. Rast_init_cats("Distance Zones", &pcats);
  29. cat = 1;
  30. Rast_set_c_cat(&cat, &cat, "distances calculated from these locations", &pcats);
  31. for (i = 0; i < ndist; i++) {
  32. if (i == 0)
  33. sprintf(label, "0-%s %s", distances[i].label, units);
  34. else {
  35. /* improved next, but it would be perfect to achieve (example):
  36. * 0-100.55 meters
  37. * 100.56-233.33 meters
  38. *
  39. *now we get:
  40. * 0-100.55 meters
  41. * 100.55-233.33 meters
  42. *
  43. *but it's better that the original code. MN 1/2002
  44. */
  45. sprintf(label, "%s-%s %s", distances[i - 1].label,
  46. distances[i].label, units);
  47. }
  48. cat = i + ZONE_INCR;
  49. Rast_set_c_cat(&cat, &cat, label, &pcats);
  50. }
  51. Rast_write_cats(output, &pcats);
  52. Rast_free_cats(&pcats);
  53. return 0;
  54. }