You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just figured out how to visualize in-memory raster dataset with localtileserver, making it possible to visualize rasterio/xarray datasets without writing files to hard drive. This is exciting!
importrasteriofromipyleafletimportMapfromlocaltileserverimportTileClient, get_leaflet_tile_layer# Open a rasterio datasetdataset=rasterio.open('https://open.gishub.org/data/raster/srtm90.tif')
data_array=dataset.read(1)
# Do some processing on the data arraydata_array[data_array<1000] =0# Create rasterio dataset in memorymemory_file=rasterio.MemoryFile()
raster_dataset=memory_file.open(driver='GTiff',
height=data_array.shape[0],
width=data_array.shape[1],
count=1,
dtype=str(data_array.dtype),
crs=dataset.crs,
transform=dataset.transform)
# Write data array values to the rasterio datasetraster_dataset.write(data_array, 1)
raster_dataset.close()
# Read the dataset from memorydataset_reader=rasterio.open(raster_dataset.name, mode='r')
# Create a TileClient and a Leaflet mapclient=TileClient(dataset_reader)
t=get_leaflet_tile_layer(client, cmap='terrain', vmin=100, vmax=3000)
m=Map(center=client.center(), zoom=client.default_zoom)
m.add_layer(t)
m
The text was updated successfully, but these errors were encountered:
Just figured out how to visualize in-memory raster dataset with localtileserver, making it possible to visualize rasterio/xarray datasets without writing files to hard drive. This is exciting!
The text was updated successfully, but these errors were encountered: