A mappyfile plugin to convert between RGB and Hex colors, and to add human readable names
Project description
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
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 it to a script, 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.
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, include_comments=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.
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
Built Distribution
File details
Details for the file mappyfile-colors-0.3.0.tar.gz
.
File metadata
- Download URL: mappyfile-colors-0.3.0.tar.gz
- Upload date:
- Size: 6.2 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | f601a5d9315e435bd68393c5d71077a660fc63a587516f55308573879bc37b58 |
|
MD5 | 69ae6855a7cd1f90f86d880d4883d42e |
|
BLAKE2b-256 | 8ad2f9acf003948cb23fc9369ab913ea72602aeb2d49835569776ed27b29330e |
Provenance
File details
Details for the file mappyfile_colors-0.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: mappyfile_colors-0.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ef9b35ef6b4050e0a269b72304af69191399871ff3c201490943967de12e2b5 |
|
MD5 | d13770a4e06cf9a8bffe71cc21588b73 |
|
BLAKE2b-256 | 1d8f58a391baabe11f125f16d1bff1b45f9ebcc884809b33d09af52f533852a9 |