question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImageOverlay or TileLayer with local files

See original GitHub issue

I was trying the Velocity demo with a smaller wind dataset and would like to add a local file rasters (higher quality terrain hillshade) or a local Tilemap I created with QGIS to the map. Those files are on a different drive though, and I can´t figure out how to get them to display. It seems absolute paths don´t work even if I try it with the same file I use for the relative path:

# png is in the same folder as the notebook
# works
rel_url = './IPy_header.png'
io1 = ImageOverlay(url=rel_url, bounds=m.bounds)
m.add_layer(io1)

# does not work
abs_url = 'file:///E:/JUPYTER/Velocity/IPy_header.png'
io2 = ImageOverlay(url=abs_url, bounds=m.bounds)

m.add_layer(io2)

How can I point to a local file or a Tilemap and get it to display?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:23 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
banesullivancommented, Apr 29, 2022

Thought I’d chime in and give a plug for something I developed to solve the issue of viewing local raster files with ipyleaflet: https://github.com/banesullivan/localtileserver

In essence, it’s a little package that will launch a local tile server in a background thread for use with ipyleaflet. Check out the README for an example, (the code here is subject to change):

from localtileserver import get_leaflet_tile_layer
from ipyleaflet import Map, ScaleControl, FullScreenControl, SplitMapControl

m = Map(
        center=(37.7249511580583, -122.27230466902257),
        zoom=9, crs=projections.EPSG3857,
       )

# Create two tile layers from 2 seperate raster files
l = get_leaflet_tile_layer('~/Desktop/TC_NG_SFBay_US_Geo.tif',
                           band=1, palette='matplotlib.Viridis_20', vmin=50, vmax=200)
r = get_leaflet_tile_layer('~/Desktop/small.tif',
                           band=2, palette='matplotlib.Plasma_6', vmin=0, vmax=150)

control = SplitMapControl(left_layer=l, right_layer=r)
m.add_control(control)

m.add_control(ScaleControl(position='bottomleft'))
m.add_control(FullScreenControl())
m

ipyleaflet

1reaction
martinRenoucommented, May 26, 2020

The discussion is drifting away from the original purpose of the issue.

Would you mind opening another issue or ask your question on another channel?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How I can load tileLayer in Leaflet framework using local tiles?
How do you load a GeoJSON file in Leaflet? 1 · Use Lambert 93 imageOverlay with Leaflet on top of OSM tiles layer...
Read more >
Local Tile Layer — ipyleaflet documentation
LocalTileLayer class. Custom tile layer using local tile files. path#. Path to your local tiles. In the classic Jupyter Notebook ...
Read more >
Leaflet library doesn't work for adding image on the map
The culprit is (at least) var imageUrl = 'C:/etna.jpg' . Browsers will prevent you from loading files from the local File System for...
Read more >
leafmap module
class ImageOverlay(ipyleaflet.ImageOverlay): """ImageOverlay class. Args: url (str): http URL or local file path to the image. bounds (tuple): bounding box ...
Read more >
Plugins - Leaflet - a JavaScript library for interactive maps
Display small and large GeoTIFF files with configurable resolution. ... A simple WMTS Tile Layer plugin for Leaflet. ... A TileLayer for GeoJSON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found