本文整理匯總了Java中org.geotools.styling.ColorMap.addColorMapEntry方法的典型用法代碼示例。如果您正苦於以下問題:Java ColorMap.addColorMapEntry方法的具體用法?Java ColorMap.addColorMapEntry怎麽用?Java ColorMap.addColorMapEntry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.geotools.styling.ColorMap
的用法示例。
在下文中一共展示了ColorMap.addColorMapEntry方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGetStringValue
import org.geotools.styling.ColorMap; //導入方法依賴的package包/類
/**
* 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));
field.populateField(expectedValue);
assertTrue(field.getStringValue().compareTo(EncodeColourMap.encode(expectedValue)) == 0);
}
示例2: getColourMap
import org.geotools.styling.ColorMap; //導入方法依賴的package包/類
/**
* 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;
}
示例3: testColourMap
import org.geotools.styling.ColorMap; //導入方法依賴的package包/類
/**
* 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));
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));
}
示例4: testEncodeColorMap
import org.geotools.styling.ColorMap; //導入方法依賴的package包/類
/**
* 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);
}
示例5: testGenerateExpression
import org.geotools.styling.ColorMap; //導入方法依賴的package包/類
/**
* 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));
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);
}
示例6: testUndoAction
import org.geotools.styling.ColorMap; //導入方法依賴的package包/類
/**
* 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));
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"));
}
示例7: viewCoverage
import org.geotools.styling.ColorMap; //導入方法依賴的package包/類
@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 MapContext map = new DefaultMapContext();
map.setTitle("Coverage Viewer");
map.addLayer(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);
}
}
示例8: addCoverages
import org.geotools.styling.ColorMap; //導入方法依賴的package包/類
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);
}
}