Package: pysld
DocumentationThe library is useful for generating theSLDfile for raster as well as vector datasets. The package can generate the 4 types of styles,Simple styleCategorized styleClassified styleRaster styleThe library is the small version ofQGIS symbology. This library is very useful for the visual appearance on the map.The package is available in official PyPI:https://pypi.org/project/pysld/The complete documentation of this library is found here:https://pysld.readthedocs.ioInstallationpipinstallpysldSome example# Import libraryfrompysld.styleimportStyleSld# Simple style for polygon featuresimple_sld=StyleSld(style_name='polygonStyle',geom_type='polygon',fill_color='#ffffff',stroke_color='#333333')simple_sld_style=simple_sld.generate_simple_style()print(simple_sld_style)# Categorized style for polygon featurecategorized_sld=StyleSld(style_name='polygonStyle',geom_type='polygon',attribute_name='USE',values=['Agriculture','Residential','Restaurant','Storehouse'],color_palette='Spectral_r')categorized_sld_style=categorized_sld.generate_categorized_style()print(categorized_sld_style)# Classified style for polygon featureclassified_sld=StyleSld(style_name='polygonStyle',geom_type='polygon',attribute_name='USE',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')classified_sld_style=classified_sld.generate_classified_style()print(classified_sld_style)# Raster styleraster_style=StyleSld(style_name='polygonStyle',color_palette='Spectral_r',continuous_legend=True)raster_sld_style=raster_sld.generate_raster_style(max_value=100,min_value=0)# Categorized style for PostGIS datacategorized_sld=StyleSld(style_name='polygonStyle',geom_type='polygon',attribute_name='USE',color_palette='Spectral_r',# Postgres connection parametersdbname='postgres',user='postgres',password='admin',host='localhost',port='5432',schema='public',pg_table_name='postgres_table_name')print(categorized.values)# It will print the unique values from postgres_table_name tablecategorized_style_sld=categorized.generate_categorized_style()Generated SLD file exampleSimple SLD<StyledLayerDescriptorversion="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>style</Name><UserStyle><Title>style</Title><FeatureTypeStyle><Rule><PolygonSymbolizer><Fill><CssParametername="fill">#ffffff</CssParameter><CssParametername="fill-opacity">1</CssParameter></Fill><Stroke><CssParametername="stroke">#333333</CssParameter><CssParametername="stroke-width">1</CssParameter></Stroke></PolygonSymbolizer></Rule></FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>Raster SLD<StyledLayerDescriptorxmlns="http://www.opengis.net/sld"xmlns:gml="http://www.opengis.net/gml"version="1.0.0"xmlns:ogc="http://www.opengis.net/ogc"xmlns:sld="http://www.opengis.net/sld"><UserLayer><sld:LayerFeatureConstraints><sld:FeatureTypeConstraint/></sld:LayerFeatureConstraints><sld:UserStyle><sld:Name>polygonStyle</sld:Name><sld:FeatureTypeStyle><sld:Rule><sld:RasterSymbolizer><Opacity>1</Opacity><sld:ChannelSelection><sld:GrayChannel><sld:SourceChannelName>1</sld:SourceChannelName></sld:GrayChannel></sld:ChannelSelection><sld:ColorMaptype="range"><sld:ColorMapEntrycolor="#54aead"label=" 0.0"quantity="0.0"/><sld:ColorMapEntrycolor="#bfe5a0"label=" 25.0"quantity="25.0"/><sld:ColorMapEntrycolor="#fffebe"label=" 50.0"quantity="50.0"/><sld:ColorMapEntrycolor="#fdbf6f"label=" 75.0"quantity="75.0"/><sld:ColorMapEntrycolor="#e95c47"label=" 100.0"quantity="100.0"/></sld:ColorMap></sld:RasterSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></UserLayer></StyledLayerDescriptor>