error in loading local tif files: Map.add_raster(filename, band=[4, 1, 2], layer_name="Color infrared")
#1960
Answered
by
giswqs
wondering516
asked this question in
Q&A
-
it happens in tutorial notebooks url = 'https://github.com/giswqs/data/raw/main/raster/srtm90.tif'
filename = 'dem.tif'
geemap.download_file(url, filename)
Map = geemap.Map()
Map.add_raster(filename, cmap='terrain', layer_name="DEM")
vis_params = {'min': 0, 'max': 4000, 'palette': 'terrain'}
Map.add_colorbar(vis_params, label='Elevation (m)')
Map the error is ---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
Cell In[10], line 2
1 Map = geemap.Map()
----> 2 Map.add_raster(filename, cmap='terrain', layer_name="DEM")
3 vis_params = {'min': 0, 'max': 4000, 'palette': 'terrain'}
4 Map.add_colorbar(vis_params, label='Elevation (m)')
File /opt/anaconda3/envs/GEETutorial/lib/python3.10/site-packages/geemap/geemap.py:2404, in Map.add_raster(self, source, indexes, colormap, vmin, vmax, nodata, attribution, layer_name, zoom_to_layer, visible, array_args, **kwargs)
2401 if isinstance(source, np.ndarray) or isinstance(source, xr.DataArray):
2402 source = array_to_image(source, **array_args)
-> 2404 tile_layer, tile_client = get_local_tile_layer(
2405 source,
2406 indexes=indexes,
2407 colormap=colormap,
2408 vmin=vmin,
2409 vmax=vmax,
2410 nodata=nodata,
2411 attribution=attribution,
2412 layer_name=layer_name,
2413 return_client=True,
2414 **kwargs,
2415 )
2416 tile_layer.visible = visible
2418 self.add(tile_layer)
File /opt/anaconda3/envs/GEETutorial/lib/python3.10/site-packages/geemap/common.py:10918, in get_local_tile_layer(source, port, debug, indexes, colormap, vmin, vmax, nodata, attribution, tile_format, layer_name, return_client, quiet, **kwargs)
10916 else:
10917 if tile_format == "ipyleaflet":
> 10918 tile_layer = get_leaflet_tile_layer(
10919 tile_client,
10920 port=port,
10921 debug=debug,
10922 indexes=indexes,
10923 colormap=colormap,
10924 vmin=vmin,
10925 vmax=vmax,
10926 nodata=nodata,
10927 attribution=attribution,
10928 name=layer_name,
10929 **kwargs,
10930 )
10931 else:
10932 tile_layer = get_folium_tile_layer(
10933 tile_client,
10934 port=port,
(...)
10944 **kwargs,
10945 )
File /opt/anaconda3/envs/GEETutorial/lib/python3.10/site-packages/localtileserver/widgets.py:99, in get_leaflet_tile_layer(source, port, debug, indexes, colormap, vmin, vmax, nodata, attribution, **kwargs)
94 class BoundTileLayer(TileLayer, LocalTileServerLayerMixin):
95 # https://github.com/jupyter-widgets/ipyleaflet/issues/888
96 # https://github.com/ipython/traitlets/issues/626#issuecomment-699957829
97 bounds = Union((Tuple(),), default_value=None, allow_none=True).tag(sync=True, o=True)
---> 99 source, created = get_or_create_tile_client(
100 source,
101 port=port,
102 debug=debug,
103 )
104 url = source.get_tile_url(
105 indexes=indexes,
106 colormap=colormap,
(...)
110 client=True,
111 )
112 if attribution is None:
File /opt/anaconda3/envs/GEETutorial/lib/python3.10/site-packages/localtileserver/client.py:571, in get_or_create_tile_client(source, port, debug)
569 source.shutdown()
570 del source
--> 571 raise e
572 return source, _internally_created
File /opt/anaconda3/envs/GEETutorial/lib/python3.10/site-packages/localtileserver/client.py:565, in get_or_create_tile_client(source, port, debug)
563 try:
564 r = requests.get(source.create_url("api/metadata"))
--> 565 r.raise_for_status()
566 except requests.HTTPError as e:
567 # Make sure to destroy the server and its thread if internally created.
568 if _internally_created:
File /opt/anaconda3/envs/GEETutorial/lib/python3.10/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
1016 http_error_msg = (
1017 f"{self.status_code} Server Error: {reason} for url: {self.url}"
1018 )
1020 if http_error_msg:
-> 1021 raise HTTPError(http_error_msg, response=self)
HTTPError: 502 Server Error: Bad Gateway for url: http://127.0.0.1:59599/api/metadata?&filename=%2FUsers%2Fwondering%2FDocuments%2FCodes%2FGEETutorial%2FTutorialNotebooks%2Fdem.tif my geemap version is |
Beta Was this translation helpful? Give feedback.
Answered by
giswqs
Apr 3, 2024
Replies: 2 comments 2 replies
-
This is localtileserver issue. Please try the following code with your own data. If it does not work, please open an issue on the localtileserver repo. from localtileserver import TileClient, get_leaflet_tile_layer, examples
from ipyleaflet import Map
# Create a TileClient from a raster file
# client = TileClient('path/to/geo.tif')
client = examples.get_san_francisco() # use example data
# Create ipyleaflet TileLayer from that server
t = get_leaflet_tile_layer(client)
# Create ipyleaflet map, add tile layer, and display
m = Map(center=client.center(), zoom=client.default_zoom)
m.add(t)
m |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
giswqs
-
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is localtileserver issue. Please try the following code with your own data. If it does not work, please open an issue on the localtileserver repo.