private void twoFeatureTypeStyles() { // twoFeatureTypeStyles start StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(); FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2(); Style style = styleFactory.getDefaultStyle(); // Feature type style 1 FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(); fts.featureTypeNames().add(new NameImpl("feature-type-1")); style.featureTypeStyles().add(fts); // Feature type style 2 FeatureTypeStyle fts2 = styleFactory.createFeatureTypeStyle(); fts2.featureTypeNames().add(new NameImpl("feature-type-2")); // creating the rule 1 Rule rule1 = styleFactory.createRule(); rule1.setName("rule1"); Filter aFilter = filterFactory.id(Collections.singleton(filterFactory.featureId("FID"))); rule1.setFilter(aFilter); fts2.rules().add(rule1); // creating the rule 2 Rule rule2 = styleFactory.createRule(); rule2.setIsElseFilter(true); rule2.setName("rule2"); fts2.rules().add(rule2); style.featureTypeStyles().add(fts2); // twoFeatureTypeStyles end }
private void styleBuilderExample() throws Exception { // styleBuilderExample start // // We are using the GeoTools StyleBuilder that is helpful for quickly making things StyleBuilder builder = new StyleBuilder(); FilterFactory2 ff = builder.getFilterFactory(); // RULE 1 // first rule to draw cities // define a point symbolizer representing a city Graphic city = builder.createGraphic(); city.setSize(ff.literal(10)); city.graphicalSymbols().add(builder.createExternalGraphic("file:city.svg", "svg")); // svg // preferred city.graphicalSymbols().add(builder.createExternalGraphic("file:city.png", "png")); // png next city.graphicalSymbols() .add(builder.createMark(StyleBuilder.MARK_CIRCLE, Color.BLUE, Color.BLACK, 1)); PointSymbolizer pointSymbolizer = builder.createPointSymbolizer(city, "the_geom"); Rule rule1 = builder.createRule(pointSymbolizer); rule1.setName("rule1"); rule1.getDescription().setTitle("City"); rule1.getDescription().setAbstract("Rule for drawing cities"); rule1.setFilter(ff.less(ff.property("POPULATION"), ff.literal(50000))); // // RULE 2 Default Graphic dotGraphic = builder.createGraphic(null, builder.createMark(StyleBuilder.MARK_CIRCLE), null); PointSymbolizer dotSymbolize = builder.createPointSymbolizer(dotGraphic); Rule rule2 = builder.createRule(dotSymbolize); rule2.setIsElseFilter(true); // // define feature type styles used to actually define how features are rendered Rule rules[] = new Rule[] {rule1, rule2}; FeatureTypeStyle featureTypeStyle = builder.createFeatureTypeStyle("Feature", rules); // // create a "user defined" style Style style = builder.createStyle(); style.setName("style"); style.getDescription().setTitle("User Style"); style.getDescription().setAbstract("Definition of Style"); style.featureTypeStyles().add(featureTypeStyle); // styleBuilderExample end }