Skip to main content

A mappyfile plugin to convert between RGB and Hex colors, and to add human readable names

Project description

Version Build Status

A mappyfile plugin to standardise and convert colors used in a Mapfile. Features include:

  • conversion between RGB and HEX colors

  • harmonise all colors in a Mapfile to either RGB or hex values

  • add human readable color names as comments

  • add color names to RGB color ranges as comments (not currently possible for HEX color ranges)

  • Python2 and 3 compatible

https://raw.githubusercontent.com/geographika/mappyfile-colors/master/rainbow.png

See example.map and rainbow_classes.txt for the Mapfile to generate the above image.

Installation

pip install mappyfile-colors

Note installing the mappyfile-colors plugin will automatically install the following dependencies:

  • mappyfile

  • webcolors

Online Demo

  • Go to the online mappyfile demo at http://mappyfile.geographika.net/

  • Select the “Rainbow colors” map

  • Open “Settings”, the mappyfile-colors Plugin Settings section allows conversion to RGB and HEX, and to include color names as comments in the Mapfile output

  • Click the Format button

Usage

To use the colors plugin, import, and then pass in a custom ColorsTransformer. Two additional parameters can also be passed to the mappyfile.loads function:

  • include_color_names - set to True to add color names as comments (default is False)

  • conversion_type - a parameter to convert colors within a Mapfile, either import ConversionType or use an integer value to set the conversion:

    NO_CONVERSION = 0
    TO_RGB = 1
    TO_HEX = 2

A sample script to convert RGB to HEX colors, and include the color names is shown below.

import mappyfile
from mappyfile.plugins import mappyfile_colors
from mappyfile_colors import ColorsTransformer, ConversionType

s = """
CLASS
    STYLE
        COLOR 184 134 11
        OUTLINECOLOR 0 0 255
        WIDTH 3
    END
END
"""

d = mappyfile.loads(s, include_color_names=True, transformerClass=ColorsTransformer, conversion_type=ConversionType.TO_HEX)
print(mappyfile.dumps(d))

This will output the following:

CLASS
    STYLE
        COLOR "#b8860b" # darkgoldenrod
        OUTLINECOLOR "#0000ff" # blue
        WIDTH 3
    END
END

See the test_plugin.py for further examples.

Color Factory

The plugin also includes a ColorFactory class to return unique colors from color palettes. This can be useful for generating MapServer classes based on unique values. Basic usage is shown below:

color_factory = mappyfile_colors.ColorFactory()
print(color_factory.palette_names)
clrs = color_factory.get_colors(palette_name="maximum_contrast")  # returns an iterator
print(next(clrs))

Author

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

mappyfile-colors-0.4.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

mappyfile_colors-0.4.0-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file mappyfile-colors-0.4.0.tar.gz.

File metadata

  • Download URL: mappyfile-colors-0.4.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0 requests/2.21.0 setuptools/40.7.0 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/2.7.15

File hashes

Hashes for mappyfile-colors-0.4.0.tar.gz
Algorithm Hash digest
SHA256 11dd2a95cb3b0757f20b5e352d1897ad12678fa1c0d343de6bf72fe06d0e5885
MD5 b9dd331162ee925c51185298e762e5e4
BLAKE2b-256 1a7b100c483c46019356a86c90a5fa3906b6d130ef39aa235ab2580088b00a81

See more details on using hashes here.

Provenance

File details

Details for the file mappyfile_colors-0.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: mappyfile_colors-0.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0 requests/2.21.0 setuptools/40.7.0 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/2.7.15

File hashes

Hashes for mappyfile_colors-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4a9ee927d19d7152a47e0bb6dffed1be0277b3a27bcdedc8077c080fa9f915c6
MD5 dbb25189d8a009c4ff2a7061e62d4688
BLAKE2b-256 e50a157c6b59cae9780e811bcfa1fe40f129249fe1bdd03ca6e27636e9834d5e

See more details on using hashes here.

Provenance

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