get_range.c 495 B

123456789101112131415161718192021222324252627
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. int get_range(struct Cell_stats *statf, CELL * min, CELL * max, int zero)
  4. {
  5. long count;
  6. int any;
  7. CELL cat;
  8. any = *min = *max = 0;
  9. Rast_rewind_cell_stats(statf);
  10. while (!any && Rast_next_cell_stat(&cat, &count, statf)) {
  11. if (zero || cat)
  12. any = 1;
  13. }
  14. if (!any)
  15. return 0;
  16. *min = *max = cat;
  17. while (Rast_next_cell_stat(&cat, &count, statf)) {
  18. if (zero || cat)
  19. *max = cat;
  20. }
  21. return 1;
  22. }