/alaspatial/src/main/java/org/ala/spatial/analysis/legend/LegendEvenIntervalLog10.java

http://alageospatialportal.googlecode.com/ · Java · 45 lines · 26 code · 8 blank · 11 comment · 2 complexity · 024a85765c3a24a449d1b205ba018053 MD5 · raw file

  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package org.ala.spatial.analysis.legend;
  6. /**
  7. * generates legend with even interval cutoff's.
  8. *
  9. * @author Adam
  10. */
  11. public class LegendEvenIntervalLog10 extends Legend {
  12. @Override
  13. public void generate(float[] d, int divisions) {
  14. init(d, divisions);
  15. if(Float.isNaN(max)) {
  16. return;
  17. }
  18. //prevent negative number assignment
  19. float offset = (min<1)?1 - min:0;
  20. float tmax = max + offset;
  21. float tmin = min + offset;
  22. double lmin = Math.log10(tmin);
  23. double lmax = Math.log10(tmax);
  24. double lrange = lmax - lmin;
  25. cutoffs = new float[divisions];
  26. for(int i=0;i<divisions;i++){
  27. cutoffs[i] = (float) Math.pow(10, lmin + lrange * ((i + 1) / (double) (divisions)))
  28. - offset;
  29. }
  30. //fix max
  31. cutoffs[divisions - 1] = max;
  32. }
  33. @Override
  34. public String getTypeName() {
  35. return "Even Interval Log 10";
  36. }
  37. }