Search in sources :

Example 6 with ColorMapEntryImpl

use of org.geotools.styling.ColorMapEntryImpl in project sldeditor by robward-scisys.

the class RasterReader method createRGBImageSymbol.

/**
 * Creates the rgb image symbol.
 *
 * @param sym the sym
 * @param cov the cov
 * @param raster the raster
 */
private void createRGBImageSymbol(RasterSymbolizer sym, GridCoverage2D cov, WritableRaster raster) {
    double dest;
    List<Double> valueList = new ArrayList<Double>();
    GridEnvelope2D gridRange2D = cov.getGridGeometry().getGridRange2D();
    for (int x = 0; x < gridRange2D.getWidth(); x++) {
        for (int y = 0; y < gridRange2D.getHeight(); y++) {
            try {
                dest = raster.getSampleDouble(x, y, 0);
                if (!valueList.contains(dest)) {
                    valueList.add(dest);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    ColorMapImpl colourMap = new ColorMapImpl();
    // Sort the unique sample values in ascending order
    Collections.sort(valueList);
    // Create colour amp entries in the colour map for all the sample values
    for (Double value : valueList) {
        ColorMapEntry entry = new ColorMapEntryImpl();
        Literal colourExpression = ff.literal(ColourUtils.fromColour(ColourUtils.createRandomColour()));
        entry.setColor(colourExpression);
        entry.setQuantity(ff.literal(value.doubleValue()));
        colourMap.addColorMapEntry(entry);
    }
    colourMap.setType(ColorMap.TYPE_VALUES);
    sym.setColorMap(colourMap);
}
Also used : ColorMapImpl(org.geotools.styling.ColorMapImpl) ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D) Literal(org.opengis.filter.expression.Literal) ArrayList(java.util.ArrayList) ColorMapEntry(org.geotools.styling.ColorMapEntry) IOException(java.io.IOException)

Example 7 with ColorMapEntryImpl

use of org.geotools.styling.ColorMapEntryImpl in project sldeditor by robward-scisys.

the class MultipleColourMapEntry method getColourMapEntry.

/**
 * Gets the colour map entry.
 *
 * @return the colour map entry
 */
public ColorMapEntry getColourMapEntry() {
    ColorMapEntry entry = new ColorMapEntryImpl();
    if (firstEntry != null) {
        entry.setLabel(labelMultipleValue ? firstEntry.getLabel() : null);
        entry.setOpacity(opacityMultipleValue ? firstEntry.getOpacity() : null);
        entry.setQuantity(quantityMultipleValue ? firstEntry.getQuantity() : null);
        entry.setColor(colourMultipleValue ? firstEntry.getColor() : null);
    }
    return entry;
}
Also used : ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) ColorMapEntry(org.geotools.styling.ColorMapEntry)

Example 8 with ColorMapEntryImpl

use of org.geotools.styling.ColorMapEntryImpl in project sldeditor by robward-scisys.

the class ColourMapModel method createColourMapEntry.

/**
 * Creates the colour map entry.
 *
 * @param data the data
 * @return the color map entry
 */
private ColorMapEntry createColourMapEntry(ColourMapData data) {
    ColorMapEntry entry = new ColorMapEntryImpl();
    entry.setColor(data.getColourExpression());
    entry.setOpacity(data.getOpacity());
    entry.setQuantity(data.getQuantity());
    entry.setLabel(data.getLabel());
    return entry;
}
Also used : ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) ColorMapEntry(org.geotools.styling.ColorMapEntry)

Example 9 with ColorMapEntryImpl

use of org.geotools.styling.ColorMapEntryImpl in project sldeditor by robward-scisys.

the class MultipleColourMapEntryTest method testParseList.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.MultipleColourMapEntry#parseList(java.util.List)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.colourmap.MultipleColourMapEntry#getColourMapEntry()}.
 */
@Test
public void testParseList() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    MultipleColourMapEntry testObj = new MultipleColourMapEntry();
    assertNotNull(testObj.getColourMapEntry());
    ColorMapEntry c1 = new ColorMapEntryImpl();
    String expectedLabel = "abc";
    String expectedColour = "#123456";
    double expectedOpacity = 0.5;
    int expectedQuantity = 42;
    c1.setLabel(expectedLabel);
    c1.setColor(ff.literal(expectedColour));
    c1.setOpacity(ff.literal(expectedOpacity));
    c1.setQuantity(ff.literal(expectedQuantity));
    List<ColorMapEntry> expectedList = new ArrayList<ColorMapEntry>();
    expectedList.add(c1);
    ColorMapEntry c2 = new ColorMapEntryImpl();
    c2.setLabel(expectedLabel);
    c2.setColor(ff.literal(expectedColour));
    c2.setOpacity(ff.literal(expectedOpacity));
    c2.setQuantity(ff.literal(expectedQuantity));
    expectedList.add(c2);
    ColorMapEntry c3 = new ColorMapEntryImpl();
    c3.setLabel(expectedLabel);
    c3.setColor(ff.literal(expectedColour));
    c3.setOpacity(ff.literal(expectedOpacity));
    c3.setQuantity(ff.literal(expectedQuantity));
    expectedList.add(c3);
    testObj.parseList(expectedList);
    ColorMapEntry actual = testObj.getColourMapEntry();
    // All the same
    assertNotNull(testObj.getColourMapEntry());
    assertEquals(actual.getLabel(), expectedLabel);
    assertEquals(actual.getColor().toString(), expectedColour);
    assertEquals(actual.getOpacity().toString(), String.valueOf(expectedOpacity));
    assertEquals(actual.getQuantity().toString(), String.valueOf(expectedQuantity));
    // Change label
    c2.setLabel("different");
    testObj.parseList(expectedList);
    actual = testObj.getColourMapEntry();
    assertNotNull(testObj.getColourMapEntry());
    assertNull(actual.getLabel());
    assertEquals(actual.getColor().toString(), expectedColour);
    assertEquals(actual.getOpacity().toString(), String.valueOf(expectedOpacity));
    assertEquals(actual.getQuantity().toString(), String.valueOf(expectedQuantity));
    // Change colour
    c1.setColor(ff.literal("#987654"));
    testObj.parseList(expectedList);
    actual = testObj.getColourMapEntry();
    assertNotNull(testObj.getColourMapEntry());
    assertNull(actual.getLabel());
    assertNull(actual.getColor());
    assertEquals(actual.getOpacity().toString(), String.valueOf(expectedOpacity));
    assertEquals(actual.getQuantity().toString(), String.valueOf(expectedQuantity));
    // Change opacity
    c3.setOpacity(ff.literal(1.0));
    testObj.parseList(expectedList);
    actual = testObj.getColourMapEntry();
    assertNotNull(testObj.getColourMapEntry());
    assertNull(actual.getLabel());
    assertNull(actual.getColor());
    assertNull(actual.getOpacity());
    assertEquals(actual.getQuantity().toString(), String.valueOf(expectedQuantity));
    // Change quantity
    c2.setQuantity(ff.literal(39.0));
    testObj.parseList(expectedList);
    actual = testObj.getColourMapEntry();
    assertNotNull(testObj.getColourMapEntry());
    assertNull(actual.getLabel());
    assertNull(actual.getColor());
    assertNull(actual.getOpacity());
    assertNull(actual.getQuantity());
}
Also used : ColorMapEntryImpl(org.geotools.styling.ColorMapEntryImpl) MultipleColourMapEntry(com.sldeditor.ui.detail.config.colourmap.MultipleColourMapEntry) ArrayList(java.util.ArrayList) ColorMapEntry(org.geotools.styling.ColorMapEntry) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Aggregations

ColorMapEntryImpl (org.geotools.styling.ColorMapEntryImpl)9 ColorMapImpl (org.geotools.styling.ColorMapImpl)6 Test (org.junit.Test)6 ColorMap (org.geotools.styling.ColorMap)5 ColorMapEntry (org.geotools.styling.ColorMapEntry)5 FilterFactory (org.opengis.filter.FilterFactory)5 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)4 FieldConfigColourMap (com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap)4 Geometry (com.vividsolutions.jts.geom.Geometry)4 ArrayList (java.util.ArrayList)3 UndoEvent (com.sldeditor.common.undo.UndoEvent)1 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)1 XMLColourMapEntry (com.sldeditor.common.xml.ui.XMLColourMapEntry)1 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)1 FieldConfigPopulation (com.sldeditor.ui.detail.config.FieldConfigPopulation)1 MultipleColourMapEntry (com.sldeditor.ui.detail.config.colourmap.MultipleColourMapEntry)1 IOException (java.io.IOException)1 GridEnvelope2D (org.geotools.coverage.grid.GridEnvelope2D)1 StyleBuilder (org.geotools.styling.StyleBuilder)1 Literal (org.opengis.filter.expression.Literal)1