Package org.geotools.styling

Examples of org.geotools.styling.NamedLayer


    public Object decode(Object input) throws Exception {
        Parser p = new Parser(sldConfiguration);

        // extract the first style in the first sld
        StyledLayerDescriptor sld = (StyledLayerDescriptor) p.parse(new StringReader((String) input));
        NamedLayer styledLayer = (NamedLayer) sld.getStyledLayers()[0];
        return styledLayer.getStyles()[0];
    }
View Full Code Here


    final StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
    final Style style = styleFactory.createStyle();
    final List<FeatureTypeStyle> fts = style.featureTypeStyles();
    fts.clear();
    fts.add(styleFactory.createFeatureTypeStyle(rules));
    final NamedLayer nl = styleFactory.createNamedLayer();
    nl.setName("");
    nl.addStyle(style);

    final StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    sld.setStyledLayers(new StyledLayer[] {
      nl
    });
View Full Code Here

      } else if (childName.equalsIgnoreCase("Title")) {
        sld.setTitle(getFirstChildValue(child));
      } else if (childName.equalsIgnoreCase("Abstract")) {
        sld.setAbstract(getFirstChildValue(child));
      } else if (childName.equalsIgnoreCase("NamedLayer")) {
        NamedLayer layer = parseNamedLayer(child);
        sld.addStyledLayer(layer);
      } else if (childName.equalsIgnoreCase("UserLayer")) {
        StyledLayer layer = parseUserLayer(child);
        sld.addStyledLayer(layer);
      }
View Full Code Here

   * </p>
   *
   * @param root
   */
  private NamedLayer parseNamedLayer(Node root) {
    NamedLayer layer = new NamedLayerImpl();

    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("Name")) {
        layer.setName(getFirstChildValue(child));
      } else if (childName.equalsIgnoreCase("NamedStyle")) {
        NamedStyle style = parseNamedStyle(child);
        layer.addStyle(style);
      } else if (childName.equalsIgnoreCase("UserStyle")) {
        Style user = parseStyle(child);
        layer.addStyle(user);
      } else if (childName.equalsIgnoreCase("LayerFeatureConstraints")) {
        layer.setLayerFeatureConstraints(parseLayerFeatureConstraints(child));
      }
    }

    return layer;
  }
View Full Code Here

    public Object decode(InputStream input) throws Exception {
        Parser p = new Parser(sldConfiguration);

        // extract the first style in the first sld
        StyledLayerDescriptor sld = (StyledLayerDescriptor) p.parse(input);
        NamedLayer styledLayer = (NamedLayer) sld.getStyledLayers()[0];
        return styledLayer.getStyles()[0];
    }
View Full Code Here

    @Override
    public void encode(Object obj, ContentHandler handler) throws Exception {
        StyleFactory sf = CommonFactoryFinder.getStyleFactory(null);
        StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
        NamedLayer nl = sf.createNamedLayer();
        nl.setName("");
        nl.styles().add((Style) obj);
        sld.setStyledLayers(new StyledLayer[] { nl });

        Encoder e = new Encoder(sldConfiguration);
        e.encode(sld, element, handler);
    }
View Full Code Here

    public Object decode(Object input) throws Exception {
        Parser p = new Parser(sldConfiguration);

        // extract the first style in the first sld
        StyledLayerDescriptor sld = (StyledLayerDescriptor) p.parse(new StringReader((String) input));
        NamedLayer styledLayer = (NamedLayer) sld.getStyledLayers()[0];
        return styledLayer.getStyles()[0];
    }
View Full Code Here

    private Style parseStyle(String styleName) throws IOException {
        SLDParser parser = new SLDParser(CommonFactoryFinder.getStyleFactory());
        parser.setInput(RasterSymbolizerVisitorTest.class.getResource(styleName));
        StyledLayerDescriptor sld = parser.parseSLD();
        NamedLayer ul = (NamedLayer) sld.getStyledLayers()[0];
        return ul.getStyles()[0];
    }
View Full Code Here

        try {
            StyleFactory factory = CommonFactoryFinder.getStyleFactory(null);
            List<StyledLayer> layers = new ArrayList<StyledLayer>();
            for (String layerName : request.getLayers()) {
                NamedLayer namedLayer = factory.createNamedLayer();
                layers.add(namedLayer);
                namedLayer.setName(layerName);
                LayerGroupInfo group = wms.getLayerGroupByName(layerName);
                LayerInfo layer = wms.getLayerByName(layerName);
                if (group != null) {
                    // nothing to do, groups have no style
                } else if (layer != null) {
                    Style style = layer.getDefaultStyle().getStyle();
                    // add the default style first
                    style = cloneStyle(style);
                    style.setDefault(true);
                    style.setName(layer.getDefaultStyle().getName());
                    namedLayer.styles().add(style);
                    // add alternate styles
                    for (StyleInfo si : layer.getStyles()) {
                        style = cloneStyle(si.getStyle());
                        style.setName(si.getName());
                        namedLayer.styles().add(style);
                    }
                } else {
                    // we should really add a code and a locator...
                    throw new ServiceException("Unknown layer " + layerName);
                }
View Full Code Here

    SLD3DParser p = parser(styleFile);
    StyledLayerDescriptor sld = p.parseSLD();
    if (sld.getStyledLayers().length == 0) {
      Style[] style = p.readDOM();
      if (style.length > 0) {
        NamedLayer l = styleFactory.createNamedLayer();
        l.addStyle(style[0]);
        sld.addStyledLayer(l);
      }
    }
    return Styles.style(sld);
  }
View Full Code Here

TOP

Related Classes of org.geotools.styling.NamedLayer

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.