Search in sources :

Example 1 with Interpolate

use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.

the class StyleCacheTest method GraphicCacheTest.

@Test
public void GraphicCacheTest() throws Exception {
    // Test a complex graphic
    final Expression Lookup = FF.property("POP_CNTRY");
    final List<InterpolationPoint> values = new ArrayList<InterpolationPoint>();
    // test color interpolation ---------------------------------------------
    values.clear();
    values.add(new DefaultInterpolationPoint(0d, FF.literal(3d)));
    values.add(new DefaultInterpolationPoint(500000000d, FF.literal(50d)));
    Interpolate interpolate = new DefaultInterpolate(Lookup, values, Method.COLOR, Mode.CUBIC, null);
    List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
    symbols.add(SF.mark(StyleConstants.MARK_CIRCLE, SF.fill(Color.RED), SF.stroke()));
    Graphic graphic = SF.graphic(symbols, StyleConstants.DEFAULT_GRAPHIC_OPACITY, interpolate, StyleConstants.DEFAULT_GRAPHIC_ROTATION, StyleConstants.DEFAULT_ANCHOR_POINT, StyleConstants.DEFAULT_DISPLACEMENT);
    CachedGraphic cached = CachedGraphic.cache(graphic);
    assertFalse(cached.isStatic());
    assertEquals(VisibilityState.DYNAMIC, cached.isStaticVisible());
}
Also used : DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) DefaultInterpolate(org.geotoolkit.style.function.DefaultInterpolate) Interpolate(org.geotoolkit.style.function.Interpolate) CachedGraphic(org.geotoolkit.display2d.style.CachedGraphic) Expression(org.opengis.filter.Expression) Graphic(org.opengis.style.Graphic) CachedGraphic(org.geotoolkit.display2d.style.CachedGraphic) ExternalGraphic(org.opengis.style.ExternalGraphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) DefaultInterpolate(org.geotoolkit.style.function.DefaultInterpolate) DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) Test(org.junit.Test)

Example 2 with Interpolate

use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.

the class SEforSLD110Test method testFillInterpolation.

// //////////////////////////////////////////////////////////////////////////
// JAXB TEST UNMARSHELLING FOR USER CASES //////////////////////////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testFillInterpolation() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_SE_FILL_INTERPOLATION);
    assertNotNull(obj);
    JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType> jax = (JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType>) obj;
    PointSymbolizer pointSymbol = TRANSFORMER_GT.visit(jax.getValue());
    assertNotNull(pointSymbol);
    assertEquals(pointSymbol.getGeometryPropertyName(), valueGeom);
    assertEquals(Units.POINT, pointSymbol.getUnitOfMeasure());
    assertNotNull(pointSymbol.getGraphic());
    Graphic graphic = pointSymbol.getGraphic();
    Mark mark = (Mark) graphic.graphicalSymbols().get(0);
    Expression color = mark.getFill().getColor();
    assertTrue(color instanceof Interpolate);
    POOL.recycle(UNMARSHALLER);
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) Graphic(org.opengis.style.Graphic) Mark(org.opengis.style.Mark) JAXBElement(javax.xml.bind.JAXBElement) Interpolate(org.geotoolkit.style.function.Interpolate) Expression(org.opengis.filter.Expression) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 3 with Interpolate

use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.

the class GTtoSE110Transformer method visit.

@Override
public ColorMapType visit(final ColorMap colorMap, final Object data) {
    // TODO Fix that when better undestanding raster functions.
    final org.geotoolkit.se.xml.v110.ColorMapType cmt = se_factory.createColorMapType();
    final Expression fct = colorMap.getFunction();
    if (fct instanceof Categorize) {
        cmt.setCategorize(visit((Categorize) fct));
    } else if (fct instanceof Interpolate) {
        cmt.setInterpolate(visit((Interpolate) fct));
    } else if (fct instanceof Jenks) {
        cmt.setJenks(visit((Jenks) fct));
    }
    return cmt;
}
Also used : Categorize(org.geotoolkit.style.function.Categorize) ColorMapType(org.geotoolkit.se.xml.v110.ColorMapType) Interpolate(org.geotoolkit.style.function.Interpolate) Expression(org.opengis.filter.Expression) Jenks(org.geotoolkit.style.function.Jenks)

Example 4 with Interpolate

use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.

the class PaletteReaderTest method readCLR.

