ClassBreaksOpImage extends StatisticsOpImage { @Override public Object getProperty(String name) { Object obj = properties.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); if (obj == Image.UndefinedProperty) { Classification c = preCalculate(); if (c != null) { properties.setProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY, c); } } return super.getProperty(name); } ClassBreaksOpImage(
            RenderedImage image,
            Integer numClasses,
            Double[][] extrema,
            ROI roi,
            Integer[] bands,
            Integer xStart,
            Integer yStart,
            Integer xPeriod,
            Integer yPeriod,
            Double noData,
            Boolean percentages); @Override Object getProperty(String name); @Override void setProperty(String name, Object value);  }
@Test public void getMissingProperty() { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.QUANTILE); pb.setParameter("numClasses", 5); RenderedImage op = new ClassBreaksRIF().create(pb, null); Object roi = op.getProperty("ROI"); assertEquals(Image.UndefinedProperty, roi); }
@Test public void testEqualInterval() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.EQUAL_INTERVAL); pb.setParameter("numClasses", 4); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); Number[] breaks = classification.getBreaks()[0]; assertEquals(5, breaks.length); assertEquals(1, breaks[0].doubleValue(), EPS); assertEquals(14, breaks[1].doubleValue(), EPS); assertEquals(27, breaks[2].doubleValue(), EPS); assertEquals(40, breaks[3].doubleValue(), EPS); assertEquals(53, breaks[4].doubleValue(), EPS); }
@Test public void testQuantileBreaks() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.QUANTILE); pb.setParameter("numClasses", 4); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); Number[] breaks = classification.getBreaks()[0]; assertEquals(5, breaks.length); assertEquals(1, breaks[0].doubleValue(), EPS); assertEquals(3, breaks[1].doubleValue(), EPS); assertEquals(11, breaks[2].doubleValue(), EPS); assertEquals(26, breaks[3].doubleValue(), EPS); assertEquals(53, breaks[4].doubleValue(), EPS); }
@Test public void testQuantileBreaksHistogram() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.QUANTILE); pb.setParameter("numClasses", 4); pb.setParameter("extrema", getExtrema(image)); pb.setParameter("histogram", true); pb.setParameter("histogramBins", 100); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); Number[] breaks = classification.getBreaks()[0]; assertEquals(5, breaks.length); assertEquals(1, breaks[0].doubleValue(), EPS); assertEquals(8, breaks[1].doubleValue(), EPS); assertEquals(11, breaks[2].doubleValue(), EPS); assertEquals(26, breaks[3].doubleValue(), EPS); assertEquals(53, breaks[4].doubleValue(), EPS); }
@Test public void testNaturalBreaks() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.NATURAL_BREAKS); pb.setParameter("numClasses", 4); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); Number[] breaks = classification.getBreaks()[0]; assertEquals(5, breaks.length); assertEquals(1, breaks[0].doubleValue(), EPS); assertEquals(3, breaks[1].doubleValue(), EPS); assertEquals(16, breaks[2].doubleValue(), EPS); assertEquals(26, breaks[3].doubleValue(), EPS); assertEquals(53, breaks[4].doubleValue(), EPS); }
@Test public void testNaturalBreaksHistogram() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.NATURAL_BREAKS); pb.setParameter("numClasses", 4); pb.setParameter("extrema", getExtrema(image)); pb.setParameter("histogram", true); pb.setParameter("histogramBins", 100); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); Number[] breaks = classification.getBreaks()[0]; assertEquals(5, breaks.length); assertEquals(1, breaks[0].doubleValue(), EPS); assertEquals(3, breaks[1].doubleValue(), EPS); assertEquals(16, breaks[2].doubleValue(), EPS); assertEquals(26, breaks[3].doubleValue(), EPS); assertEquals(53, breaks[4].doubleValue(), EPS); }
@Test public void testNaturalBreaksWithPercentages() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.NATURAL_BREAKS); pb.setParameter("numClasses", 4); pb.setParameter("percentages",true); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); double[] percentages = classification.getPercentages(); assertEquals(4, percentages.length); assertTrue(percentages[0]==18.75); assertTrue(percentages[1]==43.75); assertTrue(percentages[2]==12.5); assertTrue(percentages[3]==25.0); }
@Test public void testNaturalBreaksHistogramWithPercentages() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.NATURAL_BREAKS); pb.setParameter("numClasses", 4); pb.setParameter("extrema", getExtrema(image)); pb.setParameter("histogram", true); pb.setParameter("histogramBins", 4); pb.setParameter("percentages",true); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); double[] percentages = classification.getPercentages(); assertEquals(3, percentages.length); assertTrue(Math.floor(percentages[0])==56.0); assertTrue(percentages[1]==31.25); assertTrue(percentages[2]==12.5); }
@Test public void testNaturalBreaksWithPercentagesMoreClassesThanIntervals() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.NATURAL_BREAKS); pb.setParameter("numClasses", 11); pb.setParameter("extrema", getExtrema(image)); pb.setParameter("histogram", true); pb.setParameter("histogramBins", 100); pb.setParameter("percentages",true); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); double[] percentages = classification.getPercentages(); assertEquals(6, percentages.length); assertTrue(percentages[0]==12.5); assertTrue(percentages[1]==18.75); assertTrue(percentages[2]==18.75); assertTrue(percentages[3]==12.5); assertTrue(percentages[4]==12.5); assertTrue(percentages[5]==25.0); }
@Test public void testNaturalBreaksHistogramWithPercentagesMoreClassesThanIntervals() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.NATURAL_BREAKS); pb.setParameter("numClasses", 11); pb.setParameter("extrema", getExtrema(image)); pb.setParameter("histogram", true); pb.setParameter("histogramBins", 100); pb.setParameter("percentages",true); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); double[] percentages = classification.getPercentages(); assertEquals(6, percentages.length); assertTrue(percentages[0]==12.5); assertTrue(percentages[1]==18.75); assertTrue(percentages[2]==18.75); assertTrue(percentages[3]==12.5); assertTrue(percentages[4]==12.5); assertTrue(percentages[5]==25.0); }
@Test public void testQuantileBreaksWithPercentages() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.QUANTILE); pb.setParameter("numClasses", 4); pb.setParameter("percentages",true); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); double[] percentages = classification.getPercentages(); assertEquals(percentages.length, 4); assertTrue(percentages[0]== 18.75); assertTrue(percentages[1]== 31.25); assertTrue(percentages[2]== 25.0); assertTrue(percentages[3]== 25.0); }
@Test public void testQuantileBreaksPercentagesMoreClassesThaIntervals(){ RenderedImage image = ImageUtilities.createImageFromArray( new Number[] {1,1,1,1,1,1,1,1,8,8,8,8,3,3,3,3}, 4, 4); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.QUANTILE); pb.setParameter("numClasses", 5); pb.setParameter("percentages",true); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); double[] percentages = classification.getPercentages(); assertEquals(percentages.length, 2); assertTrue(percentages[0]==50.0); assertTrue(percentages[1]==50.0); }
@Test public void testQuantileBreaksHistogramWithPercentages() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.QUANTILE); pb.setParameter("numClasses", 4); pb.setParameter("extrema", getExtrema(image)); pb.setParameter("histogram", true); pb.setParameter("histogramBins", 100); pb.setParameter("percentages",true); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); double[] percentages = classification.getPercentages(); assertEquals(percentages.length, 4); assertTrue(percentages[0]== 31.25); assertTrue(percentages[1]== 18.75); assertTrue(percentages[2]== 25.0); assertTrue(percentages[3]== 25.0); }
@Test public void testQuantileBreaksHistogramsPercentagesMoreClassesThaIntervals(){ RenderedImage image2 = ImageUtilities.createImageFromArray( new Number[] {1,1,1,1,1,1,1,1,8,8,8,8,11,11,11,16}, 4, 4); ParameterBlockJAI pb2 = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb2.addSource(image2); pb2.setParameter("method", ClassificationMethod.QUANTILE); pb2.setParameter("numClasses", 5); pb2.setParameter("extrema", getExtrema(image2)); pb2.setParameter("histogram", true); pb2.setParameter("histogramBins", 100); pb2.setParameter("percentages",true); RenderedImage op2 = JAI.create("ClassBreaks", pb2, null); Classification classification2 = (Classification) op2.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification2); double[] percentages2 = classification2.getPercentages(); assertEquals(percentages2.length, 3); assertTrue(percentages2[0]==50.0); assertTrue(percentages2[1]==25.0); assertTrue(percentages2[2]==25.0); }
@Test public void testEqualIntervalBreaksWithPercentages() throws Exception { RenderedImage image = createImage(); ParameterBlockJAI pb = new ParameterBlockJAI(new ClassBreaksDescriptor()); pb.addSource(image); pb.setParameter("method", ClassificationMethod.EQUAL_INTERVAL); pb.setParameter("numClasses", 4); pb.setParameter("percentages",true); RenderedImage op = JAI.create("ClassBreaks", pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); double[] percentages = classification.getPercentages(); assertEquals(percentages.length, 4); assertTrue(percentages[0]== 56.25); assertTrue(percentages[1]== 31.25); assertTrue(percentages[2]== 0.0); assertTrue(percentages[3]== 12.5); }
@Test public void testCreatesOperationDirectlyFromClassBreaksRIF() throws Exception { RenderedImage image = createImage(); ParameterBlock pb = new ParameterBlock(); pb.addSource(image); pb.set(4, 0); pb.set(ClassificationMethod.NATURAL_BREAKS, 1); pb.set(null, 2); pb.set(null, 3); pb.set(new Integer[] {0}, 4); pb.set(1, 5); pb.set(1, 6); pb.set(0.0, 7); RenderedImage op = new ClassBreaksRIF().create(pb, null); Classification classification = (Classification) op.getProperty(ClassBreaksDescriptor.CLASSIFICATION_PROPERTY); assertNotNull(classification); Number[] breaks = classification.getBreaks()[0]; assertEquals(5, breaks.length); assertEquals(1, breaks[0].doubleValue(), EPS); assertEquals(3, breaks[1].doubleValue(), EPS); assertEquals(16, breaks[2].doubleValue(), EPS); assertEquals(26, breaks[3].doubleValue(), EPS); assertEquals(53, breaks[4].doubleValue(), EPS); }