Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter is set before PolygonSymbolizer #11

Closed
ustroetz opened this issue May 28, 2014 · 2 comments
Closed

Filter is set before PolygonSymbolizer #11

ustroetz opened this issue May 28, 2014 · 2 comments

Comments

@ustroetz
Copy link

I am running this script:

from sld import *
sld_doc = StyledLayerDescriptor() 

# Create Layer
nl = sld_doc.create_namedlayer('Drivetime Polygon Style ')
us = nl.create_userstyle()
us.Title = 'Drivetime'


# Create Rule
fts = us.create_featuretypestyle()
r1 = fts.create_rule('Interval 1', PolygonSymbolizer)

# Create Filter
f1 = Filter(r1)
f1.PropertyIsEqualTo = PropertyCriterion(f1, 'PropertyIsEqualTo')
f1.PropertyIsEqualTo.PropertyName = 'drivetime' 
f1.PropertyIsEqualTo.Literal = 'v1'

r1.Filter = f1

content = sld_doc.as_sld(pretty_print=True)
print content

And it creates this sld file:

<sld:StyledLayerDescriptor xmlns:sld="http://www.opengis.net/sld" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ogc="http://www.opengis.net/ogc" version="1.0.0">
  <sld:NamedLayer>
    <sld:Name>Drivetime Polygon Style </sld:Name>
    <sld:UserStyle>
      <sld:Title>Drivetime</sld:Title>
      <sld:FeatureTypeStyle>
        <sld:Rule>
          <sld:Title>Interval 1</sld:Title>
          <sld:PolygonSymbolizer>
            <sld:Fill>
              <sld:CssParameter name="fill">#AAAAAA</sld:CssParameter>
            </sld:Fill>
            <sld:Stroke>
              <sld:CssParameter name="stroke">#000000</sld:CssParameter>
              <sld:CssParameter name="stroke-width">1</sld:CssParameter>
            </sld:Stroke>
          </sld:PolygonSymbolizer>
          <ogc:Filter>
            <ogc:PropertyIsEqualTo>
              <ogc:PropertyName>drivetime</ogc:PropertyName>
              <ogc:Literal>v1</ogc:Literal>
            </ogc:PropertyIsEqualTo>
          </ogc:Filter>
        </sld:Rule>
      </sld:FeatureTypeStyle>
    </sld:UserStyle>
  </sld:NamedLayer>
</sld:StyledLayerDescriptor>

The file is not valid, because the PolygonSymbolizer is before the filter. Is this a bug or am I doing something wrong?

@dzwarg
Copy link
Contributor

dzwarg commented Jul 12, 2014

Hello @ustroetz,

You must 'normalize' the doc before serializing it. You can call the 'normalize' method on the SLD object to perform this re-arrangement.

# Rearranges filters in the order defined by the schema
# note: the sld object is modified in place
sld_doc.normalize()

In addition, you can check the validity of the sld against the schema with validate, too:

# Validate that an SLD conforms to the schema
sld_doc.validate()

@ustroetz
Copy link
Author

Oh cool! Thanks for letting me know dzwarg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants