org.geotools.styling.ColorMap Java Examples

The following examples show how to use org.geotools.styling.ColorMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageDataLoader.java    From gama with GNU General Public License v3.0 7 votes vote down vote up
private static Style createStyle(int band, double min, double max) {

		FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
		StyleFactory sf = CommonFactoryFinder.getStyleFactory();

		RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
		ColorMap cMap = sf.createColorMap();
		ColorMapEntry start = sf.createColorMapEntry();
		start.setColor(ff.literal("#ff0000"));
		start.setQuantity(ff.literal(min));
		ColorMapEntry end = sf.createColorMapEntry();
		end.setColor(ff.literal("#0000ff"));
		end.setQuantity(ff.literal(max));

		cMap.addColorMapEntry(start);
		cMap.addColorMapEntry(end);
		sym.setColorMap(cMap);
		Style style = SLD.wrapSymbolizers(sym);

		return style;
	}
 
Example #2
Source File: FieldConfigColourMap.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Populate field.
 *
 * @param value the value
 */
@Override
public void populateField(ColorMap value) {
    if (value != null) {
        if (colourRampConfig != null) {
            colourRampConfig.populate(value);
        }
        model.populate(value);

        if (colourMapEntryPanel != null) {
            colourMapEntryPanel.setSelectedEntry(null);
        }

        if (!isSuppressUndoEvents()) {
            UndoManager.getInstance()
                    .addUndoEvent(new UndoEvent(this, getFieldId(), oldValueObj, value));

            oldValueObj = value;
        }
        valueUpdated();
    }
}
 
Example #3
Source File: EncodeColourMap.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Encode colour map entries into a string.
 *
 * @param colourMap the colour map
 * @return the string
 */
public static String encode(ColorMap colourMap) {

    StringBuilder sb = new StringBuilder();

    for (ColorMapEntry entry : colourMap.getColorMapEntries()) {
        sb.append((entry.getLabel() == null) ? "" : entry.getLabel());
        sb.append(SEPARATOR);
        sb.append(entry.getColor());
        sb.append(SEPARATOR);
        sb.append(Double.valueOf(entry.getOpacity().toString()));
        sb.append(SEPARATOR);
        sb.append(entry.getQuantity());
        sb.append(ENTRY_SEPARATOR);
    }

    return sb.toString();
}
 
Example #4
Source File: ColourMapModel.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Populate.
 *
 * @param value the value
 */
public void populate(ColorMap value) {
    colourMapList.clear();

    for (ColorMapEntry colourMapEntry : value.getColorMapEntries()) {
        Expression colourExpression = colourMapEntry.getColor();
        Expression opacityExpression = colourMapEntry.getOpacity();
        Expression quantityExpression = colourMapEntry.getQuantity();
        String label = colourMapEntry.getLabel();

        ColourMapData data = new ColourMapData();

        data.setColour(colourExpression);
        data.setOpacity(opacityExpression);
        data.setQuantity(quantityExpression);
        data.setLabel(label);
        colourMapList.add(data);
    }
    this.fireTableDataChanged();
}
 
Example #5
Source File: ColourMapModel.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the colour map.
 *
 * @return the colour map
 */
public ColorMap getColourMap() {
    ColorMap colourMap = new ColorMapImpl();

    for (ColourMapData data : colourMapList) {
        ColorMapEntry entry = createColourMapEntry(data);

        colourMap.addColorMapEntry(entry);
    }
    return colourMap;
}
 
Example #6
Source File: FieldConfigPopulationTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#populateColourMapField(com.sldeditor.common.xml.ui.FieldIdEnum,
 * org.geotools.styling.ColorMap)}. Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#getColourMap(com.sldeditor.common.xml.ui.FieldIdEnum)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#getColourMap(com.sldeditor.ui.detail.config.FieldId)}.
 */
