Package org.geotools.styling

Examples of org.geotools.styling.StyledLayerDescriptor


  }

  public static StyledLayerDescriptor createDefaultSLD(Style style) {
    StyleFactory factory = CommonFactoryFinder.getStyleFactory();

    StyledLayerDescriptor sld = factory.createStyledLayerDescriptor();
    UserLayer layer = factory.createUserLayer();

    // FeatureTypeConstraint ftc =
    // styleFactory.createFeatureTypeConstraint(null, Filter.INCLUDE, null);
    layer.setLayerFeatureConstraints(new FeatureTypeConstraint[] { null });
    sld.addStyledLayer(layer);
    layer.addUserStyle((org.geotools.styling.Style) style);

    return sld;
  }
View Full Code Here


    //
    // We are using the GeoTools styleFactory that allows access to get/set methods
    org.geotools.styling.StyleFactory sf = CommonFactoryFinder.getStyleFactory();
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
   
    StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
    sld.setName("sld");
    sld.setTitle("Example");
    sld.setAbstract("Example Style Layer Descriptor");
   
    UserLayer layer = sf.createUserLayer();
    layer.setName("layer");
   
    //
    // define constraint limited what features the sld applies to
    FeatureTypeConstraint constraint = sf.createFeatureTypeConstraint("Feature", Filter.INCLUDE,
            null);
   
    layer.layerFeatureConstraints().add(constraint);
   
    //
    // create a "user defined" style
    Style style = sf.createStyle();
    style.setName("style");
    style.getDescription().setTitle("User Style");
    style.getDescription().setAbstract("Definition of Style");
   
    //
    // define feature type styles used to actually define how features are rendered
    FeatureTypeStyle featureTypeStyle = sf.createFeatureTypeStyle();
   
    // RULE 1
    // first rule to draw cities
    Rule rule1 = sf.createRule();
    rule1.setName("rule1");
    rule1.getDescription().setTitle("City");
    rule1.getDescription().setAbstract("Rule for drawing cities");
    rule1.setFilter(ff.less(ff.property("POPULATION"), ff.literal(50000)));
   
    //
    // create the graphical mark used to represent a city
    Stroke stroke = sf.stroke(ff.literal("#000000"), null, null, null, null, null, null);
    Fill fill = sf.fill(null, ff.literal(Color.BLUE), ff.literal(1.0));
   
    // OnLineResource implemented by gt-metadata - so no factory!
    OnLineResourceImpl svg = new OnLineResourceImpl(new URI("file:city.svg"));
    svg.freeze(); // freeze to prevent modification at runtime
   
    OnLineResourceImpl png = new OnLineResourceImpl(new URI("file:city.png"));
    png.freeze(); // freeze to prevent modification at runtime
   
    //
    // List of symbols is considered in order with the rendering engine choosing
    // the first one it can handle. Allowing for svg, png, mark order
    List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
    symbols.add(sf.externalGraphic(svg, "svg", null)); // svg preferred
    symbols.add(sf.externalGraphic(png, "png", null)); // png preferred
    symbols.add(sf.mark(ff.literal("circle"), fill, stroke)); // simple circle backup plan
   
    Expression opacity = null; // use default
    Expression size = ff.literal(10);
    Expression rotation = null; // use default
    AnchorPoint anchor = null; // use default
    Displacement displacement = null; // use default
   
    // define a point symbolizer of a small circle
    Graphic city = sf.graphic(symbols, opacity, size, rotation, anchor, displacement);
    PointSymbolizer pointSymbolizer = sf.pointSymbolizer("point", ff.property("the_geom"), null,
            null, city);
   
    rule1.symbolizers().add(pointSymbolizer);
   
    featureTypeStyle.rules().add(rule1);
   
    //
    // RULE 2 Default
   
    List<GraphicalSymbol> dotSymbols = new ArrayList<GraphicalSymbol>();
    dotSymbols.add(sf.mark(ff.literal("circle"), null, null));
    Graphic dotGraphic = sf.graphic(dotSymbols, null, ff.literal(3), null, null, null);
    PointSymbolizer dotSymbolizer = sf.pointSymbolizer("dot", null, null, null, dotGraphic);
    List<org.opengis.style.Symbolizer> symbolizers = new ArrayList<org.opengis.style.Symbolizer>();
    symbolizers.add(dotSymbolizer);
    Filter other = null; // null will mark this rule as "other" accepting all remaining features
    Rule rule2 = sf.rule("default", null, null, Double.MIN_VALUE, Double.MAX_VALUE, symbolizers,
            other);
    featureTypeStyle.rules().add(rule2);
   
    style.featureTypeStyles().add(featureTypeStyle);
   
    layer.userStyles().add(style);
   
    sld.layers().add(layer);
    // styleFactoryExample end
}
View Full Code Here

