Giter Club home page Giter Club logo

osm2geojsonstream's Introduction

osm2geojsonstream

Streams OSM data in XML format to GeoJSON. Generates GeoJSON features from OSM ways and nodes.

This is a fork from Ryan Clark's osm2geojson library, forked before osm2geojson incorporated osmium.

Install it globally

npm install -g osm2geojsonstream

Use it from the command line like this

osm2geojsonstream -b "[-111.01032257080078,31.314701127170984,-110.68004608154295,31.447492524518246]"

That will download data from the specified area. Make sure it is not more than 0.25 sq.deg. If you have an extracted XML file, you can...

osm2geojsonstream -f /path/to/osm.xml

You may want to redirect the results to a file unless you can read really fast...

osm2geojsonstream -f /path/to/osm.xml > osm.geojson

Use it in another project like this

npm install osm2geojsonstream

... then in your own scripts:

osm2geojsonstream = require("osm2geojsonstream")();
aReadableStream.pipe(osm2geojsonstream).pipe(aWritableStream);

Optional filtering and mapping

The function returned by require('osm2geojsonstream') can take two optional arguments -- a filter function and a mapping function.

A "filter function" should return true for the features you care about, and false for those you don't. Those that return false will not be included in the final GeoJSON FeatureCollection.

For example:

osm2geojsonstream = require("osm2geojsonstream")(function (feature) {
    return feature.geometry.type === 'Polygon';
});

This will provide an output stream of features that only contains polygons.

The second argument you can provide is a "mapping function". This function accepts one GeoJSON feature, and returns a "transformed" version of the feature. You can use this to adjust the features however you wish. For example:

osm2geojsonstream = require("osm2geojsonstream")(null, function (feature) {
    return {
        type: "Feature",
        properties: {
            name: feature.properties.name.toLowerCase() || 'default name',
            transformedWith: 'osm2geojsonstream',
            originalProperties: feature.properties
        },
        geometry: feature.geometry    
    };
});

osm2geojsonstream's People

Contributors

rclark avatar keithrz avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

flaise

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.