@Test
public void testColourMap() {

    FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;

    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);

    FieldConfigColourMap colourMapField =
            new FieldConfigColourMap(
                    new FieldConfigCommonData(Geometry.class, fieldId, "label", true, false));
    colourMapField.createUI();
    fieldConfigManager.add(fieldId, colourMapField);

    ColorMap expectedValue = new ColorMapImpl();
    ColorMapEntry entry = new ColorMapEntryImpl();
    StyleBuilder styleBuilder = new StyleBuilder();

    entry.setColor(styleBuilder.colorExpression(Color.PINK));
    entry.setQuantity(styleBuilder.literalExpression(2.3));
    expectedValue.addColorMapEntry(entry);
    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
    obj.populateColourMapField(fieldId, expectedValue);
    assertEquals(
            expectedValue.getColorMapEntries().length,
            obj.getColourMap(fieldId).getColorMapEntries().length);

    // This shouldn't work as it does not know about the field
    FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
    obj.populateColourMapField(wrongFieldEnum, expectedValue);
    assertNull(obj.getColourMap(wrongFieldEnum));
}
 
Example #7
Source File: FieldConfigPopulationTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigPopulation#FieldConfigPopulation(com.sldeditor.ui.detail.GraphicPanelFieldManager)}.
 */
@Test
public void testFieldConfigPopulation() {
    FieldIdEnum fieldId = FieldIdEnum.UNKNOWN;
    FieldConfigPopulation obj = new FieldConfigPopulation(null);
    obj.populateBooleanField(fieldId, Boolean.TRUE);
    obj.populateComboBoxField(fieldId, "");
    obj.populateColourField(fieldId, null);
    obj.populateColourMapField(FieldIdEnum.ANCHOR_POINT_V, (ColorMap) null);
    obj.populateFontField(FieldIdEnum.ANCHOR_POINT_V, (Font) null);
    obj.populateTextField(fieldId, (String) null);
    obj.populateDoubleField(fieldId, (Double) null);
    obj.populateIntegerField(fieldId, (Integer) null);
    obj.populateField(fieldId, (Expression) null);
    obj.populateUserLayer(fieldId, (UserLayer) null);
    obj.populateFieldTypeConstraint(fieldId, (List<FeatureTypeConstraint>) null);

    assertNull(obj.getExpression(fieldId));
    assertFalse(obj.getBoolean(fieldId));
    assertEquals(0, obj.getInteger(fieldId));
    assertTrue(Math.abs(obj.getDouble(fieldId) - 0.0) < 0.001);
    assertTrue(obj.getText(fieldId).compareTo("") == 0);
    assertNull(obj.getComboBox(fieldId));
    assertNull(obj.getColourMap(fieldId));
    assertNull(obj.getFieldConfig(fieldId));
    assertNull(obj.getFeatureTypeConstraint(fieldId));
}
 
Example #8
Source File: EncodeColourMapTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.EncodeColourMap#encode(org.geotools.styling.ColorMap)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.EncodeColourMap#encode(java.util.List)}.
 */
@Test
public void testEncodeColorMap() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    ColorMapEntryImpl entry1 = new ColorMapEntryImpl();
    entry1.setColor(ff.literal(COLOUR_1));
    entry1.setOpacity(ff.literal(OPACITY_1));
    entry1.setQuantity(ff.literal(QUANTITY_1));
    ColorMap expectedValue = new ColorMapImpl();
    expectedValue.addColorMapEntry(entry1);
    ColorMapEntryImpl entry2 = new ColorMapEntryImpl();
    entry2.setColor(ff.literal(COLOUR_2));
    entry2.setLabel(LABEL_2);
    entry2.setOpacity(ff.literal(OPACITY_2));
    entry2.setQuantity(ff.literal(QUANTITY_2));
    expectedValue.addColorMapEntry(entry2);

    XMLColourMapEntry xml1 = new XMLColourMapEntry();
    xml1.setColour(COLOUR_1);
    xml1.setOpacity(OPACITY_1);
    xml1.setQuantity(42);
    List<XMLColourMapEntry> xmlList = new ArrayList<XMLColourMapEntry>();
    xmlList.add(xml1);

    XMLColourMapEntry xml2 = new XMLColourMapEntry();
    xml2.setColour(COLOUR_2);
    xml2.setLabel(LABEL_2);
    xml2.setOpacity(OPACITY_2);
    xml2.setQuantity(QUANTITY_2);
    xmlList.add(xml2);

    String actualValue1 = EncodeColourMap.encode(expectedValue);
    String actualValue2 = EncodeColourMap.encode(xmlList);

    assertTrue(actualValue1.compareTo(actualValue2) == 0);
}
 
