## Wrangling GeoTIFFs in the browser Nick Forbes-Smith
CSIRO's Data61 — RMIT University
Hobart, Tasmania, Australia
The first
(and last)
FOSS4G talk on Geotiff.js!
FOSS4G 2019 - Discover huge raster files in the Browser with geotiff.js - Fabian Schindler
FOSS4G 2019 - Algorithm Walk-through: How to Visualize a Large GeoTIFF on Your Web Map - Daniel J. Dufour
FOSS4G 2019 - Interactive (EO) data visualization in the web - Lubomír Bucek & Daniel Santillan Pedrosa
FOSS4G 2019 - Breaking the curse of raster processing software-as-a-service - Iván Sánchez Ortega
FOSS4G 2018 - Wave Good-Bye to Buttonology: Satellite Imagery Analysis Made Easy with GeoTIFF.io - Daniel Dufour & Stephen Peyton
FOSS4G 2016 - geotiff.js and plotty.js - Visualizing Scientific Raster Data in the Browser - Fabian Schindler
...
...
## I make - Web map apps w/ - distributed job processing back-ends
for natural hazard modeling
and heaps of GeoTIFFs
Wildfire simulation
Wildfire simulation
Climate change risk analytics
Evacuation simulation
Evacuation simulation
Flood Simulation
Flood Simulation
## JS libraries
Angular, PrimeNG
Mapbox GL JS, Terria/Cesium
d3
,
Plotty
Geotiff.js
,
Georaster
GPU.js
,
Geoblaze
## Show GeoTIFF on Web‑map
Not going to talk about GeoTIFF
-------------- Usual method: WMS
### WMS 1. Load GeoTIFF into WMS Server (GeoServer) 2. Create style(s) 3. Publish 4. Client (mapbox, leaflet...) requests static image tiles
Okay, this is great -------------- We're done right?
...GeoTIFFs are being created on demand?
...interactive/dynamic styling?
...inspect raw values?
...run script on values?
...I have millions (or **BILLIONS!**) of geotiffs?
### So many requests to the server! Even if the browser already has the data
Forget that rubbish! ## We have GeoTIFF.js and WebGL!
I'm joking WMS is not rubbish
### GeoTIFF.js 1. Client (mapbox, leaflet...) requests and renders GeoTIFF...
Single layer
Colour scale
Set min/max and clamp
Blending layers with CSS
## Web-based Geotiff Analytics -------------- Usual method: WPS
### WPS 1. Write python script - Read in data via WCS - Crunch the numbers - Return result 2. Load scripts into WPS server (eg PyWPS) 3. Publish 4. Client executes WPS processes
Okay, this is great too
...I already have the data in the browser?!
...100s of requests using the same data in realtime?
...more requests to the server!
Ridiculous
But we can also do this with ## JavaScript in the browser!
Wooo "edge computing"!
Contouring
Statistics
Raster algebra
## What! How? -------------- - Fetch + decode data —
Geotiff.js
- Data wrapper —
Georaster
- Visualise —
Plotty
- Analytics —
Geoblaze
,
GPU.js, (d3)
## Geotiff.js This does all the hard work! Pure JavaScript implementation of Geotiff: - Reads in file - Supports HTTP range requests for subsets - bbox or band - Decodes and uncompresses
From
https://geotiffjs.github.io/geotiff.js/
```js // Fetch a GeoTIFF const response = await fetch(someUrl); // Decode... const arrayBuffer = await response.arrayBuffer(); const tiff = await GeoTIFF.fromArrayBuffer(arrayBuffer); const image = await tiff.getImage(); // Get pixels const pixels = await image.readRasters(); // Get some properties const origin = image.getOrigin(); const resolution = image.getResolution(); const bbox = image.getBoundingBox(); ... ```
## Georaster > Wrapper around Georeferenced Rasters GeoTIFF, NetCDF, JPG, and PNG — provides a standard interface
Also simplifies GeoTIFF.js usage
From
https://github.com/GeoTIFF/georaster
```js // Fetch const response = await fetch(someUrl); const arrayBuffer = await response.arrayBuffer(); const georaster = await parseGeoraster(arrayBuffer) // Get pixels const pixels = georaster.values; // Get some properties const projection = georaster.projection; ... ```
## Plotty Colourise 2d raster using Canvas API and WebGL (with JS fallback) Set value domain, clamp, transform matrix, colorscale, raster/band algebra
From
https://github.com/santilland/plotty
```js plot = new plotty.plot({ canvas: document.getElementById("canvas"), data: somePixels, width: width, height: height, domain: [-1, 1], colorScale: 'viridis' }); plot.render(); ```
## Geoblaze - Basic statistics (min, max, mean, mode) - Band arithmetic and histogram generation No WebGL - all done on CPU.
From
https://docs.geoblaze.io/
```js const mean = geoblaze.mean(georaster, geometry); const ndvi = geoblaze.bandArithmetic(georaster, '(c - b)/(c + b)'); const histogram = geoblaze.histogram(georaster, geometry, options); ```
## GPU.js Kernel functions - matrix algebra - Raster calculation - Interpolation - Reprojection...
and other crazy stuff
From
https://github.com/gpujs/gpu.js
```js import { GPU } from 'gpu.js'; const gpu = new GPU(); const multiplyMatrix = gpu.createKernel(function(a: number[][], b: number[][]) { let sum = 0; for (let i = 0; i < 512; i++) { sum += a[this.thread.y][i] * b[i][this.thread.x]; } return sum; }).setOutput([512, 512]); const c = multiplyMatrix(a, b) as number[][]; ```
## D3 - contouring / isobands - streamlines - arrows / barbs
From
https://github.com/d3/d3-contour
```js const contours: MultiPolygon[] = d3.contours() .size([width, height]) .thresholds([0,1,2,3,...]) (pixelValues); ```
## I want this now! -------------- -
geotiff.io/
- have a play with geotiffs in the browser and geoblaze - Leaflet -
georaster-layer-for-leaflet
- OpenLayers -
ol-geotiff
- Cesium/Terria, Mapbox...
## Limitations -------------- - File size - Projections - Client-side computation (GPU) - Service-oriented or API? - Client-side complexity
## File size - GeoTIFF files can be large - Don't want to load entire file! - Cloud Optimised GeoTIFFs (COGs) - Layout friendly for network consumption
## Projection Web mercator...
## Client-side computation Uncompress, render pixels to canvas... Analysing values...
## WMS is service oriented JS librares are for client-side use
Can be used with Node.js but Python libraries are better!
## Client-side complexity Just want to show static imagery? Probably not worth it - WMS is supported by everything!
## Demo
## Future -------------- - COG / Satelite imagery performance - NetCDF - Reprojection (WebGL?) - Caching - GUI raster formula editor
## Other cool things
### Hillshade
### Reprojection
### 3D
### PNG raw 24 bit integer packed into RGB channels - see mapbox elevation tiles Hybrid WMS approach?
## Thanks -------------- Questions?