Skip to main content

A mappyfile plugin to convert GeoJSON to inline Mapfile features

Project description

Version Build Status

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.

https://raw.githubusercontent.com/geographika/mappyfile-geojson/master/polygon.png

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'}"

Author

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

mappyfile-geojson-0.1.4.zip (11.4 kB view hashes)

Uploaded Source

Built Distribution

mappyfile_geojson-0.1.4-py2.py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page