IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

GeotoolKit - Symbology

Date de publication : 24 juin 2010

Par Johann Sorel
 

Cet article explique comment créer des symbols complexe pour vos cartes dans GeotoolKit. Un zip contenant tous les exemples se trouve à la fin.
Commentez Donner une note à l´article (5)

       Version PDF (Miroir)   Version hors-ligne (Miroir)
Viadeo Twitter Facebook Share on Google+        



I. Introduction
II. Exemple


I. Introduction

La symbology dans GeotoolKit s'appuit sur quatre normes :
- OGC Styled Layer Descriptor
- OGC Symbology Encoding
- OGC Filter
- ISO 19117 : Portrayal Service
La structure des styles est tres proche de la definition de SLD et SE, je vous invites donc a les télécharger.


II. Exemple

Exmple de cercle rouge.

import org.geotoolkit.factory.FactoryFinder;
import org.geotoolkit.factory.Hints;
import org.geotoolkit.style.MutableFeatureTypeStyle;
import org.geotoolkit.style.MutableRule;
import org.geotoolkit.style.MutableStyle;
import org.geotoolkit.style.MutableStyleFactory;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.expression.Expression;
import org.opengis.style.AnchorPoint;
import org.opengis.style.Displacement;
import org.opengis.style.Fill;
import org.opengis.style.Graphic;
import org.opengis.style.GraphicalSymbol;
import org.opengis.style.PointSymbolizer;
import org.opengis.style.Stroke;

import static org.geotoolkit.style.StyleConstants.*;

...

		final MutableStyleFactory sf = (MutableStyleFactory) FactoryFinder.getStyleFactory(
                                   new Hints(Hints.STYLE_FACTORY,MutableStyleFactory.class));
        final FilterFactory ff = FactoryFinder.getFilterFactory(null);


        //creation d'un cercle rouge
        final Stroke stroke = sf.stroke(Color.RED, 1); //rouge un pixel de large
        final Fill fill = sf.fill(new Color(0, 0, 0, 0)); //transparant
        final GraphicalSymbol redCercle = sf.mark(MARK_CIRCLE, stroke, fill);

        //configuration de la taille, opacité ...etc...
        final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
        symbols.add(redCercle);
        final Expression opacity = LITERAL_ONE_FLOAT;
        final Expression size = ff.literal(14);
        final Expression rotation = LITERAL_ZERO_FLOAT;
        final AnchorPoint anchor = DEFAULT_ANCHOR_POINT;
        final Displacement displacement = DEFAULT_DISPLACEMENT;
        final Graphic graphic = sf.graphic(symbols, opacity, size, rotation, anchor, displacement);

        //creation du symbol
        final PointSymbolizer symbolizer1 = sf.pointSymbolizer(graphic, null);
        
        //on assemble les different elements
        final MutableStyle style = sf.style();
        final MutableFeatureTypeStyle fts = sf.featureTypeStyle();
        final MutableRule rule = sf.rule();
        rule.symbolizers().add(symbolizer1);
        fts.rules().add(rule);
        style.featureTypeStyles().add(fts);

        System.out.println(style);
Exmple pour une image.

		//utilisation d'un image sur disque ou dans le jar
        final GraphicalSymbol image = sf.externalGraphic(new ImageIcon("image/monImage.gif"), null);

        //configuration de la taille, opacité ...etc...
        final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
        symbols.add(image);
        final Expression opacity = LITERAL_ONE_FLOAT;
        final Expression size = ff.literal(14);
        final Expression rotation = LITERAL_ZERO_FLOAT;
        final AnchorPoint anchor = DEFAULT_ANCHOR_POINT;
        final Displacement displacement = DEFAULT_DISPLACEMENT;
        final Graphic graphic = sf.graphic(symbols, opacity, size, rotation, anchor, displacement);

        //creation du symbol
        final PointSymbolizer symbolizer1 = sf.pointSymbolizer(graphic, null);
        
        //on assemble les different elements
        final MutableStyle style = sf.style();
        final MutableFeatureTypeStyle fts = sf.featureTypeStyle();
        final MutableRule rule = sf.rule();
        rule.symbolizers().add(symbolizer1);
        fts.rules().add(rule);
        style.featureTypeStyles().add(fts);
Ne pas oublier qu'un toString() sur un object de style vous affichera sa structure, toujours tres pratique pour le debuggage.

Style : DefaultMutableStyle null[Description : Title=Title Abstract=Description]
+---FTS : DefaultMutableFeatureTypeStyle null[Description : Title=Title Abstract=Description]
    +---Rule : DefaultMutableRule null[Description : Title=Title Abstract=Description]
        +---Symbol : DefaultPointSymbolizer null[Description : Title=Title Abstract=Description]


               Version PDF (Miroir)   Version hors-ligne (Miroir)

Valid XHTML 1.0 TransitionalValid CSS!