Coder Social home page Coder Social logo

osm-p2p-geojson's Introduction

osm-p2p-geojson

Transform OSM documents in an osm-p2p-db to GeoJSON

Table of Contents

Install

npm install osm-p2p-geojson

Usage

// 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
  })
})

API

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

var stream = getGeoJSON(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 osm-p2p-db
  • 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 getGeoJSON.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.

Contribute

PRs accepted.

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

License

MIT © Gregor MacLennan

osm-p2p-geojson's People

Contributors

hackergrrl avatar gmaclennan avatar noffle avatar sethvincent avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.