Example #9
Source File: FieldConfigColourMapTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#generateExpression()}. Test
 * method for {@link
 * com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#populateExpression(java.lang.Object,
 * org.opengis.filter.expression.Expression)}. Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#populateField(org.geotools.styling.ColorMap)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * org.geotools.styling.ColorMap)}. Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#getColourMap()}.
 */
@Test
public void testGenerateExpression() {

    FieldConfigColourMap field =
            new FieldConfigColourMap(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, false));
    ColorMap testValue = null;
    field.populate(null);
    field.setTestValue(FieldIdEnum.UNKNOWN, testValue);
    field.populateField(testValue);

    field.createUI();

    ColorMap expectedValue1 = new ColorMapImpl();
    field.populateField(expectedValue1);
    assertEquals(expectedValue1, field.getColourMap());

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    ColorMap expectedValue2 = new ColorMapImpl();
    ColorMapEntryImpl entry = new ColorMapEntryImpl();
    entry.setColor(ff.literal("#001122"));
    expectedValue2.addColorMapEntry(entry);
    field.setTestValue(FieldIdEnum.UNKNOWN, expectedValue2);
    assertEquals(
            expectedValue2.getColorMapEntries().length,
            field.getColourMap().getColorMapEntries().length);

    field.populateExpression((String) null);
}
 
Example #10
Source File: FieldConfigColourMapTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#undoAction(com.sldeditor.common.undo.UndoInterface)}.
 * Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#redoAction(com.sldeditor.common.undo.UndoInterface)}.
 */
@Test
public void testUndoAction() {
    FieldConfigColourMap field =
            new FieldConfigColourMap(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, false));
    field.undoAction(null);
    field.redoAction(null);
    field.createUI();

    ColorMap expectedValue1 = new ColorMapImpl();
    field.populateField(expectedValue1);
    assertEquals(expectedValue1, field.getColourMap());

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    ColorMap expectedValue2 = new ColorMapImpl();
    ColorMapEntryImpl entry = new ColorMapEntryImpl();
    entry.setColor(ff.literal("#001122"));
    expectedValue2.addColorMapEntry(entry);
    field.populateField(expectedValue2);

    UndoManager.getInstance().undo();
    assertEquals(
            expectedValue1.getColorMapEntries().length,
            field.getColourMap().getColorMapEntries().length);
    UndoManager.getInstance().redo();
    assertEquals(
            expectedValue2.getColorMapEntries().length,
            field.getColourMap().getColorMapEntries().length);

    // Increase the code coverage
    field.undoAction(null);
    field.undoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
    field.redoAction(null);
    field.redoAction(new UndoEvent(null, FieldIdEnum.NAME, "", "new"));
}
 
Example #11
Source File: FieldConfigColourMap.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void colourMapUpdated() {
    if (!isSuppressUndoEvents()) {
        ColorMap colourMap = model.getColourMap();

        UndoManager.getInstance()
                .addUndoEvent(new UndoEvent(this, getFieldId(), oldValueObj, colourMap));

        oldValueObj = colourMap;
    }
    valueUpdated();
}
 
