A mappyfile plugin to convert GeoJSON to inline Mapfile features
Project description
A mappyfile plugin to convert GeoJSON to inline Mapfile features. Useful for adding dynamically created features (from web services, user created features, and other external data sources), to a map.
import geojson
import mappyfile
import mappyfile_geojson
# will soon be available to import as
# from mappyfile.plugins import mappyfile_geojson
gj = geojson.load(fn)
l = mappyfile_geojson.convert(gj)
print(mappyfile.dumps(l))
Converts:
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[ 102.0, 0.0 ],
[ 103.0, 1.0 ],
[ 104.0, 0.0 ],
[ 105.0, 1.0 ]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
}
to:
LAYER
EXTENT 102.0 0.0 105.0 1.0
STATUS ON
TYPE LINE
PROCESSING "ITEMS=prop0,prop1"
FEATURE
ITEMS "value0;0.0"
POINTS
102.0 0.0
103.0 1.0
104.0 0.0
105.0 1.0
END
END
END
Demo
An example of using the plugin with mappyfile can be found in example.py along with an example.map.
Requirements
Python 2.7 or Python 3.x
mappyfile (the plugin can be used on its own but will create a dictionary object structured to use within mappyfile). Installing mapfile should be done seperately.
Installation
Note installing the mappyfile-geojson plugin will automatically install geoson.
pip install mappyfile
pip install mappyfile-geojson
Notes
Can calculate extent of input features, with optional buffer
Multipart features currently not implemented
Nested properties are not supported
"properties": { "prop0": "value0", "prop1": { "this": "that" } }
Will become:
ITEMS "value0;{u'this': u'that'}"
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
Hashes for mappyfile_geojson-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89f4be9968e43cce137ccb66f7b45d90daddf8da7d9c2cf68661871ee7346074 |
|
MD5 | d1ba65cd169e9a63d15373b1d6a941e1 |
|
BLAKE2b-256 | 73cec87781bb14ff746a1263af54e205f1440900e8e560d1fa6d6a1e078255d5 |