glad-stream-decoder
Version:
Transform stream to decode GLAD forest alerts
86 lines (57 loc) • 2.95 kB
Markdown
[](https://github.com/RichardLitt/standard-readme)
> Transform stream that decodes GLAD forest alerts
[](https://www.globalforestwatch.org/) publishes weekly deforestation alerts as PNG map tiles. The data of the alert, the confidence level and intensity is encoded to the tile. This module decodes that information and creates an image tile with the alerts colored with the alpha transparency representing their intensity.
The transform stream expects raw image data, as you would get from reading the image data from the canvas. To decode a PNG to raw image data, and to re-encode the output to PNG, use [`png-stream`](https://github.com/devongovett/png-stream)
- [Install](
- [Usage](
- [API](
- [Maintainers](
- [Contribute](
- [License](
```sh
npm i glad-stream-decoder
```
```js
var fs = require('fs')
var path = require('path')
var GLADStreamDecoder = require('glad-stream-decoder')
var PNGDecoder = require('png-stream/decoder')
var PNGEncoder = require('png-stream/encoder')
// encoded.png is an PNG encoded with date, confidence + intensity from
// http://wri-tiles.s3.amazonaws.com/glad_prod/tiles/{z}/{x}/{y}.png
var rs = fs.createReadStream('encoded.png'))
var ws = fs.createWriteStream('decoded.png'))
rs
.pipe(new PNGDecoder())
.pipe(new DecodeGLADStream({
// Only show alerts since this date
since: new Date(2017, 0, 1),
// Color alerts green
color: '#00FF00'
}))
.pipe(new PNGEncoder())
.pipe(ws)
```
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
- [GLADStreamDecoder](
Transforms an encoded rgb image stream (a buffer of r,g,b values in order)
from GLAD alerts into an rgba image stream with alerts as colored pixels
`opts.color` and the intensity as the transparency of the pixel.
**Parameters**
- `opts` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `opts.color` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** CSS color string or [red, green, blue] array for color of pixels
- `opts.since` **[date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)** Date object, filters alerts since this date
## Maintainers
[@gmaclennan](https://github.com/gmaclennan)
## Contribute
PRs accepted.
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## License
MIT © 2018 Digital Democracy