This repository provides some command line utilities for working with Who's on First data. For the Who's on first importer, which is unrelated, see this repo.
[BETA] This repo is still a work-in-progress.
npm i -g @whosonfirst/wofTo avoid reinventing the wheel, some code in this repo will 'shell out' to execute a common *nix command line application instead of native javascript code.
Ideally we'd like to only depend on utilities which come standard on most *nix systems, but it might be the case that your environment lacks one or more of these programs:
# check dependencies
which cat find node git bzip2 gzip pv bsdtar docker# ubuntu
sudo apt-get install git bzip2 gzip pv libarchive-tools docker
# mac OSX
brew install git bzip2 gzip pv libarchive dockerwof --help
wof <cmd> [args]
Commands:
wof bundle interact with tar bundles
wof feature misc functions for working with feature streams
wof fs interact with files in the filesystem
wof git interact with git repositories
wof sqlite interact with SQLite databases
Options:
--version Show version number [boolean]
--verbose, -v enable verbose logging [boolean] [default: false]
--help Show help [boolean]interact with git repositories
wof git export <repo> export features from a git repo
wof git list <repo> list paths in a git repoBoth 'bare' and 'checkout' style clones are supported, these commands use the git archive command and so do not require the geojson files to be present in the filesystem.
If you don't need a working copy of the files you can save disk space by using a --bare style clone.
The following command uses only 661M of disk space, compared to 3.8G for the equivalent 'checkout' style clone which also extracts ~400k files to the filesystem.
git clone \
--bare \
--depth 1 \
--single-branch \
--branch master \
https://github.com/whosonfirst-data/whosonfirst-data-admin-us.git us-barelist paths in a git repo
wof git list /data/wof
... list of geojson fileswof git list /data/wof --path data/101/914/241/101914241.geojson
... list of geojson files matching the path argumentexport features from a git repo
wof git export /data/wof
... stream of geojson featureswof git export /data/wof --path data/101/914/241/101914241.geojson
... stream of geojson features matching the path argumentinteract with SQLite databases
wof sqlite export <db> export features from a SQLite database
wof sqlite import <db> import features into a SQLite databaseexport features from a SQLite database
wof sqlite export wof.db
... stream of geojson featuresProvide a custom SQL statement with --sql, or use one of the built-in aliases @all (default) or @exportable:
wof sqlite export --sql='@exportable' wof.dbimport features into a SQLite database
cat 101914243.geojson | wof sqlite import --rm wof.dbmisc functions for working with feature streams
wof feature format reformat a feature stream
wof feature map <script> apply user-provided map function to features
wof feature ogr <dst> export features using ogr2ogr
wof feature properties output feature properties
wof feature stats generate aggregate statsreformat a feature stream
cat jsonstream | wof feature format
... stream of minified json, one item per linecat jsonstream | wof feature format --open $'[\n' --sep $'\n,\n' --close $'\n]'
... stream of minified json, with array header, footer and separatorcat 101914243.geojson | wof feature format --indent 2
... stream of pretty printed jsonprovide a javascript mapping function to rewrite the output stream
# my-custom-mapper.js
module.exports = (feat, params) => featcat jsonstream | wof feature map my-custom-mapper.js
... stream of json after the map function has been appliedparameters can be passed to the view as either a JSON object:
# using 'params' (note the plural)
cat jsonstream | wof feature map my-custom-mapper.js \
--params='{"foo": "bar", "faz": "baz"}'or as key/value pairs:
# using 'param'
cat jsonstream | wof feature map my-custom-mapper.js \
--param="foo=bar" \
--param='faz=baz'Some built-in views are bundled in the whosonfirst/views directory:
cat jsonstream | wof feature map \
view://shapefile.js \
--param="placetype=locality" \
--param='geom=.*point'
... stream of json after the map function has been applieda convenience command for piping a feature stream into ogr2ogr:
cat jsonstream | wof feature ogr example.shp --format='Esri Shapefile'cat jsonstream | wof feature ogr example.gpkg --format='GPKG'cat jsonstream | wof feature ogr example.parquet --format='Parquet'use a dockerized version of ogr2ogr (to avoid installing locally):
wof feature ogr --dockersee: https://gdal.org/programs/ogr2ogr.html
a convenience command for piping a feature stream into tippecanoe:
cat jsonstream | wof feature tippecanoe --unlink example.pmtilesuse a dockerized version of tippecanoe (to avoid installing locally):
wof feature tippecanoe --dockersee: https://github.com/mapbox/tippecanoe
output feature properties
cat 101914243.geojson | wof feature properties -p 'wof:id' -p 'wof:placetype'
{"wof:id":101914243,"wof:placetype":"locality"}generate aggregate stats
cat 101914243.geojson | wof feature stats
{"locality":1}