Search in sources :

Example 1 with Categorize

use of org.geotoolkit.style.function.Categorize 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 2 with Categorize

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

the class PaletteReaderTest method readPAL.

@Test
public void readPAL() throws IOException {
    String palette = "0,0,143,\"5000 - 4500\"\n" + "0,0,244,\"4500 - 3500\"\n" + "236,255,34,\"3500 - 1000\"\n" + "255,89,0,\"1000 - 500\"\n" + "244,0,0,\"500 - 0\"\n" + "143,0,0,\"0\"";
    final ColorMap cm = new PaletteReader(PaletteReader.PATTERN_PAL).read(palette);
    assertTrue(cm.getFunction() instanceof Categorize);
    final Categorize categorize = (Categorize) cm.getFunction();
    final Map<Expression, Expression> steps = categorize.getThresholds();
    assertEquals(8, steps.size());
    int i = 0;
    for (Entry<Expression, Expression> entry : steps.entrySet()) {
        Entry<Expression, Expression> expected = null;
        switch(i) {
            case 0:
                expected = new AbstractMap.SimpleEntry(StyleConstants.CATEGORIZE_LESS_INFINITY, SF.literal(new Color(143, 0, 0)));
                break;
            case 1:
                expected = new AbstractMap.SimpleEntry(FF.literal(0d), SF.literal(new Color(244, 0, 0)));
                break;
            case 2:
                expected = new AbstractMap.SimpleEntry(FF.literal(500d), SF.literal(new Color(255, 89, 0)));
                break;
            case 3:
                expected = new AbstractMap.SimpleEntry(FF.literal(1000d), SF.literal(new Color(236, 255, 34)));
                break;
            case 4:
                expected = new AbstractMap.SimpleEntry(FF.literal(3500d), SF.literal(new Color(0, 0, 244)));
                break;
            case 5:
                expected = new AbstractMap.SimpleEntry(FF.literal(4500d), SF.literal(new Color(0, 0, 143)));
                break;
            case 6:
                expected = new AbstractMap.SimpleEntry(FF.literal(5000d), SF.literal(new Color(0f, 0f, 0f, 0f)));
                break;
            case 7:
                expected = new AbstractMap.SimpleEntry(FF.literal(Double.NaN), SF.literal(new Color(0, 0, 0, 0)));
                break;
            default:
                fail("Unexpected number of elements.");
        }
        assertEquals(expected, entry);
        i++;
    }
}
Also used : Categorize(org.geotoolkit.style.function.Categorize) AbstractMap(java.util.AbstractMap) Expression(org.opengis.filter.Expression) ColorMap(org.opengis.style.ColorMap) Color(java.awt.Color) DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) Test(org.junit.Test)

Example 3 with Categorize

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

the class PaletteReaderTest method readCPT_RGB.

