A pure Python MapFile parser for working with MapServer
Project description
A pure Python parser for working with MapServer MapFiles, built using Lark. mappyfile is an official OSGeo Community Project.
mappyfile is used for formatting and validation in https://app.mapserverstudio.net/, and can be tested for free on any of your Mapfiles. If you find mappyfile useful please consider signing up for a professional account at https://mapserverstudio.net/. This will help to fund maintenance and further development of both mappyfile and MapServer.
Requirements
Python 3.8 or higher
Installation
mappyfile is available on PyPI (the Python Package Index), and can be installed using pip:
pip install mappyfile
This will also install its required dependencies - Lark, and jsonschema.
To install the optional lark-cython library for better performance on CPython you can run the following command:
pip install mappyfile[lark_cython]
mappyfile is also available on conda. Install as follows:
conda install -c conda-forge mappyfile
Documentation
Full documentation is available at http://mappyfile.readthedocs.io/en/latest/
Usage
From within Python scripts:
import mappyfile
mapfile = mappyfile.open("./docs/examples/raster.map")
# update the map name
mapfile["name"] = "MyNewMap"
new_layer_string = """
LAYER
NAME 'land'
TYPE POLYGON
DATA '../data/vector/naturalearth/ne_110m_land'
CLASS
STYLE
COLOR 107 208 107
OUTLINECOLOR 2 2 2
WIDTH 1
END
END
END
"""
layers = mapfile["layers"]
new_layer = mappyfile.loads(new_layer_string)
layers.insert(0, new_layer) # insert the new layer at any index in the Mapfile
for l in layers:
print("{} {}".format(l["name"], l["type"]))
print(mappyfile.dumps(mapfile, indent=1, spacer="\t"))
Three command line tools are available - format, validate, and schema:
mappyfile format raster.map formatted_raster.map
mappyfile validate D:\ms-ogc-workshop\ms4w\apps\ms-ogc-workshop\**\*.map
mappyfile schema mapfile-schema-8-0.json --version=8.0
Contributors
Julien Enselme @jenselme
Loïc Gasser @loicgasser
Ian Turton @ianturton
TC Haddad @tchaddad (Conda support)
Project details
Release history Release notifications | RSS feed
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-1.0.2.tar.gz
.
File metadata
- Download URL: mappyfile-1.0.2.tar.gz
- Upload date:
- Size: 105.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43ada1b98cfc0fd670e6f384d74b15f6601aadb5ab9e1f1d506e839a37a9b8dc |
|
MD5 | dc0bf8d080a2585357ccf75bc3f70f55 |
|
BLAKE2b-256 | 22982d156f18ee0d6dd8ae4909a10c4bec81e7cb7c6b71d443b5128dd8c62145 |
File details
Details for the file mappyfile-1.0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: mappyfile-1.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 58.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 695c9a8841ce3e8fef49314f9873d7efda2544dea0825b6550540d9a7e650ceb |
|
MD5 | 7d4baed69760b0095ca75545c70d3fc0 |
|
BLAKE2b-256 | 67a8137dc8f0647134e162ec8bd4ac08c5e703749fde77c7af4fbd91bd93aa16 |