mappyfile-gdal
A mappyfile plugin to create Mapfiles for GDAL datasets.
It takes the JSON output of gdal raster info or gdal vector info and writes a
MapServer Mapfile for it, with a layer per dataset,
a map extent and size matching the data, and default symbology so the result
can be rendered straight away.
Installation
pip install mappyfile-gdal
GDAL 3.11 or later is needed for the gdal command line tool, and MapServer to render
the generated Mapfiles. Both are available from conda-forge:
conda create -n gdal-mapserver -c conda-forge gdal mapserver --yes
conda activate gdal-mapserver
pip install mappyfile-gdal
Usage
Pipe gdal info output straight into the tool, using - to read from stdin:
gdal raster info --stats raster.tif | mappyfile-gdal - raster.map
map2img -m raster.map -o raster.png
Without an output path the Mapfile is printed to stdout:
gdal vector info poly.gpkg | mappyfile-gdal
Or use a saved JSON file, or a whole folder of them:
gdal raster info --stats raster.tif --of json > raster.json
mappyfile-gdal raster.json raster.map
mappyfile-gdal ./json ./mapfiles
Example
Two layers from the Natural Earth GeoPackage, piped through to a rendered image:
gdal info natural_earth_vector.gpkg --of JSON --layer ne_10m_lakes --layer ne_10m_admin_0_countries | mappyfile-gdal - out.map
map2img -m out.map -o out.png
The generated Mapfile is out.map.
Options
| Option | Description |
|---|---|
--shapepath PATH |
Sets SHAPEPATH, so relative DATA and CONNECTION paths resolve |
--version |
Print the version and exit |
-h, --help |
Print usage and exit |
-v, --verbose |
Show debug messages |
-q, --quiet |
Only show errors |
gdal info reports paths exactly as they were given to it, so a dataset opened with a
relative path produces a Mapfile with a relative DATA. MapServer resolves those
against SHAPEPATH, or against the Mapfile's own folder when SHAPEPATH isn't set:
gdal raster info --stats aaigrid/byte.asc | mappyfile-gdal - byte.map --shapepath /data/gdal
Statistics
Passing --stats to gdal raster info allows minimum and maximum to be
written as PROCESSING "SCALE=min,max", which stretches the
values to the full range of greys. Without it MapServer scales each request from the
pixels it happens to be drawing, so the same value appears as different shades at
different zoom levels.
Selecting layers
For a dataset with many layers, such as a GeoPackage, every layer is added to the
Mapfile. To get a Mapfile for a single layer, select it in GDAL using the --layer option:
gdal vector info --layer roads data.gpkg | mappyfile-gdal - roads.map
Python API
import json
from mappyfile_gdal.main import main
with open("example.json", encoding="utf-8") as f:
data = json.load(f)
# save the Mapfile and return its path
main(data, "example.map", shapepath="/data/gdal")
# or return the Mapfile as a string
mapfile = main(data)
What gets generated
- Rasters become a
TYPE RASTERlayer, withPROCESSING "SCALE"and"NODATA"when statistics are available. - Vectors use
CONNECTIONTYPE OGRwith one layer per geometry layer, polygons are drawn first and points last, each in its own colour with semi-transparent fills so overlapping layers stay visible. - WMS capabilities documents use
CONNECTIONTYPE WMSwith one layer per subdataset. EXTENTis inset by half a pixel, since MapServer measures it between the centers of the corner pixels while GDAL reports the outer edges.PROJECTIONis set when the dataset's CRS has an authority code. Datasets without one are drawn in their native coordinates.
Development
git clone https://github.com/geographika/mappyfile-gdal.git
cd mappyfile-gdal
pip install -e .
pip install -r requirements-dev.txt
pytest
flake8 .
mypy mappyfile_gdal
License
MIT
Release files for mappyfile-gdal 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mappyfile_gdal-0.1.0.tar.gz | 19.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mappyfile_gdal-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.7 kB
Release files / mappyfile_gdal-0.1.0.tar.gz
| Download URL | mappyfile_gdal-0.1.0.tar.gz |
|---|---|
| Size | 19.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df726de6e8a72186ad3732a72c3cbf5ea9a594ca10a4a6520e75929244beea22
|
|
BLAKE2b-256 checksum How to use checksums |
25c5451aabe2e9bd72b38df68c776944cf2e68d41c0386586a706ce7a0857dee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logRelease files / mappyfile_gdal-0.1.0-py3-none-any.whl
| Download URL | mappyfile_gdal-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f50466662f33e8f2a355f85c941faa63013ec8e9eb707c45ddd7676dbda71c18
|
|
BLAKE2b-256 checksum How to use checksums |
f032de6744a66548d2d0e2ee9d6bd0233071fd66b42551341f1177595cbc3414
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency log