Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/node-geojson/geojson-stream
Stream features into and out of GeoJSON objects and Feature Collections.
https://github.com/node-geojson/geojson-stream
Last synced: 5 days ago
JSON representation
Stream features into and out of GeoJSON objects and Feature Collections.
- Host: GitHub
- URL: https://github.com/node-geojson/geojson-stream
- Owner: node-geojson
- Created: 2013-10-17T17:45:31.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2019-01-16T22:47:34.000Z (almost 6 years ago)
- Last Synced: 2024-09-19T01:24:44.985Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 54
- Watchers: 54
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-starred - node-geojson/geojson-stream - Stream features into and out of GeoJSON objects and Feature Collections. (others)
README
# geojson-stream
[![Greenkeeper badge](https://badges.greenkeeper.io/tmcw/geojson-stream.svg)](https://greenkeeper.io/)
[![build status](https://secure.travis-ci.org/tmcw/geojson-stream.svg)](http://travis-ci.org/tmcw/geojson-stream)Stream features into and out of [GeoJSON](http://geojson.org/) objects
and Feature Collections. Little more than [JSONStream](https://github.com/dominictarr/JSONStream)
with pre-filled settings.## usage
npm install --save geojson-stream
## api
### `geojsonStream.stringify()`
Returns a transform stream that accepts GeoJSON Feature objects and emits
a stringified FeatureCollection.### `geojsonStream.parse(mapFunc)`
Returns a transform stream that accepts a GeoJSON FeatureCollection as a stream
and emits Feature objects.`mapFunc(feature, index)` is an optional function which takes a `Feature`, and its zero-based index in the `FeatureCollection` and returns either a `Feature`, or null/undefined
if the feature should be omitted from output.## example
```
const geojsonStream = require('geojson-stream');
const fs = require('fs');
const out = fs.createWriteStream('buildings-with-id.geojson');
fs
.createReadStream(`buildings.geojson`)
.pipe(geojsonStream.parse((building, index) => {
if (building.geometry.coordinates === null) {
return null;
}
building.id = index;
return building;
}))
.pipe(geojsonStream.stringify())
.pipe(out);
```