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
An example of using the plugin with mappyfile
can be found in example.py
along with an example.map.
- 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.
Note installing the mappyfile-geojson
plugin will automatically install geoson
.
pip install mappyfile
pip install mappyfile-geojson
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'}"
- Seth Girvin @geographika