PageRenderTime 25ms CodeModel.GetById 22ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

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