@Test
public void readCLR() throws IOException {
    String palette = "ColorMap 1 1\n" + "0.000000 143 0 0\n" + "500.000000 244 0 0\n" + "1000.000000 255 89 0\n" + "1500.000000 255 189 0\n" + "2000.000000 236 255 34\n" + "2500.000000 135 255 135\n" + "3000.000000 34 255 236\n" + "3500.000000 0 189 255\n" + "4000.000000 0 89 255\n" + "4500.000000 0 0 244\n" + "5000.000000 0 0 143";
    final ColorMap cm = new PaletteReader(PaletteReader.PATTERN_CLR).read(palette);
    assertTrue(cm.getFunction() instanceof Interpolate);
    final Interpolate interpolate = (Interpolate) cm.getFunction();
    final List<InterpolationPoint> steps = interpolate.getInterpolationPoints();
    assertEquals(12, steps.size());
    for (int i = 0; i < steps.size(); i++) {
        final InterpolationPoint step = steps.get(i);
        InterpolationPoint expected = null;
        switch(i) {
            case 0:
                expected = new DefaultInterpolationPoint(Double.NaN, SF.literal(new Color(0, 0, 0, 0)));
                break;
            case 1:
                expected = new DefaultInterpolationPoint(0d, SF.literal(new Color(143, 0, 0)));
                break;
            case 2:
                expected = new DefaultInterpolationPoint(500d, SF.literal(new Color(244, 0, 0)));
                break;
            case 3:
                expected = new DefaultInterpolationPoint(1000d, SF.literal(new Color(255, 89, 0)));
                break;
            case 4:
                expected = new DefaultInterpolationPoint(1500d, SF.literal(new Color(255, 189, 0)));
                break;
            case 5:
                expected = new DefaultInterpolationPoint(2000d, SF.literal(new Color(236, 255, 34)));
                break;
            case 6:
                expected = new DefaultInterpolationPoint(2500d, SF.literal(new Color(135, 255, 135)));
                break;
            case 7:
                expected = new DefaultInterpolationPoint(3000d, SF.literal(new Color(34, 255, 236)));
                break;
            case 8:
                expected = new DefaultInterpolationPoint(3500d, SF.literal(new Color(0, 189, 255)));
                break;
            case 9:
                expected = new DefaultInterpolationPoint(4000d, SF.literal(new Color(0, 89, 255)));
                break;
            case 10:
                expected = new DefaultInterpolationPoint(4500d, SF.literal(new Color(0, 0, 244)));
                break;
            case 11:
                expected = new DefaultInterpolationPoint(5000d, SF.literal(new Color(0, 0, 143)));
                break;
            default:
                fail("Unexpected number of elements.");
        }
        assertEquals(expected, step);
    }
}
Also used : DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) Interpolate(org.geotoolkit.style.function.Interpolate) ColorMap(org.opengis.style.ColorMap) Color(java.awt.Color) DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) Test(org.junit.Test)

Example 5 with Interpolate

use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.

the class CachedIsolineSymbolizer method extractSteps.

/**
 * Extract isolines steps from RasterSymbolizer ColorMap.
 */
private double[] extractSteps(RasterSymbolizer rasterSymbolizer) {
    Set<Double> steps = new HashSet<Double>();
    if (rasterSymbolizer != null && rasterSymbolizer.getColorMap() != null) {
        ColorMap colorMap = rasterSymbolizer.getColorMap();
        Expression function = colorMap.getFunction();
        if (function instanceof Interpolate) {
            Interpolate interpolate = (Interpolate) function;
            List<InterpolationPoint> points = interpolate.getInterpolationPoints();
            for (InterpolationPoint point : points) {
                steps.add(point.getData().doubleValue());
            }
            dynamicColorMap = false;
        } else if (function instanceof Categorize) {
            Categorize categorize = (Categorize) function;
            Map<Expression, Expression> thresholds = categorize.getThresholds();
            for (Map.Entry<Expression, Expression> entry : thresholds.entrySet()) {
                Expression key = entry.getKey();
                Number step = (Number) key.apply(null);
                if (step != null && Double.isFinite(step.doubleValue())) {
                    steps.add(step.doubleValue());
                }
            }
            dynamicColorMap = false;
        } else if (function instanceof Jenks) {
            Jenks jenks = (Jenks) function;
            Map<Double, Color> jenksColorMap = jenks.getColorMap();
            if (jenksColorMap != null) {
                for (Double jenksStep : jenksColorMap.keySet()) {
                    if (jenksStep != null && !jenksStep.isNaN()) {
                        steps.add(jenksStep);
                    }
                }
            }
            dynamicColorMap = true;
        }
    }
    int i = 0;
    Iterator<Double> iterator = steps.iterator();
    double[] stepsArray = new double[steps.size()];
    while (iterator.hasNext()) {
        stepsArray[i++] = iterator.next();
    }
    return stepsArray;
}
Also used : Categorize(org.geotoolkit.style.function.Categorize) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) ColorMap(org.opengis.style.ColorMap) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) Interpolate(org.geotoolkit.style.function.Interpolate) Expression(org.opengis.filter.Expression) Jenks(org.geotoolkit.style.function.Jenks) ColorMap(org.opengis.style.ColorMap)

Aggregations

Interpolate (org.geotoolkit.style.function.Interpolate)8 Expression (org.opengis.filter.Expression)6 Categorize (org.geotoolkit.style.function.Categorize)5 InterpolationPoint (org.geotoolkit.style.function.InterpolationPoint)5 Jenks (org.geotoolkit.style.function.Jenks)5 ColorMap (org.opengis.style.ColorMap)4 Color (java.awt.Color)3 Test (org.junit.Test)3 LinearGradientPaint (java.awt.LinearGradientPaint)2 MultipleGradientPaint (java.awt.MultipleGradientPaint)2 ArrayList (java.util.ArrayList)2 JAXBElement (javax.xml.bind.JAXBElement)2 NumberRange (org.apache.sis.measure.NumberRange)2 DefaultInterpolationPoint (org.geotoolkit.style.function.DefaultInterpolationPoint)2 Graphic (org.opengis.style.Graphic)2 Rectangle (java.awt.Rectangle)1 Point2D (java.awt.geom.Point2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 NumberFormat (java.text.NumberFormat)1 HashMap (java.util.HashMap)1