Skip to main content

Package for SLD generator

Project description

Downloads License: MIT

Documentation

The library is useful for generating the SLD file for raster as well as vector datasets. The package can generate the 4 types of styles,

  1. Simple style
  2. Categorized style
  3. Classified style
  4. Raster style

The library is the small version of QGIS 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.io

Installation

pip install pysld

Some example

# Import library
from pysld.style import StyleSld

# Simple style for polygon feature
simple_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 feature
categorized_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 feature
classified_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 style
raster_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 data
categorized_sld = StyleSld(
            style_name='polygonStyle',
            geom_type='polygon',
            attribute_name='USE',
            color_palette='Spectral_r',
            # Postgres connection parameters
            dbname='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 table
categorized_style_sld = categorized.generate_categorized_style()

Generated SLD file example

Simple SLD
<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>style</Name>
        <UserStyle>
        <Title>style</Title>
        <FeatureTypeStyle>
    <Rule>
        <PolygonSymbolizer>
            <Fill>
                <CssParameter name="fill">#ffffff</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>
Raster SLD
<StyledLayerDescriptor xmlns="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:ColorMap type="range">
                    <sld:ColorMapEntry color="#54aead" label=" 0.0" quantity="0.0"/>
                    <sld:ColorMapEntry color="#bfe5a0" label=" 25.0" quantity="25.0"/>
                    <sld:ColorMapEntry color="#fffebe" label=" 50.0" quantity="50.0"/>
                    <sld:ColorMapEntry color="#fdbf6f" label=" 75.0" quantity="75.0"/>
                    <sld:ColorMapEntry color="#e95c47" label=" 100.0" quantity="100.0"/>
                </sld:ColorMap>
            </sld:RasterSymbolizer>
            </sld:Rule>
        </sld:FeatureTypeStyle>
        </sld:UserStyle>
    </UserLayer>
</StyledLayerDescriptor>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysld-0.0.6.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

pysld-0.0.6-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file pysld-0.0.6.tar.gz.

File metadata

  • Download URL: pysld-0.0.6.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.3

File hashes

Hashes for pysld-0.0.6.tar.gz
Algorithm Hash digest
SHA256 2c129cfb5b7a896822885cfea9e1064b8b36945cef2ca05554a5c6aa3b3ed61e
MD5 a7176681ab71d19821eb56277a3780d9
BLAKE2b-256 28272ba5467915b4c6bb0cf1ddd3090743910e233e14368260a2cd5c93ea3b88

See more details on using hashes here.

File details

Details for the file pysld-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: pysld-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.3

File hashes

Hashes for pysld-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6f779192ff3d83470c0c4faae2c2db5652319e903a6a3af9e0788ddebd195bed
MD5 467c9e10ac5892b0f5b066649dd43863
BLAKE2b-256 3297c5fb07ca815a426a0da806200874d584b4654a5331dc72e6abaa6252871f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page