2

I had a problem with my SLD today, I actually solved my issue but i'm very curious if there's another way around it, Mainly because my method is a hassle and may not work in other situations.

I've got a SLD with a filter regarding the quantity of the objects, and according the quantity it makes a attribute based coloring. This SLD actually worked as long as the declared attributed were in the database. here is the sld :

<?xml version="1.0" encoding="Windows-1255"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>Attribute-based polygon</Name>
<UserStyle>
<Title>SLD Cook Book: Attribute-based polygon</Title>
<FeatureTypeStyle>
<Rule>
<Name>SmallPop</Name>
<Title>פחות מ 4 קוב לשעה</Title>
<ogc:Filter>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>4</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#8000FF</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
<Rule>
<Name>Medium</Name>
<Title>4 עד 6 קוב לשעה</Title>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>4</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>6</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#00FFFF</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
  <Rule>
<Name>Medium2</Name>
<Title>6 עד 8 קוב לשעה</Title>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>6</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>8</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#74DF00</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>

  <Rule>
<Name>Medium3</Name>
<Title>8 עד 10 קוב לשעה</Title>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>8</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>10</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#DBA901</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>

<Rule>
<Name>LargePop</Name>
<Title>יותר מ 10 קוב לשעה</Title>
<ogc:Filter>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>10</ogc:Literal>
</ogc:PropertyIsGreaterThan>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#B40404</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

But when I had a new version of the layer, with some of the records missing (for example, no record above the quantity of 5), the SLD failed to load.

So, I changed my sld to the following:

<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>Attribute-based polygon</Name>
<UserStyle>
<Title>SLD Cook Book: Attribute-based polygon</Title>
<FeatureTypeStyle>
<Rule>
<Name>SmallPop</Name>
<Title>Minor</Title>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>1</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#8000FF</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
<Rule>
<Name>Medium</Name>
<Title>Small</Title>
<ogc:Filter>

<ogc:PropertyIsEqualTo>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>2</ogc:Literal>
</ogc:PropertyIsEqualTo>

</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#00FFFF</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
  <Rule>
<Name>Medium2</Name>
<Title>Medium</Title>
<ogc:Filter>

<ogc:PropertyIsEqualTo>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>3</ogc:Literal>
</ogc:PropertyIsEqualTo>

</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#74DF00</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>

  <Rule>
<Name>Medium3</Name>
<Title>Large</Title>
<ogc:Filter>

<ogc:PropertyIsEqualTo>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>4</ogc:Literal>
</ogc:PropertyIsEqualTo>

</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#DBA901</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>

<Rule>
<Name>LargePop</Name>
<Title>Very Large</Title>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>quantity</ogc:PropertyName>
<ogc:Literal>10</ogc:Literal>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">#B40404</CssParameter>
</Fill>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

Isn't in weird that I need to change the SLD according to the records in my layer ? I expect it to ignore every rule that contain missing record, but that is not the case.

any thoughts ?

thanks

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.