Package org.geotools.styling

Examples of org.geotools.styling.ColorMapImpl


          }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;
              }
             
View Full Code Here


  @Override
  public ColorMap getColorMap() throws Exception{
    sort();
    refresh();
   
    ColorMapImpl colorMap = new ColorMapImpl();
    colorMap.setType(ColorMapImpl.TYPE_VALUES);

    for (ColorEntry c : colors){
      ColorMapEntryBuilder cme = new ColorMapEntryBuilder();
      ColorMapEntry e = cme.color(c.getColor()).opacity(c.getOpacity()).quantity(formatter.formatNumber(c.getValue())).build();
      if (c.getLabel() != null && !c.getLabel().trim().isEmpty()){
        e.setLabel(c.getLabel());
      }
      colorMap.addColorMapEntry(e);
    }
    return colorMap;
   
  }
View Full Code Here

   */
  @Override
  public ColorMap getColorMap() throws Exception{
    sort();
    refresh();
    ColorMapImpl colorMap = new ColorMapImpl();
    colorMap.setType(ColorMapImpl.TYPE_INTERVALS);
   
    List<ColorMapEntry> entries = new ArrayList<ColorMapEntry>();
    for (int i = 0; i < colors.size(); i ++){
      ColorEntry c1 = colors.get(i);
      ColorMapEntryBuilder cme = new ColorMapEntryBuilder();
      ColorMapEntry e = cme.color(c1.getColor()).opacity(c1.getOpacity()).quantity(formatter.formatNumber(c1.getValue())).build();
      if (c1.getLabel() != null && !c1.getLabel().trim().isEmpty()){
        e.setLabel(c1.getLabel());
      }
      entries.add(e);
    }
    ColorMapEntry[] sorted = entries.toArray(new ColorMapEntry[0]);
    SingleBandEditorPage.sortEntries(sorted);
    for (int i = 0; i < sorted.length; i ++){
      colorMap.addColorMapEntry(sorted[i]);
    }
    return colorMap;
  }
View Full Code Here

  @Override
  public ColorMap getColorMap() throws Exception{
    sort();
    refresh();
   
    ColorMapImpl colorMap = new ColorMapImpl();
    colorMap.setType(ColorMapImpl.TYPE_RAMP);
   
    for (int i = 0; i < colors.size(); i ++){
      ColorEntry c1 = colors.get(i);     
      ColorMapEntryBuilder cme = new ColorMapEntryBuilder();
      ColorMapEntry e = cme.color(c1.getColor()).opacity(c1.getOpacity()).quantity(formatter.formatNumber(c1.getValue())).build();
      if (c1.getLabel() != null && !c1.getLabel().trim().isEmpty()){
        e.setLabel(c1.getLabel());
      }
      colorMap.addColorMapEntry(e);
     
    }
    return colorMap;
  }
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

                intervals = true;
            } else {
                intervals = false;
            }
        }
        ColorMap colorMap = new ColorMapImpl();

        // Adding transparent color entry before the min
        double start = min - (intervals ? 0 : 1E-2);
        ColorMapEntry entry = entries[0].getColorMapEntry(start);
        entry.setOpacity(filterFactory.literal(0));
        colorMap.addColorMapEntry(entry);

        if (intervals) {
            colorMap.setType(ColorMap.TYPE_INTERVALS);
            for (int i = 1; i < numEntries - 1; i += 2) {
                colorMap.addColorMapEntry(entries[i].getColorMapEntry(min, range));
            }
        } else {
            colorMap.setType(ColorMap.TYPE_RAMP);
            for (int i = 0; i < numEntries - 1; i ++) {
                colorMap.addColorMapEntry(entries[i].getColorMapEntry(min, range));
            }
        }
        colorMap.addColorMapEntry(entries[numEntries - 1].getColorMapEntry(max));

        // Adding transparent color entry after the max
        ColorMapEntry entryEnd = entries[numEntries - 1].getColorMapEntry(max + 1E-2);
        entryEnd.setOpacity(filterFactory.literal(0));
        colorMap.addColorMapEntry(entryEnd);

        return colorMap;
    }
View Full Code Here

TOP

Related Classes of org.geotools.styling.ColorMapImpl

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.