Serverless GIS


The above map loads 1 raster and 1 vector layer in a serverless manner. Mouse over waterbody for more info. Click on map to load waterbody info near point of click.

Update: I've created an entirely new demo map with 8 COG and 19 FGB layers using the process described below. The map is created with vanilla JavaScript/HTML/CSS accessing data directly from cloud storage. The 3 tile layer base maps are 3rd party end points and require no care/feeding. The index.html can be served from the cloud storage or existing web server. This is as simple and painless as it gets.

What is Serverless?
Serverless is a generic term I'm using to describe a web client/app that loads/processes data directly from cloud network storage (such as S3) without the need for an intermediate back-end resource (server, container or service).

What are the benefits of Serverless?
The vast majority of maps on the internet are static raster/vector tiles/json served on backend servers using complex services, databases, bloated python/npm code, massive tile caches and expensive resources. Using Cloud Optimized GeoTIFF (COG) for raster and FlatGeoBuf (FGB) for lossless vector on static data negates the need for backend code and expensive resources.

When should Serverless be avoided?
In situations where on demand analysis between multiple/large datasets is needed, it's easy to overwhelm a client's resouces. While analysis can and should be done with serverless, it's a fine line when and where analysis should be done. Consider your own organization and you'll probably find much of what you do can be pushed onto the client and off backend servers.

But, you need a tile cache!
That's exactly what COG is; it has overviews built in and acts as a tile cache. COG has grown wildly in the last few years. COG use range requests to extract part of a raster file out of cloud storage, this includes those small overviews that act as a tile cache. The above map uses a 1.5GB National Land Cover raster and the associated color table. Only overviews or small sections are used to draw the map layer depending on zoom and extent. The entire file is never downloaded. The inital load of the above map downloads < 1M of raster data.

FGB is an indexed vector data format. Like COG, range requests are used to extract part or all of the data. It's extremely fast. It can also be extremely slow if you request a large amount of data from the file.

Creating a COG from GeoTIFF or other raster type using GDAL:
gdalwarp -f COG -co TILING_SCHEME=GoogleMapsCompatible -co COMPRESS=DEFLATE -t_srs EPSG:4326 nlcd.tif nlcd_cog.tif

Creating a FlatGeoBuf from shapefile or other vector type using GDAL:
ogr2ogr -f FlatGeobuf -nln waterbody -t_srs EPSG:4326 -nlt PROMOTE_TO_MULTI -makevalid waterbody.fgb waterbody.shp

Data & Software
As mentioned, the above map uses a 1.5GB Land Cover raster COG and a 500MB National Hydro data vector FGB. Only CONUS named waterbodies are included. A single click on the map will load all waterbodies within .2 degree bounding box of the mouse click. Vanilla JavaScript packages used are: Leaflet, GeoRaster, GeoRaster-Layer-For-Leaflet and FlatGeoBuf-json.

Have Fun! © 2005-2023 - W3C - @postholer