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);
}
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;
}
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;
}
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());
}
Aggregations