@Test
public void readCPT_RGB() throws IOException {
    String palette = "# Truly simulates the JET colormap in Matlab\n" + "# COLOR_MODEL = RGB\n" + "  0   0   0 143   1   0   0 159\n" + "  1   0   0 159   2  50   0 175\n" + "  2  50   0 175   3   0  12 191\n" + "  3   0  12 191   4   0   0 207\n" + "  4   0   0 207   5   0   0 223";
    final ColorMap cm = new PaletteReader(PaletteReader.PATTERN_CPT).read(palette);
    assertTrue(cm.getFunction() instanceof Categorize);
    final Categorize categorize = (Categorize) cm.getFunction();
    final Map<Expression, Expression> steps = categorize.getThresholds();
    assertEquals(8, steps.size());
    int i = 0;
    for (Entry<Expression, Expression> entry : steps.entrySet()) {
        Entry<Expression, Expression> expected = null;
        switch(i) {
            case 0:
                expected = new AbstractMap.SimpleEntry(StyleConstants.CATEGORIZE_LESS_INFINITY, SF.literal(new Color(0f, 0f, 0f, 0f)));
                break;
            case 1:
                expected = new AbstractMap.SimpleEntry(FF.literal(0d), SF.literal(new Color(0, 0, 143)));
                break;
            case 2:
                expected = new AbstractMap.SimpleEntry(FF.literal(1d), SF.literal(new Color(0, 0, 159)));
                break;
            case 3:
                expected = new AbstractMap.SimpleEntry(FF.literal(2d), SF.literal(new Color(50, 0, 175)));
                break;
            case 4:
                expected = new AbstractMap.SimpleEntry(FF.literal(3d), SF.literal(new Color(0, 12, 191)));
                break;
            case 5:
                expected = new AbstractMap.SimpleEntry(FF.literal(4d), SF.literal(new Color(0, 0, 207)));
                break;
            case 6:
                expected = new AbstractMap.SimpleEntry(FF.literal(5d), SF.literal(new Color(0, 0, 223)));
                break;
            case 7:
                expected = new AbstractMap.SimpleEntry(FF.literal(Double.NaN), SF.literal(new Color(0, 0, 0, 0)));
                break;
            default:
                fail("Unexpected number of elements.");
        }
        assertEquals(expected, entry);
        i++;
    }
}
Also used : Categorize(org.geotoolkit.style.function.Categorize) AbstractMap(java.util.AbstractMap) Expression(org.opengis.filter.Expression) ColorMap(org.opengis.style.ColorMap) Color(java.awt.Color) DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) Test(org.junit.Test)

Example 4 with Categorize

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

the class PaletteReaderTest method readCPT_HSV.

