Package org.geotools.styling

Examples of org.geotools.styling.ColorMap


            style.setName(layer.getName());
            ArrayList<CoverageRule> listOfRules = new ArrayList<CoverageRule>();
            // Rule ruleToUpdate = SLDs.getRasterSymbolizerRule(style);
            RasterSymbolizer rasterSymbolizer = SLDs.rasterSymbolizer(style);

            ColorMap colorMap = rasterSymbolizer.getColorMap();
            ColorMapEntry[] colorMapEntries = colorMap.getColorMapEntries();
            for( int i = 0; i < colorMapEntries.length - 1; i = i + 2 ) {
                double fromQuantity = getQuantity(colorMapEntries[i]);
                java.awt.Color f = getColor(colorMapEntries[i]);
                double fromOpacity = getOpacity(colorMapEntries[i]);
View Full Code Here


                // }

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

                ColorMap colorMap = sf.createColorMap();
                ArrayList<CoverageRule> rulesList = colorRulesEditor.getRulesList();
                for( int i = 0; i < rulesList.size(); i++ ) {
                    CoverageRule coverageRule = rulesList.get(i);
                    if (!coverageRule.isActive()) {
                        continue;
                    }
                    Color fromColor = coverageRule.getFromColor();
                    Color toColor = coverageRule.getToColor();
                    double[] values = coverageRule.getFromToValues();
                    double opacity = coverageRule.getOpacity();

                    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(values[0]);
                    Expression toExpr = sB.literalExpression(values[1]);
                    Expression opacityExpr = sB.literalExpression(opacity);

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

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

                rasterSym.setColorMap(colorMap);

                /*
 
View Full Code Here

   * @param imageSize size of icon to create for legend entry
   * @return list of legend entries in the first color map found or
   * null if no color map found
   */
  public static List<LegendEntry> findEntries(FeatureTypeStyle[] style, Dimension imageSize, Dimension textSize){
    ColorMap cm = findColorMap(style);
    if (cm == null || cm.getColorMapEntries().length == 0){
      return null;
    }
    return findEntries(cm, imageSize, textSize);
   
  }
View Full Code Here

          Object x = ((IStructuredSelection)cmbPalette.getSelection()).getFirstElement();
          if (x instanceof BrewerPalette){
            BrewerPalette palette = (BrewerPalette) ((IStructuredSelection)cmbPalette.getSelection()).getFirstElement();
            getCurrentSelection().setColorPalette(palette, reverseColors);
          }else if (x instanceof PredefinedColorRule){
            ColorMap cm = ((PredefinedColorRule)x).getColorMap();
            if (cm != null && getCurrentSelection() != null){
              //flip colors
              if (reverseColors){
                ColorMap reverse = new ColorMapImpl();
                for (int i = 0; i < cm.getColorMapEntries().length; i ++){
                  ColorMapEntry entry = cm.getColorMapEntries()[i];
                  ColorMapEntry clone = new ColorMapEntryImpl();
                  clone.setColor(cm.getColorMapEntry(cm.getColorMapEntries().length - 1 - i).getColor());
                  clone.setLabel(entry.getLabel());
                  clone.setQuantity(entry.getQuantity());
                  clone.setOpacity(entry.getOpacity());
                  reverse.addColorMapEntry(clone);
                 
                }
                cm = reverse;
              }
             
              getCurrentSelection().init(cm);
            }
          }
        }
      }
    });
   
    Label lblSep = new Label(linkPnl, SWT.SEPARATOR | SWT.VERTICAL);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
    gd.heightHint = 10;
    lblSep.setLayoutData(gd);
   
    lnk = new Link(linkPnl, SWT.NONE);
    lnk.setText("<a>" + Messages.SingleBandEditorPage_FormatExportLink + "</a>")//$NON-NLS-1$ //$NON-NLS-2$
    lnk.addSelectionListener(new SelectionAdapter() {
     
      @Override
      public void widgetSelected(SelectionEvent e) {
        getFormat();
      }
    });
   
    Link lnk2 = new Link(linkPnl, SWT.NONE);
    lnk2.setText("<a>" + Messages.SingleBandEditorPage_OneClickExportLink + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$
    lnk2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
    lnk2.setToolTipText(Messages.SingleBandEditorPage_OneClickTooltip);
    lnk2.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        oneClickExport();
      }
    });
   
   
    cmbThemingStyle.getCombo().addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        IColorMapTypePanel panel = getCurrentSelection();
        if (panel != null){
          ((StackLayout)tableComp.getLayout()).topControl = stacks.get(panel);
          tableComp.layout();
          btnTest.setText(panel.getComputeValuesLabel());
          btnTest.getParent().layout();
         

          Object x = ((IStructuredSelection)cmbPalette.getSelection()).getFirstElement();;
          if (x instanceof BrewerPalette){
            BrewerPalette palette = (BrewerPalette) x;
            getCurrentSelection().setInitialColorPalette(palette);
          }else if (x instanceof PredefinedColorRule){
            ColorMap cm = ((PredefinedColorRule)x).getColorMap();
            if (cm != null && getCurrentSelection() != null){
              getCurrentSelection().init(cm);
            }
           
          }
        }
      }
    });
   
   
    cmbPalette.addSelectionChangedListener(new ISelectionChangedListener() {     
      @Override
      public void selectionChanged(SelectionChangedEvent event) {
        Object x = ((IStructuredSelection)cmbPalette.getSelection()).getFirstElement();;
        if (x instanceof BrewerPalette){
          BrewerPalette palette = (BrewerPalette) x;
          if (getCurrentSelection() != null){
            getCurrentSelection().setColorPalette(palette, reverseColors);
          }
        }else if (x instanceof PredefinedColorRule){
          ColorMap cm = ((PredefinedColorRule)x).getColorMap();
          if (cm != null && getCurrentSelection() != null){
            getCurrentSelection().init(cm);
          }
        }
       
View Full Code Here

   * @throws Exception
   */
  private void updateStyle() throws Exception{
        RasterSymbolizer rasterSym = sf.createRasterSymbolizer();
              
        ColorMap colorMap = getCurrentSelection().getColorMap();
        rasterSym.setColorMap(colorMap);

        Style newStyle = SLD.wrapSymbolizers(rasterSym);
        newStyle.setName(((Layer)getSelectedLayer()).getName() );
        StyleBlackboard styleBlackboard = getSelectedLayer().getStyleBlackboard();
View Full Code Here

    RasterSymbolizer symbolizer = SLD.rasterSymbolizer(style);
    if (symbolizer == null || symbolizer.getColorMap() == null){
      //no symbolizer
     
    }else{
      ColorMap cm = symbolizer.getColorMap();
      for (IColorMapTypePanel pnl : stylePanels){
        if (pnl.canSupport(cm.getType())){
          pnl.init(cm);
          cmbThemingStyle.setSelection(new StructuredSelection(pnl));
          cmbThemingStyle.getControl().notifyListeners(SWT.Selection, new Event());
        }
      }
      if (formatter.getRawDataType() == DataType.INTEGER){
        //if some of the entries are doubles we want to format in double
        //regardless of the fact that the raster is an integer raster.
        try{
          for (ColorMapEntry e : cm.getColorMapEntries()){
            Double dvalue = (Double) e.getQuantity().evaluate(null, Double.class);
            Integer ivalue = (Integer) e.getQuantity().evaluate(null, Integer.class);
            if (ivalue.doubleValue() != dvalue){
              formatter.setDataType(DataType.DOUBLE);
            }
View Full Code Here

  }

  private ColorMap parseRulesValuesList(final String[][] colorRules)
      throws IOException {

    ColorMap cm = new ColorMapImpl();
    ExpressionBuilder builder = new ExpressionBuilder();
    if (colorRules[0].length == 3) {
      if (dataMin == null && dataMax == null) {
        minMaxJob.schedule();
        try {
          minMaxJob.join();
        } catch (InterruptedException e) {
          SLDPlugin.log(e.getMessage(), e);
          return null;
        }
      }
      /*
       * the colorrules are without values, so we ramp through them over
       * the range.
       */
      if (dataMin == null) {
        dataMin = -100.0;
      }
      if (dataMax == null) {
        dataMax = 5000.0;
      }

      // calculate the color increment
      float rinc = (float) (dataMax - dataMin)
          / (float) (colorRules.length - 1);

      for (int i = 0; i < colorRules.length - 1; i++) {
        try {
          double to = dataMin + ((i + 1) * rinc);
          Color toColor = new Color(
              Integer.parseInt(colorRules[i + 1][0]),
              Integer.parseInt(colorRules[i + 1][1]),
              Integer.parseInt(colorRules[i + 1][2]));
          if (i == 0) {
            double from = dataMin + (i * rinc);
            Color fromColor = new Color(
                Integer.parseInt(colorRules[i][0]),
                Integer.parseInt(colorRules[i][1]),
                Integer.parseInt(colorRules[i][2]));

            ColorMapEntryImpl cme = new ColorMapEntryImpl();
            cme.setColor((Expression) builder.literal(fromColor)
                .build());
            cme.setQuantity((Expression) builder.literal(from)
                .build());
            cm.addColorMapEntry(cme);
          }
          ColorMapEntryImpl cme = new ColorMapEntryImpl();
          cme.setColor((Expression) builder.literal(toColor).build());
          cme.setQuantity((Expression) builder.literal(to).build());
          cm.addColorMapEntry(cme);

        } catch (NumberFormatException e) {
          SLDPlugin.log(e.getMessage(), e);
          continue;
        }
      }

    } else {
      /*
       * in this case we have also the values for the range defined and
       * the color rule has to be "v1 r1 g1 b1 v2 r2 g2 b2".
       */
      if (colorRules[0].length != 8) {
        throw new IOException(
            "The colortable can have records of 3 or 8 columns. Check your colortables."); //$NON-NLS-1$
      }

      for (int i = 0; i < colorRules.length; i++) {
        try {
          double to = Double.parseDouble(colorRules[i][4]);
          Color toColor = new Color(
              Integer.parseInt(colorRules[i][5]),
              Integer.parseInt(colorRules[i][6]),
              Integer.parseInt(colorRules[i][7]));
          if (i == 0) {
            double from = Double.parseDouble(colorRules[i][0]);
            Color fromColor = new Color(
                Integer.parseInt(colorRules[i][1]),
                Integer.parseInt(colorRules[i][2]),
                Integer.parseInt(colorRules[i][3]));

            ColorMapEntryImpl cme = new ColorMapEntryImpl();
            cme.setColor((Expression) builder.literal(fromColor)
                .build());
            cme.setQuantity((Expression) builder.literal(from)
                .build());
            cm.addColorMapEntry(cme);
          }
          ColorMapEntryImpl cme = new ColorMapEntryImpl();
          cme.setColor((Expression) builder.literal(toColor).build());
          cme.setQuantity((Expression) builder.literal(to).build());
          cm.addColorMapEntry(cme);
        } catch (NumberFormatException e) {
          SLDPlugin.log(e.getMessage(), e);
          continue;
        }
      }
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

        assertSimpleStyle(collector);

        // check the symbolizer
        RasterSymbolizer rs = (RasterSymbolizer) collector.symbolizers.get(0);
        assertNull(rs.getChannelSelection());
        ColorMap cmap = rs.getColorMap();
        assertEquals(ColorMap.TYPE_RAMP, cmap.getType());
        assertFalse(cmap.getExtendedColors());
        assertEntry("#008000", 70.0, 1.0, null, cmap.getColorMapEntry(0));
        assertEntry("#663333", 256.0, 1.0, null, cmap.getColorMapEntry(1));
    }
View Full Code Here

        // check the symbolizer
        RasterSymbolizer rs = (RasterSymbolizer) collector.symbolizers.get(0);
        assertEquals(0.3, rs.getOpacity().evaluate(null, Double.class), 0.0);
        assertNull(rs.getChannelSelection());
        ColorMap cmap = rs.getColorMap();
        assertEquals(ColorMap.TYPE_RAMP, cmap.getType());
        assertFalse(cmap.getExtendedColors());
        assertEntry("#008000", 70.0, 1.0, null, cmap.getColorMapEntry(0));
        assertEntry("#663333", 256.0, 1.0, null, cmap.getColorMapEntry(1));
    }
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.