Skip to content

Fail to load raster layer: ImageOverlay #1145

Open
@hillsonghimire

Description

@hillsonghimire

I tried the following code to visualize a single band raster image form landsat 8, but the image cannot render over the map. The broken thumbnail appears over the map layer.

I am using google colab as notebook server.

image

import rasterio
from pyproj import Proj, transform

from ipyleaflet import Map, ImageOverlay

# Open the raster file using rasterio
path = '/content/LC08_L1TP_126049_20200301_20200313_01_T1_B1.TIF'
src = rasterio.open(path)

with rasterio.open(path) as src:
    bounds = src.bounds
    crs = src.crs
utm_crs = crs.to_proj4()
wgs84_crs = Proj(init='epsg:4326')

# Convert UTM bounds to latitude and longitude
left, bottom = transform(utm_crs, wgs84_crs, bounds.left, bounds.bottom)
right, top = transform(utm_crs, wgs84_crs, bounds.right, bounds.top)

# print(left, right, )
# print(bottom, top,)

m = Map(center=(((bottom+top)/2, (left+right)/2)), zoom=3)

# # Create an ImageOverlay and add it to the map
overlay = ImageOverlay(url='/content/LC08_L1TP_126049_20200301_20200313_01_T1_B1.TIF', bounds=((bottom, left), (top, right)))
m.add_layer(overlay)

# # Display the map
m

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions