Package org.geotools.styling

Examples of org.geotools.styling.ColorMap


     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value) throws Exception {

        ColorMap map = styleFactory.createColorMap();
       
        List<Node> children = node.getChildren();
        int i = 0;
        while(!"Value".equals(children.get(i).getComponent().getName())) i++;
       
        ColorMapEntry entry = styleFactory.createColorMapEntry();
        entry.setColor((Expression)children.get(i++).getValue());
        map.addColorMapEntry(entry);
       
        while(i < children.size()) {
            entry = styleFactory.createColorMapEntry();
            entry.setQuantity((Expression)children.get(i).getValue());
            if (i+1 >= children.size()) {
                throw new IllegalArgumentException("Incorrectly specified color map Threshold/Value pair");
            }
           
            entry.setColor((Expression)children.get(i+1).getValue());
            map.addColorMapEntry(entry);

            i+=2;
        }
       
        return map;
View Full Code Here


     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
        throws Exception {
        ColorMap colorMap = styleFactory.createColorMap();
        List entries = (List) node.getChildValues("ColorMapEntry");

        for (Iterator itr = entries.iterator(); itr.hasNext();) {
            colorMap.addColorMapEntry((ColorMapEntry) itr.next());
        }

        return colorMap;
    }
View Full Code Here

        // background bkgColor
        bgColor = LegendUtils.getBackgroundColor(request);

        // colormap element
        final ColorMap cmap = rasterSymbolizer.getColorMap();
        final Builder cmapLegendBuilder = new ColorMapLegendCreator.Builder();
        if (cmap != null && cmap.getColorMapEntries() != null
                && cmap.getColorMapEntries().length > 0) {

            // passing additional options
            cmapLegendBuilder.setAdditionalOptions(request.getLegendOptions());

            // setting type of colormap
            cmapLegendBuilder.setColorMapType(cmap.getType());

            // is this colormap using extended colors
            cmapLegendBuilder.setExtended(cmap.getExtendedColors());

            // setting the requested colormap entries
            cmapLegendBuilder.setRequestedDimension(new Dimension(width, height));

            // setting transparency and background bkgColor
            cmapLegendBuilder.setTransparent(transparent);
            cmapLegendBuilder.setBackgroundColor(bgColor);

            // setting band

            // Setting label font and font bkgColor
            cmapLegendBuilder.setLabelFont(LegendUtils.getLabelFont(request));
            cmapLegendBuilder.setLabelFontColor(LegendUtils.getLabelFontColor(request));

            // set band
            final ChannelSelection channelSelection = rasterSymbolizer.getChannelSelection();
            cmapLegendBuilder.setBand(channelSelection != null ? channelSelection.getGrayChannel()
                    : null);

            // adding the colormap entries
            final ColorMapEntry[] colorMapEntries = cmap.getColorMapEntries();
            for (ColorMapEntry ce : colorMapEntries)
                if (ce != null)
                    cmapLegendBuilder.addColorMapEntry(ce);

            // check the additional options before proceeding
View Full Code Here

   * @throws Exception
   */
  private Style remapStyle(StyleInfo defaultStyle, RasterSymbolizer rasterSymbolizer, double min, double max, int classes, COLORRAMP_TYPE ramp, String layerName) throws Exception {
    StyleBuilder sb = new StyleBuilder();
   
    ColorMap originalColorMap = rasterSymbolizer.getColorMap();
    ColorMap resampledColorMap = null;
   
    int numClasses = originalColorMap.getColorMapEntries().length;
   
//    if (numClasses > 0) {
//      resampledColorMap = originalColorMap;
//      double res = (max - min) / (numClasses - 1);
//      int c = 0;
//      for (ColorMapEntry cmEntry : resampledColorMap.getColorMapEntries()) {
//        cmEntry.setQuantity(sb.literalExpression(min + res * c));
//        c++;
//      }
//    } else
    if (classes > 0) {
      final String[] labels = new String[classes];
      final double[] quantities = new double[classes];
     
      ColorRamp colorRamp = null;

      double res = (max - min) / (classes - 1);
      for (int c = 0; c < classes; c++) {
        labels[c] = "values";
        quantities[c] = min + res * c;
      }
     
      switch (ramp) {
      case RED:
        colorRamp = new RedColorRamp();
        break;
      case BLUE:
        colorRamp = new BlueColorRamp();
        break;
      case GRAY:
        colorRamp = new GrayColorRamp();
        break;
      case RANDOM:
        colorRamp = new RandomColorRamp();
        break;
      }
      colorRamp.setNumClasses(classes);
     
      resampledColorMap = sb.createColorMap(
          labels,
          quantities,
          colorRamp.getRamp().toArray(new Color[1]),
          ColorMap.TYPE_RAMP
      );
      FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(null);
      resampledColorMap.getColorMapEntry(0).setOpacity(filterFactory.literal(0));
    } else {
      return defaultStyle.getStyle();
    }
   
//    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
View Full Code Here

    public Object execute(GetLegendGraphicRequest request, Map<String, Object> map, String colorMap) {

        GridCoverage2D coverage = null;
        try {

            ColorMap cmap = null;

            // Setting up filter functions
            FilterFunction_svgColorMap colorMapFilterFunction = new FilterFunction_svgColorMap();
            FilterFunction_gridCoverageStats statsFilterFunction = new FilterFunction_gridCoverageStats();

            // Only parsing the first layer.
            String layerID = "";
            int digits = DEFAULT_DIGITS;
            Set<String> params = map.keySet();
            for (String param: params) {
                if (param.equalsIgnoreCase("LAYER")) {
                    layerID = (String) map.get("LAYER");
                } else if (param.equalsIgnoreCase("DIGITS")) {
                    digits = Integer.parseInt((String) map.get("DIGITS"));
                }
            }

            final int indexOf = layerID.indexOf(":");
           
            final CoverageInfo coverageInfo = geoserverCatalog.getCoverageByName(new NameImpl(
                    layerID.substring(0, indexOf), layerID.substring(indexOf + 1)));
            List<CoverageDimensionInfo> dimensions = coverageInfo.getDimensions();
            String unit = "";
            if (dimensions != null && !dimensions.isEmpty()) {
                CoverageDimensionInfo dimensionInfo = dimensions.get(0);
                unit = dimensionInfo.getUnit();
            }

            // Getting coverage to parse statistics
            final CoverageStoreInfo storeInfo = coverageInfo.getStore();
            final GridCoverage2DReader reader = (GridCoverage2DReader) geoserverCatalog
                    .getResourcePool().getGridCoverageReader(storeInfo, null);

            GeneralParameterValue[] parameters = parseReadParameters(coverageInfo, map, reader);
            coverage = (GridCoverage2D) reader.read(parameters);

            final double min = (Double) statsFilterFunction.evaluate(coverage, "minimum");
            final double max = (Double) statsFilterFunction.evaluate(coverage, "maximum");

            // Getting a colorMap on top of that
            cmap = (ColorMap) colorMapFilterFunction.evaluate(colorMap, min, max);
            final Builder cmapLegendBuilder = new ColorMapLegendCreator.Builder();
            if (cmap != null && cmap.getColorMapEntries() != null
                    && cmap.getColorMapEntries().length > 0) {

                // setting type of colormap
                cmapLegendBuilder.setColorMapType(cmap.getType());

                // is this colormap using extended colors
                cmapLegendBuilder.setExtended(cmap.getExtendedColors());

                // setting the requested colormap entries
                cmapLegendBuilder.setRequestedDimension(new Dimension(request.getWidth(), request
                        .getHeight()));

                // // setting transparency and background bkgColor
                // cmapLegendBuilder.setTransparent(transparent);
                // cmapLegendBuilder.setBackgroundColor(bgColor);

                // setting band

                // Setting label font and font bkgColor
                cmapLegendBuilder.setLabelFont(LegendUtils.getLabelFont(request));
                cmapLegendBuilder.setLabelFontColor(LegendUtils.getLabelFontColor(request));
                cmapLegendBuilder.setUnit(unit);
                cmapLegendBuilder.setDigits(digits);
                cmapLegendBuilder.setAlternativeColorMapEntryBuilder(true);
                // set band
                // final ChannelSelection channelSelection = rasterSymbolizer.getChannelSelection();
                // cmapLegendBuilder.setBand(channelSelection != null ? channelSelection.getGrayChannel()
                // : null);

                // adding the colormap entries
                final ColorMapEntry[] colorMapEntries = cmap.getColorMapEntries();
                for (ColorMapEntry ce : colorMapEntries)
                    if (ce != null)
                        cmapLegendBuilder.addColorMapEntry(ce);

                // check the additional options before proceeding
View Full Code Here

   */
  private Style remapStyle(StyleInfo defaultStyle, RasterSymbolizer rasterSymbolizer, double min, double max,
          int classes, COLORRAMP_TYPE ramp, String layerName, final int digits, final int colorMapType) throws Exception {
    StyleBuilder sb = new StyleBuilder();
   
    ColorMap originalColorMap = rasterSymbolizer.getColorMap();
    ColorMap resampledColorMap = null;
   
    int numClasses = originalColorMap.getColorMapEntries().length;
   
//    if (numClasses > 0) {
//      resampledColorMap = originalColorMap;
//      double res = (max - min) / (numClasses - 1);
//      int c = 0;
//      for (ColorMapEntry cmEntry : resampledColorMap.getColorMapEntries()) {
//        cmEntry.setQuantity(sb.literalExpression(min + res * c));
//        c++;
//      }
//    } else
    if (classes > 0) {
      final String[] labels = new String[classes+1];
      final double[] quantities = new double[classes+1];
     
      ColorRamp colorRamp = null;
      quantities[0] = min - DEFAULT_MIN_DECREMENT;
      if (colorMapType == ColorMap.TYPE_INTERVALS){
          max = max + DEFAULT_MIN_DECREMENT;
          min = min + DEFAULT_MIN_DECREMENT;
      }
      double res = (max - min) / (classes - 1);
      labels[0] = "transparent";
      final String format ="%." + digits + "f";
      for (int c = 1; c <= classes; c++) {
        quantities[c] = min + res * (c-1);
        labels[c] = String.format(Locale.US, format, quantities[c]);
      }
     
      switch (ramp) {
      case RED:
        colorRamp = new RedColorRamp();
        break;
      case BLUE:
        colorRamp = new BlueColorRamp();
        break;
      case GRAY:
        colorRamp = new GrayColorRamp();
        break;
      case JET:
        colorRamp = new JetColorRamp();
        break;
      case RANDOM:
        colorRamp = new RandomColorRamp();
        break;
      }
      colorRamp.setNumClasses(classes);
     
      resampledColorMap = sb.createColorMap(
          labels,
          quantities,
          colorRamp.getRamp().toArray(new Color[1]),
          colorMapType
      );
      FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(null);
      resampledColorMap.getColorMapEntry(0).setOpacity(filterFactory.literal(0));
    } else {
      return defaultStyle.getStyle();
    }
   
//    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
View Full Code Here

    return symbol;
  }

  /** Internal parse method - made protected for unit testing */
  protected ColorMap parseColorMap(Node root) {
    ColorMap symbol = factory.createColorMap();

    if (root.hasAttributes()) {
      // parsing type attribute
      final NamedNodeMap atts = root.getAttributes();
      Node typeAtt = atts.getNamedItem("type");
      if (typeAtt != null) {
        final String type = typeAtt.getNodeValue();

        if ("ramp".equalsIgnoreCase(type)) {
          symbol.setType(ColorMap.TYPE_RAMP);
        } else if ("intervals".equalsIgnoreCase(type)) {
          symbol.setType(ColorMap.TYPE_INTERVALS);
        } else if ("values".equalsIgnoreCase(type)) {
          symbol.setType(ColorMap.TYPE_VALUES);
        } else if (LOGGER.isLoggable(Level.FINE))
          LOGGER.fine(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2,
              "ColorMapType", type));

      }

      // parsing extended colors
      typeAtt = atts.getNamedItem("extended");
      if (typeAtt != null) {
        final String type = typeAtt.getNodeValue();

        if ("true".equalsIgnoreCase(type)) {
          symbol.setExtendedColors(true);
        } else if ("false".equalsIgnoreCase(type)) {
          symbol.setExtendedColors(false);
        } else if (LOGGER.isLoggable(Level.FINE))
          LOGGER.fine(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2,
              "Extended", type));

      }
    }

    NodeList children = root.getChildNodes();
    final int length = children.getLength();
    for (int i = 0; i < length; i++) {
      Node child = children.item(i);

      if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
        continue;
      }
      String childName = child.getLocalName();
      if (childName == null) {
        childName = child.getNodeName();
      }

      if (childName.equalsIgnoreCase("ColorMapEntry")) {
        symbol.addColorMapEntry(parseColorMapEntry(child));
      }
    }

    return symbol;
  }
View Full Code Here

    }

    @Test
    public void testSvgColorMapFilterFunctionRGB() throws Exception {
        final FilterFunction_svgColorMap func = new FilterFunction_svgColorMap();
        final ColorMap colorMap = (ColorMap) func.evaluate("rgb(0,0,255);rgb(0,255,0);rgb(255,0,0)", 10, 100);
        final ColorMapEntry[] entries = colorMap.getColorMapEntries();

        check(entries);
      }
View Full Code Here

      }

    @Test
    public void testSvgColorMapFilterFunctionHEX() throws Exception {
        final FilterFunction_svgColorMap func = new FilterFunction_svgColorMap();
        final ColorMap colorMap = (ColorMap) func.evaluate("#0000FF;#00FF00;#FF0000", 10, 100);
        final ColorMapEntry[] entries = colorMap.getColorMapEntries();

        check(entries);
      }
View Full Code Here

        // background bkgColor
        bgColor = LegendUtils.getBackgroundColor(request);

        // colormap element
        final ColorMap cmap = rasterSymbolizer.getColorMap();
        final Builder cmapLegendBuilder = new ColorMapLegendCreator.Builder();
        if (cmap != null && cmap.getColorMapEntries() != null
                && cmap.getColorMapEntries().length > 0) {

            // passing additional options
            cmapLegendBuilder.setAdditionalOptions(request.getLegendOptions());

            // setting type of colormap
            cmapLegendBuilder.setColorMapType(cmap.getType());

            // is this colormap using extended colors
            cmapLegendBuilder.setExtended(cmap.getExtendedColors());

            // setting the requested colormap entries
            cmapLegendBuilder.setRequestedDimension(new Dimension(width, height));

            // setting transparency and background bkgColor
            cmapLegendBuilder.setTransparent(transparent);
            cmapLegendBuilder.setBackgroundColor(bgColor);

            // setting band

            // Setting label font and font bkgColor
            cmapLegendBuilder.setLabelFont(LegendUtils.getLabelFont(request));
            cmapLegendBuilder.setLabelFontColor(LegendUtils.getLabelFontColor(request));

            // set band
            final ChannelSelection channelSelection = rasterSymbolizer.getChannelSelection();
            cmapLegendBuilder.setBand(channelSelection != null ? channelSelection.getGrayChannel()
                    : null);

            // adding the colormap entries
            final ColorMapEntry[] colorMapEntries = cmap.getColorMapEntries();
            for (ColorMapEntry ce : colorMapEntries)
                if (ce != null)
                    cmapLegendBuilder.addColorMapEntry(ce);

            // check the additional options before proceeding
View Full Code Here

TOP

Related Classes of org.geotools.styling.ColorMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.