3

I want to use ImageOverlay function in ipyleaflet by below code, it only shows openstreetmap without geotiff layer, How can I do it?

from ipyleaflet import Map, ImageOverlay

m = Map(center=(31, 48), zoom=9)
image = ImageOverlay(url="D:/aa//IDW.tif",
        bounds=((30, 46.1), (32.5, 48.8)))

m.add_layer(image);
m
HMadadi
  • 391
  • 5
  • 22

2 Answers2

1

You can only add relative local paths (as mentioned by @Darwin1871)

Here is a snapshot from the docs

enter image description here

Sam Murphy
  • 815
  • 11
  • 23
1

You can convert the image into a base64 string:

import base64

with open("D:/aa/IDW.png", "rb") as file:
    base64_encoded = base64.b64encode(file.read())
    
image = ImageOverlay(
    url="data:image/png;base64," + base64_encoded.decode(),
    bounds=((30, 46.1), (32.5, 48.8))
)

Since TIFF images are not supported by many browsers (Wikipedia), rather use PNG or JPEG.

F1refly
  • 336
  • 2
  • 7