/* * Difference.java * * Created on March 29, 2001, 12:16 PM */ package uk.ac.leeds.ccg.geotools.classification; import uk.ac.leeds.ccg.geotools.*; import java.util.ArrayList; /** * This classification calculates the difference between each ordered data value in the sorted list. * It then classifies the data using the binCount greatest differences to seperate the classes. * If binCount is greater than the number of different data values to assign then each different data value * is coloured uniquely and the key displays the value in [] and the number of such data values in () * if showInCatCount is true. If binCount is less than the number of different data values to assign then * categories are created and the key displays; the range of a class in [], and the number of data * values in the class in () if showInCatCount is true. * * @author jamesm * @version */ public class Difference extends uk.ac.leeds.ccg.geotools.classification.SimpleClassifier { /** Creates new Difference */ public Difference(GeoData source,int binCount) { buildBins(source,binCount); } private void buildBins(GeoData data, int binCount){ bins.clear(); Bin bin; ArrayList list = GeoDataUtils.sort(data); System.out.println("Using Difference"); System.out.println("Number of categories desired "+binCount); // (NB. list.size()=data.getSize()) System.out.println("Number of records to assign "+data.getSize()); double thisDataValue=data.getMissingValueCode(); double nextDataValue=data.getMissingValueCode(); int numberOfDifferentValues=0; for (int j=1;j<=list.size();j++){ thisDataValue=((Double)list.get(j-1)).doubleValue(); if(thisDataValue!=data.getMissingValueCode()){ if(thisDataValue!=nextDataValue){ numberOfDifferentValues=numberOfDifferentValues+1; nextDataValue=thisDataValue; } } } System.out.println("Number of different data values to assign "+numberOfDifferentValues); System.out.println("Missing value code "+data.getMissingValueCode()); System.out.println("Number of missing values "+data.getMissingCount()); System.out.println("Minimum value "+data.getMin()); System.out.println("Maximum value "+data.getMax()); // Classify missing values if(data.getMissingCount()>0)bins.add(new Bin(data.getMissingValueCode(),data.getMissingValueCode())); // Handle case where number of categories desired binCount is >= to the number of different data values to assign int counter=0; if (binCount>=numberOfDifferentValues){ int colourFactor=binCount/(list.size()-data.getMissingCount());; for(int i=1;i<=binCount;i++){ if (i>(list.size()-data.getMissingCount())){ break; } thisDataValue=((Double)list.get(i-1)).doubleValue(); counter=counter+1; if(thisDataValue!=nextDataValue){ // Because no setCat() method for controlling binCount colourFactor is used to assign sensible colours bins.add(new Bin(thisDataValue,thisDataValue)); counter=0; } nextDataValue=thisDataValue; } } else{ // Calculate the difference between values //double averageDifference=0.0; thisDataValue=((Double)list.get(0)).doubleValue(); double differences[] = new double[list.size()]; for(int i=1;ithisDataValue && nextDataValue2<=nextDataValue){ counter=counter+1; } } } catName=catName+" ("+counter+")"; } }*/ bins.add(bin); thisDataValue=nextDataValue; } } } }