Package org.geotools.styling

Examples of org.geotools.styling.StyleFactory


            Layer layer = spatialDatabase.getLayer(typeName);
            Object obj = layer.getStyle();
            if(obj instanceof Style) {
              result = (Style)result;
            } else if (obj instanceof File || obj instanceof String) {
              StyleFactory styleFactory = new StyleFactoryImpl();
              SLDParser parser = new SLDParser(styleFactory);
              try {
                if(obj instanceof File) {
                  parser.setInput(new FileReader((File)obj));
                }else{
View Full Code Here


  private static byte[] encodeRules(
      final Rule[] rules ) {
    // all that we care about is the rules, so encode a minimal set of an
    // sld to represent a set of rules
    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
    });
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final SLDTransformer writer = new SLDTransformer();
View Full Code Here

        return styleFactory.createFill(color, backgroundColor, opacity, graphicFill);
    }

    public static Style injectProperties(Style style, Map<String, String> properties) {
        List<List<MiniRule>> ftStyles = MiniRule.minify(style);
        StyleFactory factory = CommonFactoryFinder.getStyleFactory();
        return MiniRule.makeStyle(factory, new IconPropertyInjector(properties).injectProperties(ftStyles));
    }
View Full Code Here

        return styledLayer.getStyles()[0];
    }

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

       StyleInfo style = l.getDefaultStyle();
       Style s = style.getStyle();

       FeatureTypeStyle fts = s.featureTypeStyles().get(0);
       FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
       StyleFactory sf = CommonFactoryFinder.getStyleFactory();
       for (int i = 0; i < 21; i++) {
           Filter f = ff.equals(ff.literal(1), ff.literal(1));
           Rule r = sf.createRule();
           r.setFilter(f);
           r.symbolizers().add(sf.createPolygonSymbolizer());
           fts.rules().add(r);
       }

       cat.getResourcePool().writeStyle(style, s);
       cat.save(style);
View Full Code Here

        if (request.getSldVer() != null && "".equals(request.getSldVer())
                && !"1.0.0".equals(request.getSldVer()))
            throw new ServiceException("SLD version " + request.getSldVer() + " not supported");

        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);
                }
            }

            StyledLayerDescriptor sld = factory.createStyledLayerDescriptor();
            sld.setStyledLayers((StyledLayer[]) layers.toArray(new StyledLayer[layers.size()]));

            return sld;
        } catch (IOException e) {
            throw new ServiceException(e);
View Full Code Here

            /**
             * Override so it does not try to load a file from disk
             */
            @Override
            public Style getStyle() throws IOException {
                StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
                Style style = styleFactory.createStyle();
                style.setName("Default Style");
                return style;
            }
        };
        defaultStyle.setFilename("defaultStyleFileName");
View Full Code Here

     */
    static final int THRESHOLD = 400;

    @Test
    public void testSimpleCircle() throws Exception {
        StyleFactory sfact =  CommonFactoryFinder.getStyleFactory();
        FilterFactory ffact =  CommonFactoryFinder.getFilterFactory();
       
        Mark m = sfact.mark(
                ffact.literal("circle"),
                sfact.fill(null, ffact.literal("#FF0000"), null),
                sfact.stroke(ffact.literal("#000000"), null, ffact.literal(1), null, null, null, null));
       
        Graphic g = sfact.graphic(Arrays.asList((GraphicalSymbol)m), Expression.NIL, Expression.NIL, Expression.NIL, null, null);
        Symbolizer symb = sfact.pointSymbolizer(null, ffact.property(null), null, null, g);
        Rule r = sfact.rule(null, null, null, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Arrays.asList(symb), null);
        FeatureTypeStyle fts = sfact.featureTypeStyle(null, null, null, Collections.<Name> emptySet(), Collections.<SemanticType> emptySet(), Arrays.asList(r));
        Style s = sfact.style(null, null, true, Arrays.asList(fts), null);
       
        BufferedImage img = IconRenderer.renderIcon((org.geotools.styling.Style)s);
       
        // Default mark size, plus border, plus padding, times rendering scale, plus extra padding.
        final int size = (16+1+1)*4+1;
 
View Full Code Here

     * @param sldName
     * @return
     * @throws IOException
     */
    private Style readSLD(String sldName) throws IOException {
        StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
        SLDParser stylereader = new SLDParser(styleFactory, getClass().getResource(
                sldName));
        Style[] readStyles = stylereader.readXML();
   
        Style style = readStyles[0];
View Full Code Here

        ImageAssert.assertEquals(expected, img, THRESHOLD);
    }
   
    @Test
    public void testSimpleSquare() throws Exception {
        StyleFactory sfact =  CommonFactoryFinder.getStyleFactory();
        FilterFactory ffact =  CommonFactoryFinder.getFilterFactory();
       
        Mark m = sfact.mark(
                ffact.literal("square"),
                sfact.fill(null, ffact.literal("#0000FF"), null),
                sfact.stroke(ffact.literal("#000000"), null, ffact.literal(1), null, null, null, null));
       
        Graphic g = sfact.graphic(Arrays.asList((GraphicalSymbol)m), Expression.NIL, Expression.NIL, Expression.NIL, null, null);
        Symbolizer symb = sfact.pointSymbolizer(null, ffact.property(null), null, null, g);
        Rule r = sfact.rule(null, null, null, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Arrays.asList(symb), null);
        FeatureTypeStyle fts = sfact.featureTypeStyle(null, null, null, Collections.<Name> emptySet(), Collections.<SemanticType> emptySet(), Arrays.asList(r));
        Style s = sfact.style(null, null, true, Arrays.asList(fts), null);
       
        BufferedImage img = IconRenderer.renderIcon((org.geotools.styling.Style)s);
       
        // Default mark size, plus border, plus padding, times rendering scale, plus extra padding.
        final int size = (16+1+1)*4+1;
 
View Full Code Here

TOP

Related Classes of org.geotools.styling.StyleFactory

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.