osm-p2p-geojson
Export and Import GeoJSON from osm-p2p-db
Last updated 2 months ago by noffle .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install osm-p2p-geojson 
SYNC missed versions from official npm registry.

osm-p2p-geojson

Transform OSM documents in a kappa-osm database to GeoJSON

Table of Contents

Install

npm install osm-p2p-geojson

Usage

var core = require('kappa-core')
var osmdb = require('kappa-osm')
var ram = require('random-access-memory')
var memdb = require('memdb')
var osmGeoJson = require('osm-p2p-geojson')

var osm = osmdb({
  core: core,
  index: memdb(),
  storage: function (name, cb) { cb(null, ram()) }
})

osm.create({
  type: 'node',
  lat: 1,
  lon: -1,
  tags: {
    foo: 'bar'
  }
}, function (err) {
  queryStreaming()
  queryCallback()
})

function queryStreaming () {
  var q = osm.queryStream([[-Infinity, Infinity], [-Infinity, Infinity]])
  var geo = osmGeoJson(osm)

  q.pipe(geo)

  geo.on('data', console.log)
}

function queryCallback () {
  osm.query([[-Infinity, Infinity], [-Infinity, Infinity]], function (err, docs) {
    osmGeoJson(osm, { docs: docs }, function (err, geojson) {
      console.log(geojson)
    })
  })
}

API

var osmGeoJson = require('osm-p2p-geojson')

var importer = osmGeoJson.importer(osm)

Create an importer for importing GeoJSON objects into the given osm-p2p database. Can track progress through listening to the 'import' event. This event gives you the index of the most recently imported data and how many documents will be imported in total. If you try to import twice with the same importer, the callback will be called with an error.

If you want to import twice, create another importer.

var importer = osmGeoJson.importer(osm)
importer.on('import', function (index, total) {
  console.log('import', index, total)
})
importer.importFeatureCollection(geojson, onDone)

var stream = osmGeoJson(osm[, options][, callback])

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 - a kappa-osm
  • docs - a list of OSM documents. If not provided here, they must be written to the returned stream.
  • options.metadata - Array of metadata properties to include as GeoJSON properties. Defaults to ['id', 'version', 'timestamp']
  • options.objectMode - when true will return a stream of GeoJSON feature objects instead of stringified JSON. Default false. You can also use osmGeoJson.obj()
  • options.map - a function that maps a Feature to another Feature. Defaults to the no-op function 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) and tags (a hash of tag key-value pairs) and should return true 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 Features into a FeatureCollection or otherwise further transform them.

N.B.: Only "interesting" elements are exported. An interesting element is defined as an element that is both a) not malformed, and b) has a populated "tags" object set on it.

Contribute

PRs accepted.

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Gregor MacLennan

Current Tags

  • 4.0.7                                ...           latest (2 months ago)

19 Versions

  • 4.0.7                                ...           2 months ago
  • 4.0.6                                ...           2 months ago
  • 4.0.5                                ...           3 months ago
  • 4.0.4                                ...           3 months ago
  • 4.0.3                                ...           4 months ago
  • 4.0.2                                ...           5 months ago
  • 4.0.1                                ...           5 months ago
  • 4.0.0                                ...           7 months ago
  • 3.1.2                                ...           a year ago
  • 3.1.1                                ...           a year ago
  • 3.1.0                                ...           2 years ago
  • 3.0.4                                ...           2 years ago
  • 3.0.3                                ...           2 years ago
  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 21
Dependencies (18)
Dev Dependencies (11)

Copyright 2014 - 2017 © taobao.org |