☁️ Remote Cloud Optimized GeoTiffs (COGs)#
While localtileserver
is intended to be used only with raster files existing
on your local filesystem, there is support for URL files through GDAL’s
Virtual Storage Interface.
Simply pass your http<s>://
or s3://
URL to the TileClient
. This will
work quite well for pre-tiled Cloud Optimized GeoTiffs, but I do not recommend
doing this with non-tiled raster formats.
For example, the raster at the url below is ~3GiB but because it is pre-tiled, we can view tiles of the remote file very efficiently in a Jupyter notebook.
from localtileserver import get_folium_tile_layer, get_leaflet_tile_layer
from localtileserver import TileClient
import folium, ipyleaflet
url = 'https://github.com/giswqs/data/raw/main/raster/landsat7.tif'
# First, create a tile server from the URL raster file
client = TileClient(url)
Here we can create a folium map with the raster overlain:
# Create folium tile layer from that server
t = get_folium_tile_layer(client)
m = folium.Map(location=client.center(), zoom_start=client.default_zoom)
m.add_child(t)
m
Or we can do the same ipyleaflet:
# Create ipyleaflet tile layer from that server
l = get_leaflet_tile_layer(client)
m = ipyleaflet.Map(center=client.center(), zoom=client.default_zoom)
m.add(l)
m
Note
Note that the Virtual Storage Interface is a complex API, and TileClient
currently only handles vsis3
and vsicurl
. If you need a different VFS
mechanism, simply create your /vsi
path and pass that to TileClient
.