private void sldExample() {
    // sldExample start
    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
   
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    sld.setName("example");
    sld.setAbstract("Example Style Layer Descriptor");
   
    UserLayer layer = styleFactory.createUserLayer();
    layer.setName("layer");
   
    FeatureTypeConstraint constraint = styleFactory.createFeatureTypeConstraint("Feature",
            Filter.INCLUDE, null);
   
    layer.layerFeatureConstraints().add(constraint);
   
    Style style = styleFactory.createStyle();
   
    style.getDescription().setTitle("Style");
    style.getDescription().setAbstract("Definition of Style");
   
    // define feature type styles used to actually
    // define how features are rendered
    //
    layer.userStyles().add(style);
   
    sld.layers().add(layer);
    // sldExample end
}
View Full Code Here

   
    // the xml instance document above
    InputStream xml = new FileInputStream("markTest.sld");
   
    // parse
    StyledLayerDescriptor sld = (StyledLayerDescriptor) parser.parse(xml);
    // parseSLD end
}
View Full Code Here

    public Object getCopy() {
    return pages.peek();
  }
 
    public void visit(StyledLayerDescriptor sld) {
        StyledLayerDescriptor copy = null;

        StyledLayer[] layers = sld.getStyledLayers();
        StyledLayer[] layersCopy = new StyledLayer[layers.length];
        final int length=layers.length;
        for (int i = 0; i < length; i++) {
            if (layers[i] instanceof UserLayer) {
                ((UserLayer) layers[i]).accept(this);
                layersCopy[i] = (UserLayer) pages.pop();
            } else if (layers[i] instanceof NamedLayer) {
                ((NamedLayer) layers[i]).accept(this);
                layersCopy[i] = (NamedLayer) pages.pop();
            }
        }

        copy = sf.createStyledLayerDescriptor();
        copy.setAbstract(sld.getAbstract());
        copy.setName(sld.getName());
        copy.setTitle(sld.getTitle());
        copy.setStyledLayers(layersCopy);

        if( STRICT && !copy.equals( sld )){
            throw new IllegalStateException("Was unable to duplicate provided SLD:"+sld );
        }
        pages.push(copy);
    }
View Full Code Here

     * @param style the style to convert.
     * @return the style string.
     * @throws Exception
     */
    public static String styleToString( Style style ) throws Exception {
        StyledLayerDescriptor sld = sf.createStyledLayerDescriptor();
        UserLayer layer = sf.createUserLayer();
        layer.setLayerFeatureConstraints(new FeatureTypeConstraint[]{null});
        sld.addStyledLayer(layer);
        layer.addUserStyle(style);

        SLDTransformer aTransformer = new SLDTransformer();
        aTransformer.setIndentation(4);
        String xml = aTransformer.transform(sld);
View Full Code Here

    }

    public void test() throws Exception {
        SLDMockData.styledLayerDescriptor(document, document);

        StyledLayerDescriptor sld = (StyledLayerDescriptor) parse();
        assertNotNull(sld);

        assertEquals("theName", sld.getName());
        assertEquals("theTitle", sld.getTitle());
        assertEquals("theAbstract", sld.getAbstract());

        assertEquals(2, sld.getStyledLayers().length);
    }
View Full Code Here

public class SLDTest extends TestCase {
   
    public void test() throws Exception {
        Parser parser = new Parser(new SLDConfiguration());

        StyledLayerDescriptor sld = (StyledLayerDescriptor) parser.parse(getClass()
                                                                             .getResourceAsStream("example-sld.xml"));

        assertEquals(1, sld.getStyledLayers().length);

        NamedLayer layer = (NamedLayer) sld.getStyledLayers()[0];
        assertEquals("OCEANSEA_1M:Foundation", layer.getName());
        assertEquals(1, layer.getStyles().length);

        Style style = layer.getStyles()[0];
        assertEquals("GEOSYM", style.getName());
View Full Code Here

     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
        throws Exception {
        StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();

        //&lt;xsd:element ref="sld:Name" minOccurs="0"/&gt;
        if (node.hasChild("Name")) {
            sld.setName((String) node.getChildValue("Name"));
        }

        //&lt;xsd:element ref="sld:Title" minOccurs="0"/&gt;
        if (node.hasChild("Title")) {
            InternationalString intString = (InternationalString) node
                    .getChildValue("Title");
            sld.setTitle(intString.toString());
        }

        //&lt;xsd:element ref="sld:Abstract" minOccurs="0"/&gt;
        if (node.hasChild("Abstract")) {
            InternationalString intString = (InternationalString) node
                    .getChildValue("Abstract");
            sld.setAbstract(intString.toString());
        }

        //&lt;xsd:choice minOccurs="0" maxOccurs="unbounded"&gt;
        //     &lt;xsd:element ref="sld:NamedLayer"/&gt;
        //     &lt;xsd:element ref="sld:UserLayer"/&gt;
        //&lt;/xsd:choice&gt;
        StyledLayer[] layers = null;

        if (node.hasChild(NamedLayer.class)) {
            List namedLayers = node.getChildValues(NamedLayer.class);
            layers = (StyledLayer[]) namedLayers.toArray(new StyledLayer[namedLayers.size()]);
        } else if (node.hasChild(UserLayer.class)) {
            List userLayers = node.getChildValues(UserLayer.class);
            layers = (StyledLayer[]) userLayers.toArray(new StyledLayer[userLayers.size()]);
        }

        sld.setStyledLayers(layers);

        //&lt;xsd:attribute name="version" type="xsd:string" use="required" fixed="1.0.0"/&gt;
        //TODO: no version?
        return sld;
    }
View Full Code Here

                                </se:FeatureTypeStyle>
                        </UserStyle>
                </NamedLayer>
        </StyledLayerDescriptor>*/

        StyledLayerDescriptor sld = (StyledLayerDescriptor) parse("example-sld.xml");
        assertEquals(1, sld.getStyledLayers().length);
       
        NamedLayer l = (NamedLayer) sld.getStyledLayers()[0];
        assertEquals("OCEANSEA_1M:Foundation", l.getName());
       
        assertEquals(1, l.getStyles().length);
        Style s = l.getStyles()[0];
        assertEquals("GEOSYM", s.getName());
View Full Code Here

TOP

Related Classes of org.geotools.styling.StyledLayerDescriptor

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.