Classified Style
The Classified style is simillar to QGIS graduated style.
The Classified style is available for all point, line and polygon datasets. This class is inherited from categorized style and simple style. Below is the example of generating the Classified style for polygon dataset,
# Import and initialized package
from pysld.style import StyleSld
sld = StyleSld(
style_name='polygonStyle',
geom_type='polygon',
attribute_name='PEOPLE',
values=[1,2,3,34,23,122,12,2,3,21,23,32,1,23,42,1,23,1,1,23,4,3,54,6,768,8,554,3,43,543,6,657,7,75,4,4],
number_of_class=5,
classification_method='natural_break',
color_palette='Spectral_r',
)
# Generate the Classified style
style = sld.generate_classified_style()
print(style)
Note: If you want to add the label feature, simple add two more parameters, feature_label=True
and attribute_name_label
to the StyleSld
class.
The above code will generate the following map with corresponding legend,
Which is simillar to following xml
,
<StyledLayerDescriptor version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 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">
<NamedLayer>
<Name>polygonStyle</Name>
<UserStyle>
<Title>polygonStyle</Title>
<FeatureTypeStyle>
<Rule>
<Name>>= 1.0 and < 43.0</Name>
<Title>>= 1.0 and < 43.0</Title>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>1.0</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>43.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">S</CssParameter>
<CssParameter name="fill-opacity">1</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#333333</CssParameter>
<CssParameter name="stroke-width">1</CssParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
<Rule>
<Name>>= 43.0 and < 122.0</Name>
<Title>>= 43.0 and < 122.0</Title>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>43.0</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>122.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">p</CssParameter>
<CssParameter name="fill-opacity">1</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#333333</CssParameter>
<CssParameter name="stroke-width">1</CssParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
<Rule>
<Name>>= 122.0 and < 554.0</Name>
<Title>>= 122.0 and < 554.0</Title>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>122.0</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>554.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">e</CssParameter>
<CssParameter name="fill-opacity">1</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#333333</CssParameter>
<CssParameter name="stroke-width">1</CssParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
<Rule>
<Name>>= 554.0 and < 657.0</Name>
<Title>>= 554.0 and < 657.0</Title>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>554.0</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>657.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">c</CssParameter>
<CssParameter name="fill-opacity">1</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#333333</CssParameter>
<CssParameter name="stroke-width">1</CssParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
<Rule>
<Name>>= 657.0 and < 768.0</Name>
<Title>>= 657.0 and < 768.0</Title>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>657.0</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>USE</ogc:PropertyName>
<ogc:Literal>768.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<PolygonSymbolizer>
<Fill>
<CssParameter name="fill">t</CssParameter>
<CssParameter name="fill-opacity">1</CssParameter>
</Fill>
<Stroke>
<CssParameter name="stroke">#333333</CssParameter>
<CssParameter name="stroke-width">1</CssParameter>
</Stroke>
</PolygonSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
For PostGIS data, check Generate style for PostGIS data section from Categorized Style.
For the feature label check Add feature label section from Simple style.
Available options for classified style
Since the classifed style
is inherited from Categorized Style and Simple style, it supports all the parameters and function from categorized style
and simple style
as well, see Available options for categorized style and Available options for simple style.
Options |
DataType |
Default |
Description |
---|---|---|---|
number_of_class |
integer |
5 |
The number of classes for classify the values. |
values |
list of numeric values |
It should be list of numeric values. See Some additional function for more detail. |
|
classification_method |
string |
‘natural_break’ |
The classification method for classify the vlaues. Available options are, |