whosonfirst / py-mapzen-whosonfirst-export

Export tools for the Who's On First documents
BSD 3-Clause "New" or "Revised" License
2 stars 3 forks source link

py-mapzen-whosonfirst-export

Export tools for the Who's On First

Description

This package provides library code and tools for "exportifying" Who's Of First (WOF) GeoJSON documents which makes them ready to be included in a commit or pull request in a https://github.com/whosonfirst-data repository.

When a WOF record is "exportified" a number of derived properties are automatically updated (for example wof:belongsto, src:geom_hash and wof:lastmodified) and the document is formatted according to the WOF style guide (specifically that GeoJSON properties but not geometries be indented).

Install

sudo pip install -r requirements.txt --process-dependency-links .

Caveats

IMPORTANT

This library is provided as-is, right now. It lacks proper documentation which will probably make it hard for you to use unless you are willing to poke and around and investigate things on your own.

Example

Export records to STDOUT

import os
import sys

import mapzen.whosonfirst.utils
import mapzen.whosonfirst.export

if __name__ == "__main__":

    ex = mapzen.whosonfirst.export.stdout()

    for path in sys.argv[1:]:
        f = mapzen.whosonfirst.utils.load_file(path)
        ex.export_feature(f)

Export records to a string

import os
import sys

import mapzen.whosonfirst.utils
import mapzen.whosonfirst.export

if __name__ == "__main__":

    ex = mapzen.whosonfirst.export.string()

    for path in sys.argv[1:]:
        f = mapzen.whosonfirst.utils.load_file(path)
        print ex.export_feature(f)

Export records to a nested directory structure

import os
import sys

import mapzen.whosonfirst.utils
import mapzen.whosonfirst.export

if __name__ == "__main__":

    data_root = "/path/to/data"
    ex = mapzen.whosonfirst.export.flatfile(data_root)

    for path in sys.argv[1:]:
        f = mapzen.whosonfirst.utils.load_file(path)
        ex.export_feature(f)

Tools

wof-exportify

For example:

./scripts/wof-exportify -e stdout -p 101736545.geojson | jq '.properties["wof:name"]'
"Montreal"

See also