Transform OSM documents in an osm-p2p-db to GeoJSON
npm install osm-p2p-geojson
// streaming:
var getGeoJSON = require('osm-p2p-geojson')
var stream = getGeoJSON(osm)
var q = osm.query({
bbox: [-Infinity, -Infinity, Infinity, Infinity]
})
// outputs geojson object
q.pipe(stream).pipe(process.stdout)
// or as callbacks:
osm.query({
bbox: [-Infinity, -Infinity, Infinity, Infinity]
}, function (err, docs) {
getGeoJSON(osm, { docs: docs }, function (err, geojson) {
console.log(geojson)
// outputs geojson object
})
})
var getGeoJSON = require('osm-p2p-geojson')
Creates a TransformStream that will take as input a stream of osm-p2p documents
and outputs a stream of GeoJSON. If you prefer a callback rather than a stream
for reading output, you can pass callback(err, geojson)
.
osm
- aosm-p2p-db
docs
- a list of OSM documents. If not provided here, they must be written to the returnedstream
.options.metadata
- Array of metadata properties to include as GeoJSON properties. Defaults to['id', 'version', 'timestamp']
options.objectMode
- whentrue
will return a stream of GeoJSON feature objects instead of stringified JSON. Defaultfalse
. You can also usegetGeoJSON.obj()
options.map
- a function that maps aFeature
to anotherFeature
. Defaults to the no-opfunction mapFn (feature) { return feature }
options.polygonFeatures
- either a list of tag keys and values that are polygons (for schema see https://github.com/tyrasd/osm-polygon-features/blob/master/schema.json) or a function that will be called with two arguments:coordinates
(from the GeoJSON geometry) andtags
(a hash of tag key-value pairs) and should returntrue
for polygons.
N.B.: If options.objectMode
is enabled and no callback
is provided, the
resultant object stream will emit GeoJSON Feature
objects. This is not valid
GeoJSON as-is: the recipient of the stream will need to either wrap these
Feature
s into a FeatureCollection
or otherwise further transform them.
PRs accepted.
Small note: If editing the Readme, please conform to the standard-readme specification.
MIT © Gregor MacLennan