opengeos / leafmap

A Python package for interactive mapping and geospatial analysis with minimal coding in a Jupyter environment
https://leafmap.org
MIT License
3.19k stars 377 forks source link

add_raster does not work on Jupyter of visual studio code using remote development #904

Closed karantai closed 1 week ago

karantai commented 1 week ago

Environment Information

Description

From my local computer I have connected to my remote server using remote development plug in , in VSCode. I have tried to visualize the geotiff images that reside on my server, in Jupyter (through VSCode) but only the basemap appears and no Geotiffs, without any warning.

Am I missing something?

What I Did

conda install conda-forge::jupyter-server-proxy
conda install conda-forge::localtileserver
conda install conda-forge::leafmap

I do not know if the following command is necessary for me:

os.environ['LOCALTILESERVER_CLIENT_PREFIX'] = 'proxy/{port}'
import leafmap
m = leafmap.Map(center=client.center(), zoom=client.default_zoom)

input_file = 'path/to/test.tif'
m.add_raster(input_file, band=[4, 3, 2], vmin=1, vmax=100, layer_name="Landsat")
m
giswqs commented 1 week ago

See https://github.com/banesullivan/localtileserver/issues/181

karantai commented 1 week ago

I tried it but without positive results. A tab opens locally and it immediately opens the default San Francisco geotiff and zooms there.

Here is some extra info


--------------------------------------------------------------------------------
  Date: Thu Sep 26 12:41:05 2024 UTC

                  OS : Linux (Ubuntu 22.04)
              CPU(s) : 40
             Machine : x86_64
        Architecture : 64bit
                 RAM : 188.4 GiB
         Environment : Jupyter
         File system : ext4

  Python 3.12.6 | packaged by conda-forge | (main, Sep 22 2024, 14:16:49) [GCC
  13.3.0]

     localtileserver : 0.10.3
               click : 8.1.7
               flask : 3.0.3
       flask_caching : 1.10.1
          flask_cors : 5.0.0
         flask_restx : 1.3.0
               numpy : 2.1.1
            rasterio : 1.3.11
           rio_cogeo : 5.3.4
           rio_tiler : 6.7.0
       server_thread : 0.2.0
            werkzeug : 3.0.4
              folium : 0.17.0
          ipyleaflet : 0.19.2
jupyter_server_proxy : 4.4.0
          jupyterlab : 4.2.5
          matplotlib : 3.9.2
             shapely : 2.0.6
           traitlets : 5.14.3
--------------------------------------------------------------------------------
karantai commented 1 week ago

I connect to my remote server using a VPN, maybe that's why I cannot visualize anything?

lopezvoliver commented 1 week ago

Try forwarding the port manually

see:

https://github.com/opengeos/leafmap/discussions/677

karantai commented 1 week ago

I solved the issue by assigning a port manually in these lines:

client = TileClient(output_file, port=40_000)
t = get_leaflet_tile_layer(client, port=40_000)

Commenting this line:

#os.environ['LOCALTILESERVER_CLIENT_PREFIX'] = 'proxy/{port}'

and did port forwarding as mentioned here:

https://github.com/banesullivan/localtileserv)er/issues/181
giswqs commented 1 week ago

@karantai Thank you for reporting back. Where did you comment out the following line? I wondered if we should make changes to the leafmap codebase so that users don't have to make changes on their own.

#os.environ['LOCALTILESERVER_CLIENT_PREFIX'] = 'proxy/{port}'