Example #12
Source File: FieldConfigColourMapTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Test undo action suppressed. */
@Test
public void testUndoActionSuppressed() {
    // Suppress undo events
    TestFieldConfigColourMap field =
            new TestFieldConfigColourMap(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, true));
    field.createUI();

    ColorMap expectedValue1 = new ColorMapImpl();
    field.populateField(expectedValue1);
    assertEquals(expectedValue1, field.getColourMap());

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    ColorMap expectedValue2 = new ColorMapImpl();
    ColorMapEntryImpl entry = new ColorMapEntryImpl();
    entry.setColor(ff.literal("#001122"));
    expectedValue2.addColorMapEntry(entry);

    int undoSizeList = UndoManager.getInstance().getUndoListSize();
    field.populateField(expectedValue2);

    field.addEntry();
    field.selectRow(0, 0);
    field.removeEntry();

    assertEquals(undoSizeList, UndoManager.getInstance().getUndoListSize());
}
 
Example #13
Source File: FieldConfigColourMap.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Redo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@Override
public void redoAction(UndoInterface undoRedoObject) {
    if ((table != null) && (undoRedoObject != null)) {
        if (undoRedoObject.getNewValue() instanceof ColorMap) {
            ColorMap newValue = (ColorMap) undoRedoObject.getNewValue();

            populateField(newValue);
        }
    }
}
 
Example #14
Source File: FieldConfigColourMap.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Undo action.
 *
 * @param undoRedoObject the undo/redo object
 */
@Override
public void undoAction(UndoInterface undoRedoObject) {
    if ((table != null) && (undoRedoObject != null)) {
        if (undoRedoObject.getOldValue() instanceof ColorMap) {
            ColorMap oldValue = (ColorMap) undoRedoObject.getOldValue();

            populateField(oldValue);
        }
    }
}
 
Example #15
Source File: FieldConfigColourMap.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the string value.
 *
 * @return the string value
 */
@Override
public ColorMap getColourMap() {
    if (table != null) {
        return model.getColourMap();
    }
    return null;
}
 
Example #16
Source File: FieldConfigPopulation.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the colour map.
 *
 * @param fieldId the field id
 * @return the colour map
 */
public ColorMap getColourMap(FieldIdEnum fieldId) {
    if (fieldConfigManager != null) {
        FieldConfigValuePopulateInterface fieldConfig = fieldConfigManager.get(fieldId);

        if (fieldConfig != null) {
            return fieldConfig.getColourMap();
        }
    }
    return null;
}
 
Example #17
Source File: FieldConfigPopulation.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate colour map field.
 *
 * @param fieldId the field id
 * @param colourMap the colour map
 */
public void populateColourMapField(FieldIdEnum fieldId, ColorMap colourMap) {
    if (fieldConfigManager == null) {
        return;
    }
    FieldConfigBase fieldConfig = fieldConfigManager.get(fieldId);
    if (fieldConfig != null) {
        fieldConfig.populateField(colourMap);
    }
}
 
Example #18
Source File: FieldConfigColourMapTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.colourmap.FieldConfigColourMap#getStringValue()}.
 */
@Test
public void testGetStringValue() {

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    ColorMapEntryImpl entry1 = new ColorMapEntryImpl();
    entry1.setColor(ff.literal("#001122"));
    entry1.setLabel("testlabel");
    entry1.setOpacity(ff.literal(0.42));
    entry1.setQuantity(ff.literal(42));
    ColorMap expectedValue = new ColorMapImpl();
    expectedValue.addColorMapEntry(entry1);
    ColorMapEntryImpl entry2 = new ColorMapEntryImpl();
    entry2.setColor(ff.literal("#551122"));
    entry2.setLabel("testlabel2");
    entry2.setOpacity(ff.literal(0.22));
    entry2.setQuantity(ff.literal(12));
    expectedValue.addColorMapEntry(entry2);

    FieldConfigColourMap field =
            new FieldConfigColourMap(
                    new FieldConfigCommonData(
                            Geometry.class, FieldIdEnum.NAME, "label", true, false));
    field.populateField(expectedValue);

    assertTrue(field.getStringValue().compareTo(EncodeColourMap.encode(expectedValue)) == 0);
}
 
