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, or to quickly visualise a geometry.
Note - to display entire GeoJSON files MapServer can be configured to read GeoJSON as an input OGR source using the GeoJSON driver.
import geojson
import mappyfile
# import directly
import mappyfile_geojson
# can also be imported as plugin using
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.
A further example, creating images for each of the test cases using mapscript is available at create_images.py.
The sample output images are in the images folder.
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 mappyfile should be done separately.
Installation
Note installing the mappyfile-geojson plugin will automatically install the required dependency geojson.
pip install mappyfile
pip install mappyfile-geojson
Notes
Can calculate extent of input features, with an optional buffer (by passing an extent_buffer to the convert function)
Multipart features are supported
Coordinate sequences with Z values are supported, but Z values are ignored as they are not supported in Mapserver inline features.
As a MapServer LAYER only supports a single geometry type, all features in the GeoJSON file should also be of the same type (however a mix of multipart and non-multipart features is supported e.g. LineString and MultiLineString)
Nested JSON properties are not supported:
"properties": { "prop0": "value0", "prop1": { "this": "that" } }
Will become:
ITEMS "value0;{u'this': u'that'}"
Releases
0.4 (09/02/2020)
Automated Windows testing
Automated release process
Set geojson dependency version
Fix failing tests due to precision issuee differences between py2 and py3
Use integers for layer EXTENT where possible e.g. 5 instead of 5.0
0.3 (29/08/2018)
Add support for MultiPoint, MultiLineString, and MultiPolygon
Allow coordinates with Z values (previously these would crash the script)
Updated README
0.2 (15/02/2018)
Unicode support
0.1 (06/02/2018)
Initial release
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 Distributions
Hashes for mappyfile_geojson-0.4.0-py3.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb16f0562d471c974922731beee9e28ca993860364345fe8f43519831e30469b |
|
MD5 | 1c83df11ea3f722872a28210577dc35d |
|
BLAKE2b-256 | 370a7dcab334b95f3b5b11b9afabefeebfe1afaa3c5ab3df9c27ca19f8e2b4c9 |
Hashes for mappyfile_geojson-0.4.0-py3.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | f72ab97a758731a1c0949801d0e59b0e190d108d0a9bb0f186778ebe5446c5df |
|
MD5 | 23588c5a892455525ce11ad7041f045b |
|
BLAKE2b-256 | 5224938c2ee5d624eb5fd01600d204634f416052dbad7f5b7e16d052b662a086 |
Hashes for mappyfile_geojson-0.4.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 831e185458e0fea0a19bcf5813d956d5375fb0c822109e6fab6053532a6be7a5 |
|
MD5 | 96c99a99234b7e11e57597dec67abaae |
|
BLAKE2b-256 | 25f57a70f22c6af5e1c434a10248e131456cd4bc238660d58abd2c4005c7ee44 |
Hashes for mappyfile_geojson-0.4.0-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 761c7c4e2b1d31e12f64b9a005a750519800157e8a73cd98cb3f8940a027321c |
|
MD5 | e9a74b65a6db7b3a518f3505dc28b6f0 |
|
BLAKE2b-256 | 7201fb0381585e242a9ddef37fc956f7fca78d1abb0d188243cca7c33e8b7c1c |