https://github.com/chrispahm/geojson-stream-whatwg
Stream features into and out of geojson, using the Streams API.
https://github.com/chrispahm/geojson-stream-whatwg
Last synced: 2 months ago
JSON representation
Stream features into and out of geojson, using the Streams API.
- Host: GitHub
- URL: https://github.com/chrispahm/geojson-stream-whatwg
- Owner: chrispahm
- License: mit
- Created: 2022-07-18T10:02:22.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-19T16:16:17.000Z (almost 3 years ago)
- Last Synced: 2025-01-29T14:23:05.489Z (4 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# geojson-stream-whatwg
Stream features into and out of [GeoJSON](http://geojson.org/) objects
and Feature Collections. Little more than [@streamparser/json](https://github.com/juanjoDiaz/streamparser-json)
with pre-filled settings.This package is a simple rewrite of Tom MacWrights [geojson-stream](https://github.com/node-geojson/geojson-stream) built on the [Streams API](https://developer.mozilla.org/en-US/docs/Web/API/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
[Observable Notebook](https://observablehq.com/@chrispahm/streaming-geojson)```js
const response = await fetch('https://example.com/buildings.geojson');
const readableStream = response.body
.pipeThrough(new TextDecoderStream())
.pipeThrough(geojsonStream.parse())const reader = readableStream.getReader();
while (true) {
const { done, value: feature } = await reader.read();
if (done) break;
console.log(feature)
}
```Please consult the test file located at test/basic.mjs for more examples.
## License
MIT