Example #19
Source File: RasterSymbolizerDetails.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Update colour map.
 *
 * @return the color map
 */
private ColorMap updateColourMap() {
    ColorMap colorMap = fieldConfigVisitor.getColourMap(FieldIdEnum.RASTER_COLOURMAP);
    ValueComboBoxData colourMapType =
            fieldConfigVisitor.getComboBox(FieldIdEnum.RASTER_COLOURMAP_TYPE);

    colorMap.setType(Integer.valueOf(colourMapType.getKey()));
    return colorMap;
}
 
Example #20
Source File: RasterSymbolizerDetails.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate colour map.
 *
 * @param rasterSymbolizer the raster symbolizer
 */
private void populateColourMap(RasterSymbolizer rasterSymbolizer) {
    ColorMap colourMap = rasterSymbolizer.getColorMap();

    fieldConfigVisitor.populateComboBoxField(
            FieldIdEnum.RASTER_COLOURMAP_TYPE, Integer.toString(colourMap.getType()));
    fieldConfigVisitor.populateColourMapField(FieldIdEnum.RASTER_COLOURMAP, colourMap);
}
 
Example #21
Source File: RasterReader.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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<>();

    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) {
                ConsoleManager.getInstance().exception(this, e);
            }
        }
    }

    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);
}
 
Example #22
Source File: ColourRampConfigPanel.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Populate the configuration fields.
 *
 * @param value the value
 */
public void populate(ColorMap value) {

    ValueComboBoxData selectedValue = typeComboBox.getSelectedValue();
    if (selectedValue != null) {
        ColourRampPanelInterface selectedPanel =
                this.colourRampMapCache.get(selectedValue.getKey());

        if (selectedPanel != null) {
            selectedPanel.populate(value);
        }
    }
}
 
Example #23
Source File: ColourRampPanel.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populate(ColorMap value) {
    if (value != null) {
        ColorMapEntry[] entries = value.getColorMapEntries();
        if ((entries != null) && (entries.length > 0)) {
            populateValue(minValueSpinner, entries[0]);
            populateValue(maxValueSpinner, entries[entries.length - 1]);
        }
    }
}
 
Example #24
Source File: OmsMapsViewer.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
private void addCoverages( final MapContent map ) throws Exception {
    if (inRasters == null) {
        return;
    }
    RasterSymbolizer rasterSym = sf.createRasterSymbolizer();
    ColorMap colorMap = sf.createColorMap();

    for( String rasterPath : inRasters ) {
        GridCoverage2D readRaster = OmsRasterReader.readRaster(rasterPath);
        RenderedImage renderedImage = readRaster.getRenderedImage();
        double max = Double.NEGATIVE_INFINITY;
        double min = Double.POSITIVE_INFINITY;
        RectIter iter = RectIterFactory.create(renderedImage, null);
        do {
            do {
                double value = iter.getSampleDouble();
                if (value > max) {
                    max = value;
                }
                if (value < min) {
                    min = value;
                }
            } while( !iter.nextPixelDone() );
            iter.startPixels();
        } while( !iter.nextLineDone() );

        // red to blue
        Color fromColor = Color.blue;
        Color midColor = Color.green;
        Color toColor = Color.red;
        Expression fromColorExpr = sb
                .colorExpression(new java.awt.Color(fromColor.getRed(), fromColor.getGreen(), fromColor.getBlue(), 255));
        Expression midColorExpr = sb
                .colorExpression(new java.awt.Color(midColor.getRed(), midColor.getGreen(), midColor.getBlue(), 255));
        Expression toColorExpr = sb
                .colorExpression(new java.awt.Color(toColor.getRed(), toColor.getGreen(), toColor.getBlue(), 255));
        Expression fromExpr = sb.literalExpression(min);
        Expression midExpr = sb.literalExpression(min + (max - min) / 2);
        Expression toExpr = sb.literalExpression(max);

        ColorMapEntry entry = sf.createColorMapEntry();
        entry.setQuantity(fromExpr);
        entry.setColor(fromColorExpr);
        colorMap.addColorMapEntry(entry);

        entry = sf.createColorMapEntry();
        entry.setQuantity(midExpr);
        entry.setColor(midColorExpr);
        colorMap.addColorMapEntry(entry);

        entry = sf.createColorMapEntry();
        entry.setQuantity(toExpr);
        entry.setColor(toColorExpr);
        colorMap.addColorMapEntry(entry);

        rasterSym.setColorMap(colorMap);

        Style rasterStyle = SLD.wrapSymbolizers(rasterSym);

        GridCoverageLayer layer = new GridCoverageLayer(readRaster, rasterStyle);

        map.addLayer(layer);
    }
}
 
