1.0.1 • Published 2 years ago
geojson-stream-whatwg v1.0.1
geojson-stream-whatwg
Stream features into and out of GeoJSON objects and Feature Collections. Little more than @streamparser/json with pre-filled settings.
This package is a simple rewrite of Tom MacWrights geojson-stream build on the Streams API.
Installation
npm install geojson-stream-whatwg
API
geojsonStream.stringify()
Returns a transform stream that accepts GeoJSON Feature objects and emits a stringified FeatureCollection.
geojsonStream.parse()
Returns a transform stream that accepts a GeoJSON FeatureCollection as a stream and emits Feature objects.
Example
const response = await fetch('https://example.com/buildings.geojson');
const readableStream = response.body
.pipeThrough(new TextDecoderStream())
.pipeThrough(geojsonStream.parse())
for await (const feature of readStream) {
console.log(feature)
}
Please consult the test file located at test/basic.mjs for more examples.
License
MIT