@Test
public void readCPT_HSV() throws IOException {
    String palette = "# COLOR_MODEL = HSV\n" + "-6000   255     0.6     1       -5500   240     0.6     1       L\n" + "-5500   240     0.6     1       -5000   225     0.6     1\n" + "-5000   225     0.6     1       -4500   210     0.6     1       L\n" + "-4500   210     0.6     1       -4000   195     0.6     1\n" + "-4000   195     0.6     1       -3500   180     0.6     1       L\n" + "-3500   180     0.6     1       -3000   165     0.6     1\n" + "-3000   165     0.6     1       -2500   150     0.6     1       L\n" + "-2500   150     0.6     1       -2000   135     0.6     1\n" + "-2000   135     0.6     1       -1500   120     0.6     1       L\n" + "-1500   120     0.6     1       -1000   105     0.6     1\n" + "-1000   105     0.6     1       -500    90      0.6     1       L\n" + "-500    90      0.6     1       0       75      0.6     1\n" + "0       60      0.35    1       500     40      0.35    1       L\n" + "500     40      0.35    1       1000    20      0.35    1\n" + "1000    20      0.35    1       1500    0       0.35    1       L\n" + "1500    360     0.35    1       2000    345     0.3     1\n" + "2000    345     0.3     1       2500    330     0.25    1       L\n" + "2500    330     0.25    1       3000    315     0.2     1       U\n" + "B       255     0.6     1\n" + "F       315     0.2     1";
    final ColorMap cm = new PaletteReader(PaletteReader.PATTERN_CPT).read(palette);
    assertTrue(cm.getFunction() instanceof Categorize);
    final Categorize categorize = (Categorize) cm.getFunction();
    final Map<Expression, Expression> steps = categorize.getThresholds();
    assertEquals(22, steps.size());
    int i = 0;
    for (Entry<Expression, Expression> entry : steps.entrySet()) {
        Entry<Expression, Expression> expected = null;
        switch(i) {
            case 0:
                expected = new AbstractMap.SimpleEntry(StyleConstants.CATEGORIZE_LESS_INFINITY, SF.literal(new Color(0f, 0f, 0f, 0f)));
                break;
            case 1:
                expected = new AbstractMap.SimpleEntry(FF.literal(-6000d), SF.literal(Color.getHSBColor(255f / 360f, 0.6f, 1)));
                break;
            case 2:
                expected = new AbstractMap.SimpleEntry(FF.literal(-5500d), SF.literal(Color.getHSBColor(240f / 360f, 0.6f, 1)));
                break;
            case 3:
                expected = new AbstractMap.SimpleEntry(FF.literal(-5000d), SF.literal(Color.getHSBColor(225f / 360f, 0.6f, 1)));
                break;
            case 4:
                expected = new AbstractMap.SimpleEntry(FF.literal(-4500d), SF.literal(Color.getHSBColor(210f / 360f, 0.6f, 1)));
                break;
            case 5:
                expected = new AbstractMap.SimpleEntry(FF.literal(-4000d), SF.literal(Color.getHSBColor(195f / 360f, 0.6f, 1)));
                break;
            case 6:
                expected = new AbstractMap.SimpleEntry(FF.literal(-3500d), SF.literal(Color.getHSBColor(180f / 360f, 0.6f, 1)));
                break;
            case 7:
                expected = new AbstractMap.SimpleEntry(FF.literal(-3000d), SF.literal(Color.getHSBColor(165f / 360f, 0.6f, 1)));
                break;
            case 8:
                expected = new AbstractMap.SimpleEntry(FF.literal(-2500d), SF.literal(Color.getHSBColor(150f / 360f, 0.6f, 1)));
                break;
            case 9:
                expected = new AbstractMap.SimpleEntry(FF.literal(-2000d), SF.literal(Color.getHSBColor(135f / 360f, 0.6f, 1)));
                break;
            case 10:
                expected = new AbstractMap.SimpleEntry(FF.literal(-1500d), SF.literal(Color.getHSBColor(120f / 360f, 0.6f, 1)));
                break;
            case 11:
                expected = new AbstractMap.SimpleEntry(FF.literal(-1000d), SF.literal(Color.getHSBColor(105f / 360f, 0.6f, 1)));
                break;
            case 12:
                expected = new AbstractMap.SimpleEntry(FF.literal(-500d), SF.literal(Color.getHSBColor(90f / 360f, 0.6f, 1)));
                break;
            case 13:
                expected = new AbstractMap.SimpleEntry(FF.literal(0d), SF.literal(Color.getHSBColor(75f / 360f, 0.6f, 1)));
                break;
            case 14:
                expected = new AbstractMap.SimpleEntry(FF.literal(Math.nextUp(0.0)), SF.literal(Color.getHSBColor(60f / 360f, 0.35f, 1)));
                break;
            case 15:
                expected = new AbstractMap.SimpleEntry(FF.literal(500d), SF.literal(Color.getHSBColor(40f / 360f, 0.35f, 1)));
                break;
            case 16:
                expected = new AbstractMap.SimpleEntry(FF.literal(1000d), SF.literal(Color.getHSBColor(20f / 360f, 0.35f, 1)));
                break;
            case 17:
                expected = new AbstractMap.SimpleEntry(FF.literal(1500d), SF.literal(Color.getHSBColor(0f / 360f, 0.35f, 1)));
                break;
            case 18:
                expected = new AbstractMap.SimpleEntry(FF.literal(2000d), SF.literal(Color.getHSBColor(345f / 360f, 0.3f, 1)));
                break;
            case 19:
                expected = new AbstractMap.SimpleEntry(FF.literal(2500d), SF.literal(Color.getHSBColor(330f / 360f, 0.25f, 1)));
                break;
            case 20:
                expected = new AbstractMap.SimpleEntry(FF.literal(3000d), SF.literal(Color.getHSBColor(315f / 360f, 0.2f, 1)));
                break;
            case 21:
                expected = new AbstractMap.SimpleEntry(FF.literal(Double.NaN), SF.literal(new Color(0, 0, 0, 0)));
                break;
            default:
                fail("Unexpected number of elements.");
        }
        assertEquals("At index : " + i, expected, entry);
        i++;
    }
}
Also used : Categorize(org.geotoolkit.style.function.Categorize) AbstractMap(java.util.AbstractMap) Expression(org.opengis.filter.Expression) ColorMap(org.opengis.style.ColorMap) Color(java.awt.Color) DefaultInterpolationPoint(org.geotoolkit.style.function.DefaultInterpolationPoint) InterpolationPoint(org.geotoolkit.style.function.InterpolationPoint) Test(org.junit.Test)

Example 5 with Categorize

use of org.geotoolkit.style.function.Categorize 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

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