Example #25
Source File: OmsCoverageViewer.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void viewCoverage() throws Exception {
    StyleFactory sf = CommonFactoryFinder.getStyleFactory(null);
    // RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
    // Style rasterStyle = SLD.wrapSymbolizers(sym);

    StyleBuilder sB = new StyleBuilder(sf);
    RasterSymbolizer rasterSym = sf.createRasterSymbolizer();

    ColorMap colorMap = sf.createColorMap();

    RenderedImage renderedImage = raster.getRenderedImage();
    double max = Double.NEGATIVE_INFINITY;
    double min = Double.POSITIVE_INFINITY;
    RectIter iter = RectIterFactory.create(renderedImage, null);
    do {
        do {
            double value = iter.getSampleDouble();
            if (value > max) {
                max = value;
            }
            if (value < min) {
                min = value;
            }
        } while( !iter.nextPixelDone() );
        iter.startPixels();
    } while( !iter.nextLineDone() );

    // red to blue
    Color fromColor = Color.blue;
    Color toColor = Color.red;
    Expression fromColorExpr = sB
            .colorExpression(new java.awt.Color(fromColor.getRed(), fromColor.getGreen(), fromColor.getBlue(), 255));
    Expression toColorExpr = sB
            .colorExpression(new java.awt.Color(toColor.getRed(), toColor.getGreen(), toColor.getBlue(), 255));
    Expression fromExpr = sB.literalExpression(min);
    Expression toExpr = sB.literalExpression(max);

    ColorMapEntry entry = sf.createColorMapEntry();
    entry.setQuantity(fromExpr);
    entry.setColor(fromColorExpr);
    colorMap.addColorMapEntry(entry);

    entry = sf.createColorMapEntry();
    entry.setQuantity(toExpr);
    entry.setColor(toColorExpr);
    colorMap.addColorMapEntry(entry);

    rasterSym.setColorMap(colorMap);

    Style rasterStyle = SLD.wrapSymbolizers(rasterSym);

    // Set up a MapContext with the two layers
    final MapContent map = new MapContent();
    map.setTitle("Coverage Viewer");
    map.addLayer(new GridCoverageLayer(raster, rasterStyle));

    // Create a JMapFrame with a menu to choose the display style for the
    final JMapFrame frame = new JMapFrame(map);
    frame.setSize(800, 600);
    frame.enableStatusBar(true);
    frame.enableTool(JMapFrame.Tool.ZOOM, JMapFrame.Tool.PAN, JMapFrame.Tool.RESET);
    frame.enableToolBar(true);
    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter(){
        public void windowClosing( WindowEvent e ) {
            frame.setVisible(false);
        }
    });

    while( frame.isVisible() ) {
        Thread.sleep(300);
    }
}
 
Example #26
Source File: FieldConfigBaseTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigBase#populateField(java.lang.String)}.
 */
