1

I have been using geoTools 11.2 in Java 1.8 to display a vector layer with a desired style of it in worldwind 2.0. I have read features and styles and created objects. I have my own defined vector layer for the worldwind. I've read SLD parameters like color,font,etc but I don't know to which features I should apply these parameters. I can read some properties from the style such as the following:

import org.opengis.feature.simple.SimpleFeature;
import org.geotools.styling.Style;
import org.geotools.styling.SLD;

public void addRenderableForFeature(SimpleFeature feature, Style style){
    FeatureTypeStyle fts = style.featureTypeStyles().get(0);
    Rule[] rules = fts.getRules();
    Rule rule = rules[0];
    Symbolizer[] syms = rule.getSymbolizers();
    PolygonSymbolizer polySymb = (PolygonSymbolizer) syms[0];
    Color stroke = SLD.polyColor(polySymb);
    double opacity = SLD.polyFillOpacity(polySymb);
    Color fill = SLD.polyFill(polySymb);
    int width = SLD.width(SLD.stroke(polySymb));
    if (width == SLD.NOTFOUND) {
        width = 1;
    }

    if (Double.isNaN(opacity)) {
        opacity = 1.0;
    }

}

But I can't determine which features this symbolizer is related to.
please help!

edit:

the sld file I am using:

<!-- language: lang-xml -->
<?xml version="1.0" encoding="UTF-8"?>
<sld:StyledLayerDescriptor xmlns="http://www.opengis.net/sld"    xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
<sld:NamedLayer>
<sld:Name>medford_parks</sld:Name>
<sld:UserStyle>
  <sld:Name>medford_parks</sld:Name>
  <sld:Title>Medford, OR - Parks</sld:Title>
  <sld:IsDefault>1</sld:IsDefault>
  <sld:FeatureTypeStyle>
    <sld:Name>name</sld:Name>
    <sld:Rule>
      <sld:Name>Forest Parks</sld:Name>
      <sld:Title>Forest Parks &lt; 280K</sld:Title>
      <ogc:Filter>
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>parktype</ogc:PropertyName>
          <ogc:Literal>Forest Park</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <sld:MaxScaleDenominator>280000.0</sld:MaxScaleDenominator>
      <sld:PolygonSymbolizer>
        <sld:Fill>
          <sld:CssParameter name="fill">#238B45</sld:CssParameter>
          <sld:CssParameter name="fill-opacity">0.8</sld:CssParameter>
        </sld:Fill>
      </sld:PolygonSymbolizer>
    </sld:Rule>
    <sld:Rule>
      <sld:Name>Parks</sld:Name>
      <sld:Title>Parks &lt; 140K</sld:Title>
      <ogc:Filter>
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>parktype</ogc:PropertyName>
          <ogc:Literal>Park</ogc:Literal>
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <sld:MinScaleDenominator>1000.0</sld:MinScaleDenominator>
      <sld:MaxScaleDenominator>140000.0</sld:MaxScaleDenominator>
      <sld:PolygonSymbolizer>
        <sld:Fill>
          <sld:CssParameter name="fill">#74C476</sld:CssParameter>
          <sld:CssParameter name="fill-opacity">0.8</sld:CssParameter>
        </sld:Fill>
      </sld:PolygonSymbolizer>
    </sld:Rule>
    <sld:Rule>
      <sld:Name>Recreational</sld:Name>
      <sld:Title>Recreational &lt; 70K</sld:Title>
      <sld:ElseFilter/>
      <sld:MinScaleDenominator>1000.0</sld:MinScaleDenominator>
      <sld:MaxScaleDenominator>70000.0</sld:MaxScaleDenominator>
      <sld:PolygonSymbolizer>
        <sld:Fill>
          <sld:CssParameter name="fill">#BAE4B3</sld:CssParameter>
          <sld:CssParameter name="fill-opacity">0.8</sld:CssParameter>
        </sld:Fill>
      </sld:PolygonSymbolizer>
    </sld:Rule>
  </sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
</sld:StyledLayerDescriptor>

SLD has some rules and filters. How can I apply these filters to my features to get a feature collection?

  • 1
    currently the symbolizer is not related to anything, is there more code that uses it? – Ian Turton Jan 3 '15 at 17:03
  • 1
    @iant the sld file has some rules and filters. How can I apply these filters to my feature? – Dariush Jan 3 '15 at 17:14
  • 1
    you can just load the SLD file to give you a style that you apply to the layer. Layer layer = new FeatureLayer(featureSource, style); map.addLayer(layer); org.geotools.xml.Configuration configuration = new org.geotools.sld.SLDConfiguration(); org.geotools.xml.Parser parser = new org.geotools.xml.Parser(configuration); // the xml instance document above InputStream xml = new FileInputStream("markTest.sld"); StyledLayerDescriptor sld = (StyledLayerDescriptor) parser.parse(xml); – Ian Turton Jan 3 '15 at 17:49
  • 1
    @iant map.addLayer(layer) is a 2D(swing) view of the layer. It is not usefull in 3D (worldwind). – Dariush Jan 3 '15 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.