1

I have 3 SLD file (let's call them 2013, 2014, 2015) which are related to three shp file. The shapefiles are identical except for the fact that the attributes are named differently (from 2013 and so on). Therefore instead of using 3 separate SLD files I would like to compact them in order to use the same SLD for each of the 3 shapefiles.

At the moment this is the kind of SLD I'm using:

<?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:UserLayer>
        <sld:LayerFeatureConstraints>
            <sld:FeatureTypeConstraint/>
        </sld:LayerFeatureConstraints>
        <sld:UserStyle>
            <sld:Name>L005 Regioni 2013 PMerc</sld:Name>
            <sld:Title/>
            <sld:FeatureTypeStyle>
                <sld:Name>group 0</sld:Name>
                <sld:FeatureTypeName>Feature</sld:FeatureTypeName>
                <sld:Rule>
                    <sld:Name>0 ton</sld:Name>
                    <ogc:Filter>
                        <ogc:PropertyIsEqualTo>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>0</ogc:Literal>
                        </ogc:PropertyIsEqualTo>
                    </ogc:Filter>
                    <sld:PolygonSymbolizer>
                        <sld:Fill>
                            <sld:CssParameter name="fill">#2C7BB6</sld:CssParameter>
                        </sld:Fill>
                        <sld:Stroke/>
                    </sld:PolygonSymbolizer>
                </sld:Rule>
                <sld:Rule>
                    <sld:Name>Da 0 ton a 50 ton</sld:Name>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsGreaterThan>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>0</ogc:Literal>
                            </ogc:PropertyIsGreaterThan>
                            <ogc:PropertyIsLessThanOrEqualTo>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>50</ogc:Literal>
                            </ogc:PropertyIsLessThanOrEqualTo>
                        </ogc:And>
                    </ogc:Filter>
                    <sld:PolygonSymbolizer>
                        <sld:Fill>
                            <sld:CssParameter name="fill">#6DA9CD</sld:CssParameter>
                        </sld:Fill>
                        <sld:Stroke/>
                    </sld:PolygonSymbolizer>
                </sld:Rule>
                <sld:Rule>
                    <sld:Name>Da 50 ton a 200 ton</sld:Name>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsGreaterThan>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>50</ogc:Literal>
                            </ogc:PropertyIsGreaterThan>
                            <ogc:PropertyIsLessThanOrEqualTo>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>200</ogc:Literal>
                            </ogc:PropertyIsLessThanOrEqualTo>
                        </ogc:And>
                    </ogc:Filter>
                    <sld:PolygonSymbolizer>
                        <sld:Fill>
                            <sld:CssParameter name="fill">#A7D3E0</sld:CssParameter>
                        </sld:Fill>
                        <sld:Stroke/>
                    </sld:PolygonSymbolizer>
                </sld:Rule>
                <sld:Rule>
                    <sld:Name>Da 200 ton a 400 ton</sld:Name>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsGreaterThan>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>200</ogc:Literal>
                            </ogc:PropertyIsGreaterThan>
                            <ogc:PropertyIsLessThanOrEqualTo>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>400</ogc:Literal>
                            </ogc:PropertyIsLessThanOrEqualTo>
                        </ogc:And>
                    </ogc:Filter>
                    <sld:PolygonSymbolizer>
                        <sld:Fill>
                            <sld:CssParameter name="fill">#DEEFCB</sld:CssParameter>
                        </sld:Fill>
                        <sld:Stroke/>
                    </sld:PolygonSymbolizer>
                </sld:Rule>
                <sld:Rule>
                    <sld:Name>Da 400 ton a 600 ton</sld:Name>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsGreaterThan>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>400</ogc:Literal>
                            </ogc:PropertyIsGreaterThan>
                            <ogc:PropertyIsLessThanOrEqualTo>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>600</ogc:Literal>
                            </ogc:PropertyIsLessThanOrEqualTo>
                        </ogc:And>
                    </ogc:Filter>
                    <sld:PolygonSymbolizer>
                        <sld:Fill>
                            <sld:CssParameter name="fill">#FFF7AF</sld:CssParameter>
                        </sld:Fill>
                        <sld:Stroke/>
                    </sld:PolygonSymbolizer>
                </sld:Rule>
                <sld:Rule>
                    <sld:Name>Da 600 ton  a 800 ton</sld:Name>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsGreaterThan>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>600</ogc:Literal>
                            </ogc:PropertyIsGreaterThan>
                            <ogc:PropertyIsLessThanOrEqualTo>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>800</ogc:Literal>
                            </ogc:PropertyIsLessThanOrEqualTo>
                        </ogc:And>
                    </ogc:Filter>
                    <sld:PolygonSymbolizer>
                        <sld:Fill>
                            <sld:CssParameter name="fill">#FCCA75</sld:CssParameter>
                        </sld:Fill>
                        <sld:Stroke/>
                    </sld:PolygonSymbolizer>
                </sld:Rule>
                <sld:Rule>
                    <sld:Name>Da 800 ton a 1000 ton</sld:Name>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsGreaterThan>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>800</ogc:Literal>
                            </ogc:PropertyIsGreaterThan>
                            <ogc:PropertyIsLessThanOrEqualTo>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>1000</ogc:Literal>
                            </ogc:PropertyIsLessThanOrEqualTo>
                        </ogc:And>
                    </ogc:Filter>
                    <sld:PolygonSymbolizer>
                        <sld:Fill>
                            <sld:CssParameter name="fill">#F7904B</sld:CssParameter>
                        </sld:Fill>
                        <sld:Stroke/>
                    </sld:PolygonSymbolizer>
                </sld:Rule>
                <sld:Rule>
                    <sld:Name> >1000 ton</sld:Name>
                    <ogc:Filter>
                        <ogc:And>
                            <ogc:PropertyIsGreaterThan>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>1000</ogc:Literal>
                            </ogc:PropertyIsGreaterThan>
                            <ogc:PropertyIsLessThanOrEqualTo>
                                <ogc:PropertyName>Ton2013</ogc:PropertyName>
                                <ogc:Literal>5000</ogc:Literal>
                            </ogc:PropertyIsLessThanOrEqualTo>
                        </ogc:And>
                    </ogc:Filter>
                    <sld:PolygonSymbolizer>
                        <sld:Fill>
                            <sld:CssParameter name="fill">#EA3D2D</sld:CssParameter>
                        </sld:Fill>
                        <sld:Stroke/>
                    </sld:PolygonSymbolizer>
                </sld:Rule>
            </sld:FeatureTypeStyle>
        </sld:UserStyle>
    </sld:UserLayer>
</sld:StyledLayerDescriptor>

where I always need to change Ton2013 in Ton2014, Ton2015 and so on.

Basically I would like to insert in my sld file something like

"if you don't find Ton2013 then use Ton2014, if you don't this either use Ton2015 and so on"

Colours and ranges of greater and smaller remain the same through the years.

  • I am not an expert in SLD files, but wouldn't it just be the easiest way, that you name the relevant data colum (quantity, or whatever it is called) the same in each shapefile? Then the rule should apply for each shapefile if I am correct? Just a thought ;) – Konrad Aug 24 '15 at 9:05
  • I don't think it would help. I need to see the evolution of the quantity through the years, so I loaded a shp file for each year. If I name the column simply Qty instead of Qty2013, how can I understand that regions coloured are according to qty2013 instead of qty2014? At the moment I'm forced to have 3 separate shp file, but I'm trying to obtain at least 1 sld file – user3520314 Aug 24 '15 at 9:09
  • Is it an Or relationship, that is you just need to map Ton2013, Ton2014, Ton2015. Will you data only have vale for either of those years, or can there be a mix in each data set? – nmtoken Mar 31 '16 at 23:19
1

I am not saying this is going to be pretty, however one possible answer is to use the filter function PropertyExists. With an if statement as follows:

<ogc:Filter>
    <ogc:Function name="if_then_else">
        <ogc:Function name="PropertyExists">
            <ogc:PropertyName>Ton2013</ogc:PropertyName>
        </ogc:Function>
        <!--Ton2013 does exist so use it-->
        <ogc:PropertyIsEqualTo>
            <ogc:PropertyName>Ton2013</ogc:PropertyName>
            <ogc:Literal>0</ogc:Literal>
        </ogc:PropertyIsEqualTo>
        <!--Ton2013 does not exist so test for Ton2014-->
        <ogc:Function name="if_then_else">
            <ogc:Function name="PropertyExists">
                <ogc:PropertyName>Ton2014</ogc:PropertyName>
            </ogc:Function>
            <!--Ton2014 does exist so use it-->
            <ogc:PropertyIsEqualTo>
                <ogc:PropertyName>Ton2014</ogc:PropertyName>
                <ogc:Literal>0</ogc:Literal>
            </ogc:PropertyIsEqualTo>
            <!--Ton2014 does not exist so use Ton2015-->
            <ogc:PropertyIsEqualTo>
                <ogc:PropertyName>Ton2015</ogc:PropertyName>
                <ogc:Literal>0</ogc:Literal>
            </ogc:PropertyIsEqualTo>
        </ogc:Function>
    </ogc:Function>
</ogc:Filter>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.