@Test
public void testPopulateFieldString() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field =
            new TestFieldConfigBase(
                    new FieldConfigCommonData(
                            String.class, expectedFieldId, expectedLabel, false, false));

    field.populateField("");
    field.setTestValue(expectedFieldId, "");

    field.populateField(42);
    field.setTestValue(expectedFieldId, 42);
    assertEquals(0, field.getIntValue());

    field.populateField(3.142);
    field.setTestValue(expectedFieldId, 3.142);
    assertTrue(Math.abs(field.getDoubleValue()) < 0.0001);

    field.populateField(ZonedDateTime.now());
    field.populateField((ReferencedEnvelope) null);
    field.setTestValue(expectedFieldId, (ReferencedEnvelope) null);
    field.populateField((Id) null);
    field.populateField((TimePeriod) null);
    field.populateField((ProcessFunction) null);
    assertNull(field.getProcessFunction());

    field.populateField(true);
    field.setTestValue(expectedFieldId, true);
    assertEquals(false, field.getBooleanValue());

    field.populateField((ColorMap) null);
    field.setTestValue(expectedFieldId, (ColorMap) null);
    assertNull(field.getColourMap());

    field.populateField((List<FeatureTypeConstraint>) null);
    field.setTestValue(expectedFieldId, (List<FeatureTypeConstraint>) null);
    assertNull(field.getFeatureTypeConstraint());

    field.populateField((Font) null);
    assertNull(field.getFont());

    field.setTestValue(expectedFieldId, (Expression) null);

    assertNull(field.getEnumValue());
}
 
Example #27
Source File: FieldConfigPopulate.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the colour map.
 *
 * @return the colour map
 */
@Override
public ColorMap getColourMap() {
    // Do nothing
    return null;
}
 
Example #28
Source File: RasterSymbolizerDetails.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/** Update symbol. */
private void updateSymbol() {

    // Contrast enhancement
    Expression gammaValueExpression =
            fieldConfigVisitor.getExpression(FieldIdEnum.RASTER_CONTRAST_GAMMAVALUE);

    ContrastEnhancement contrastEnhancement = updateContrastEnhancement(gammaValueExpression);

    // Colour map
    ColorMap colorMap = updateColourMap();

    // Channel selection
    ChannelSelection channelSelection = updateEnhancementGroup();

    //
    // Overlap
    //
    OverlapBehavior overlapBehavior = updateOverlapBehavior();

    //
    // Shaded relief
    //
    ShadedRelief shadedRelief = updateShadedRelief();

    Symbolizer symbolizer = null;

    StandardData standardData = getStandardData();

    Expression opacityExpression = fieldConfigVisitor.getExpression(FieldIdEnum.RASTER_OPACITY);

    // Geometry field
    Expression geometryField = ExtractGeometryField.getGeometryField(fieldConfigVisitor);

    RasterSymbolizer rasterSymbolizer =
            getStyleFactory()
                    .rasterSymbolizer(
                            standardData.getName(),
                            geometryField,
                            standardData.getDescription(),
                            (standardData.getUnit() != null)
                                    ? standardData.getUnit().getUnit()
                                    : null,
                            opacityExpression,
                            channelSelection,
                            overlapBehavior,
                            colorMap,
                            contrastEnhancement,
                            shadedRelief,
                            symbolizer);

    if (vendorOptionRasterFactory != null) {
        vendorOptionRasterFactory.updateSymbol(rasterSymbolizer);
    }
    rasterSymbolizer.setOverlapBehavior(overlapBehavior);
    SelectedSymbol.getInstance().replaceSymbolizer(rasterSymbolizer);

    this.fireUpdateSymbol();
}
 
Example #29
Source File: TestValueVisitor.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the test colour map value.
 *
 * @param fieldId the field id
 * @param testValue the test value
 */
public void setTestValue(FieldIdEnum fieldId, ColorMap testValue);
 
Example #30
Source File: FieldConfigPopulate.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the test value, overridden if necessary.
 *
 * @param fieldId the field id
 * @param testValue the test value
 */
@Override
public void setTestValue(FieldIdEnum fieldId, ColorMap testValue) {
    // Do nothing
}