Ejemplo n.º 1
0
  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
  }
Ejemplo n.º 2
0
  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
  }