private void quickTextSymbolizer() { // quickTextSymbolizer start // "labelPoint" feature type style StyleBuilder sb = new StyleBuilder(); FilterFactory2 ff = sb.getFilterFactory(); // creation of the TextSymbolizer AnchorPoint anchorPoint = sb.createAnchorPoint(sb.attributeExpression("X"), sb.attributeExpression("Y")); PointPlacement pointPlacement = sb.createPointPlacement(anchorPoint, null, sb.literalExpression(0)); TextSymbolizer textSymbolizer = sb.createTextSymbolizer( sb.createFill(Color.BLACK), new Font[] {sb.createFont("Lucida Sans", 10), sb.createFont("Arial", 10)}, sb.createHalo(), sb.attributeExpression("name"), pointPlacement, null); // creation of the Point symbolizer Mark circle = sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED); Graphic graph2 = sb.createGraphic(null, circle, null, 1, 4, 0); PointSymbolizer pointSymbolizer = sb.createPointSymbolizer(graph2); // creation of the style Style style = sb.createStyle(); FeatureTypeStyle featureTypeStyle = sb.createFeatureTypeStyle("labelPoint", new Symbolizer[] {textSymbolizer, pointSymbolizer}); style.featureTypeStyles().add(featureTypeStyle); // creation of the style // quickTextSymbolizer end }
private void markTestSLD() { // markTestSLD start StyleBuilder sb = new StyleBuilder(); FilterFactory ff = sb.getFilterFactory(); Style style = sb.createStyle(); style.setName("MyStyle"); // "testPoint" feature type style Mark testMark = sb.createMark(sb.attributeExpression("name"), sb.createFill(Color.RED, 0.5), null); Graphic graph = sb.createGraphic( null, new Mark[] {testMark}, null, sb.literalExpression(1), sb.attributeExpression("size"), sb.attributeExpression("rotation")); style .featureTypeStyles() .add(sb.createFeatureTypeStyle("testPoint", sb.createPointSymbolizer(graph))); // "labelPoint" feature type style AnchorPoint anchorPoint = sb.createAnchorPoint(sb.attributeExpression("X"), sb.attributeExpression("Y")); PointPlacement pointPlacement = sb.createPointPlacement(anchorPoint, null, sb.literalExpression(0)); TextSymbolizer textSymbolizer = sb.createTextSymbolizer( sb.createFill(Color.BLACK), new Font[] {sb.createFont("Lucida Sans", 10), sb.createFont("Arial", 10)}, sb.createHalo(), sb.attributeExpression("name"), pointPlacement, null); Mark circle = sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED); Graphic graph2 = sb.createGraphic(null, circle, null, 1, 4, 0); PointSymbolizer pointSymbolizer = sb.createPointSymbolizer(graph2); style .featureTypeStyles() .add( sb.createFeatureTypeStyle( "labelPoint", new Symbolizer[] {textSymbolizer, pointSymbolizer})); // markTestSLD 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 }
private void featureTypeStyleExample() { // featureTypeStyleExample start StyleBuilder styleBuilder = new StyleBuilder(); Style style = styleBuilder.createStyle(); PointSymbolizer pointSymbolizer = styleBuilder.createPointSymbolizer(); Graphic graphic = styleBuilder.createGraphic(); ExternalGraphic external = styleBuilder.createExternalGraphic("file:///C:/images/house.gif", "image/gif"); graphic.graphicalSymbols().add(external); graphic.graphicalSymbols().add(styleBuilder.createMark("circle")); pointSymbolizer.setGraphic(graphic); Rule rule = styleBuilder.createRule(pointSymbolizer); FeatureTypeStyle featureTypeStyle = styleBuilder.createFeatureTypeStyle("Feature", rule); style.featureTypeStyles().add(featureTypeStyle); // featureTypeStyleExample end }