Hello Brian,
I think each of your rules also needs a filter to specify which
geometry type it is applied to.
The code snippet below is an example of one way in which you might do this.
Hope this helps.
Michael
// Danger ! Completely untested code
// this can be null if it is the default feature geometry
String geomPropertyName = ...
// external graphic URL
URL url = ...
StyleFactory sf = CommonFactoryFinder.getStyleFactory(null);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
// create the point rule and give it a filter to identify Point geometry type
Rule pointRule = sf.createRule();
Function getGeomFn = ff.function("geometryType", ff.property(geomPropertyName));
Filter pointFilter = ff.equals(getGeomFn, ff.literal("Point"));
pointRule.setFilter(pointFilter);
pointRule.setElseFilter(false);
// symbolizer for the point rule
Graphic graphic = sf.getDefaultGraphic();
graphic.graphicalSymbols().clear();
ExternalGraphic eGr = sf.createExternalGraphic(url, "image/png");
graphic.graphicalSymbols().add(eGr);
Symbolizer sym = sf.createPointSymbolizer(graphic, geomPropertyName);
pointRule.symbolizers().add(sym);
// create the line rule which doesn't need a filter - it just
// processes anything skipped by the point rule
Rule lineRule = sf.createRule();
lineRule.setIsElseFilter(true);
Stroke stroke = sf.createStroke(ff.literal(Color.BLUE), ff.literal(1.0f));
Symbolizer lineSym = sf.createLineSymbolizer(stroke, geomPropertyName);
lineRule.symbolizers().add(lineSym);
// wrap the rules into a Style
FeatureTypeStyle fts = sf.createFeatureTypeStyle(new Rule[]{pointRule,
lineRule});
Style style = sf.createStyle();
style.featureTypeStyles().add(fts);
The imports for the above are...
import java.awt.Color;
import java.net.URL;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.styling.ExternalGraphic;
import org.geotools.styling.FeatureTypeStyle;
import org.geotools.styling.Graphic;
import org.geotools.styling.Rule;
import org.geotools.styling.Stroke;
import org.geotools.styling.Style;
import org.geotools.styling.StyleFactory;
import org.geotools.styling.Symbolizer;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory2;
import org.opengis.filter.expression.Function;
------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users