private RasterSymbolizer buildRainColorMap() { StyleBuilder sb = new StyleBuilder(); ColorMap colorMap = sb.createColorMap( new String[] {"1", "2", "3", "4"}, new double[] {0, 100, 2000, 5000}, new Color[] {Color.RED, Color.WHITE, Color.GREEN, Color.BLUE}, ColorMap.TYPE_RAMP); RasterSymbolizer rasterSymbolizer = sb.createRasterSymbolizer(colorMap, 1d); return rasterSymbolizer; }
sldBuilder.createColorMap( new String[] { // labels "category", "category", "category"
sldBuilder.createColorMap( new String[] { // labels "category", "category", "category"
sb.createColorMap( labels, quantities, realColorRamp.toArray(new Color[1]), colorMapType); FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(null);
rs = sldBuilder.createRasterSymbolizer(); final ColorMap cm = sldBuilder.createColorMap( new String[] { // labels "category0", "category1", "category2"
rsb_1.setOpacity(sldBuilder.literalExpression(1.0)); final ColorMap cm = sldBuilder.createColorMap( new String[] { // labels "category", "category", "category"
public Style getDefaultGridCoverageStyle(GridCoverage2D coverage) { Style rasterStyle = null; int numBands = coverage.getNumSampleDimensions(); if (numBands >= 3) { rasterStyle = createRGBStyle(coverage); } else { Color[] colors = new Color[] { new Color(0, 0, 0, 0), Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED }; StatisticsStrategy strategy = new DoubleStrategy(); strategy.setNoData(RasterHelper.getNoDataValue(coverage)); StatisticsVisitor visitor = new StatisticsVisitor(strategy); visitor.visit(coverage, 0); StatisticsVisitorResult ret = visitor.getResult(); String[] descs = new String[] { "No Data", "LL", "LM", "M", "MH", "HH" }; double mean = ret.getMean(); double nodata = Double.parseDouble(ret.getNoData().toString()); double[] values = new double[] { nodata, ret.getMinimum(), (ret.getMinimum() + mean) / 2.0, mean, (ret.getMaximum() + mean) / 2.0, ret.getMaximum() }; StyleBuilder sb = new StyleBuilder(); ColorMap colorMap = sb.createColorMap(descs, values, colors, ColorMap.TYPE_RAMP); rasterStyle = sb.createStyle(sb.createRasterSymbolizer(colorMap, 1.0)); } return rasterStyle; }
@Test public void testRuleTextIntervalOneElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null}, new double[] {10}, new Color[] {Color.RED}, ColorMap.TYPE_INTERVALS); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(1, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("x < 10.0", firstRow.getRuleManager().text); }
@Test public void testRuleTextRampOneElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null}, new double[] {10}, new Color[] {Color.RED}, ColorMap.TYPE_RAMP); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(1, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("", firstRow.getRuleManager().text); }
@Test public void testRuleTextRampTwoElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null}, new double[] {10, 100}, new Color[] {Color.RED, Color.BLUE}, ColorMap.TYPE_RAMP); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(2, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("10.0 >= x", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder lastRow = rows.get(1); assertEquals("100.0 <= x", lastRow.getRuleManager().text); }
@Test public void testRuleTextIntervalsTwoElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null}, new double[] {10, 100}, new Color[] {Color.RED, Color.BLUE}, ColorMap.TYPE_INTERVALS); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(2, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("x < 10.0", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder lastRow = rows.get(1); assertEquals("10.0 <= x < 100.0", lastRow.getRuleManager().text); }
@Test public void testInfiniteOnIntervals() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null, null}, new double[] {Double.NEGATIVE_INFINITY, 50, Double.POSITIVE_INFINITY}, new Color[] {Color.RED, Color.WHITE, Color.BLUE}, ColorMap.TYPE_INTERVALS); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(2, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("x < 50.0", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder midRow = rows.get(1); assertEquals("50.0 <= x", midRow.getRuleManager().text); }
@Test public void testRuleTextIntervalsThreeElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null, null}, new double[] {10, 50, 100}, new Color[] {Color.RED, Color.WHITE, Color.BLUE}, ColorMap.TYPE_INTERVALS); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(3, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("x < 10.0", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder midRow = rows.get(1); assertEquals("10.0 <= x < 50.0", midRow.getRuleManager().text); ColorMapEntryLegendBuilder lastRow = rows.get(2); assertEquals("50.0 <= x < 100.0", lastRow.getRuleManager().text); }
@Test public void testRuleTextRampThreeElements() { StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null, null}, new double[] {10, 50, 100}, new Color[] {Color.RED, Color.WHITE, Color.BLUE}, ColorMap.TYPE_RAMP); Style style = sb.createStyle(sb.createRasterSymbolizer(cmap, 1)); RasterLayerLegendHelper helper = new RasterLayerLegendHelper(request, style, null); List<ColorMapEntryLegendBuilder> rows = new ArrayList<>(helper.getcMapLegendCreator().getBodyRows()); assertEquals(3, rows.size()); ColorMapEntryLegendBuilder firstRow = rows.get(0); assertEquals("10.0 >= x", firstRow.getRuleManager().text); ColorMapEntryLegendBuilder midRow = rows.get(1); assertEquals("50.0 = x", midRow.getRuleManager().text); ColorMapEntryLegendBuilder lastRow = rows.get(2); assertEquals("100.0 <= x", lastRow.getRuleManager().text); }
StyleBuilder sb = new StyleBuilder(); ColorMap cmap = sb.createColorMap( new String[] {null, null, null}, new double[] {Double.NEGATIVE_INFINITY, 50, Double.POSITIVE_INFINITY},