### Install dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/112_quackosm.ipynb Uncomment and run this command to install the necessary libraries. ```python # %pip install -U leafmap quackosm ``` -------------------------------- ### Environment Setup Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/47_numpy_to_cog.ipynb Commands to create a conda environment and install necessary dependencies. ```bash conda create -n cog python=3.9 conda install mamba -c conda-forge mamba install leafmap rio-cogeo -c conda-forge ``` -------------------------------- ### Install and Initialize Leafmap Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/10_add_vector.ipynb Install the library and initialize the map object. ```python # !pip install leafmap ``` ```python import leafmap ``` ```python m = leafmap.Map() m ``` -------------------------------- ### Install dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/00_key_features.ipynb Install the necessary packages to run leafmap examples. ```python # !pip install leafmap geopandas pycrs osmnx ``` -------------------------------- ### Install required packages Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/55_lidar.ipynb Commands to set up the environment and install necessary dependencies. ```bash conda create -n geo python conda activate geo conda install -c conda-forge mamba mamba install -c conda-forge pygis pip install laspy[lazrs] ``` -------------------------------- ### Install leafmap and overturemaps Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/97_overture_data.ipynb Uncomment and run this command to install the necessary packages. ```python # %pip install -U leafmap overturemaps ``` -------------------------------- ### Install dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/56_download_ned.ipynb Install the necessary packages for the notebook. ```python # !pip install leafmap ``` ```python # !pip install geopandas rasterio ``` -------------------------------- ### Start local server Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/pmtiles.ipynb Start a local server to host the PMTiles file. ```python leafmap.start_server(port=8000) ``` -------------------------------- ### Install dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/87_actinia.ipynb Install the required Actinia Python client library. ```python # %pip install -U leafmap ``` ```python %pip install actinia_python_client ``` -------------------------------- ### Install dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/nasa_opera.ipynb Install the required leafmap and earthaccess packages. ```python # %pip install -U "leafmap[maplibre]" earthaccess ``` -------------------------------- ### Install and import leafmap Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/115_terrascope.ipynb Install the library and import the necessary modules. ```python # %pip install -U leafmap ``` ```python import leafmap import leafmap.terrascope as terrascope ``` -------------------------------- ### Install dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/75_segment_anything.ipynb Install the necessary libraries for leafmap and segment-geospatial. ```python # %pip install leafmap ``` ```python # %pip install segment-geospatial localtileserver ``` -------------------------------- ### Setup Conda Environment Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/14_postgis.ipynb Commands to create a dedicated conda environment and install necessary dependencies for PostGIS and Leafmap. ```bash conda create -n geo python=3.8 conda activate geo conda install geopandas conda install mamba -c conda-forge mamba install leafmap sqlalchemy psycopg2 -c conda-forge ``` -------------------------------- ### Install leafmap via PyPI Source: https://github.com/opengeos/leafmap/blob/master/docs/installation.md Standard installation command for environments using pip. ```bash pip install leafmap ``` -------------------------------- ### Install and Import Libraries Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/69_turkey_earthquake.ipynb Install the necessary packages and import the leafmap and geopandas modules. ```python # !pip install -U leafmap geopandas ``` ```python import leafmap import geopandas as gpd ``` -------------------------------- ### Install dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/32_local_tile.ipynb Uncomment these lines to install the required packages if they are not already present in your environment. ```python # !pip install leafmap ``` ```python # !pip install localtileserver ``` -------------------------------- ### Install development version from GitHub Source: https://github.com/opengeos/leafmap/blob/master/docs/installation.md Installs the latest development version directly from the GitHub repository. ```bash pip install git+https://github.com/opengeos/leafmap ``` -------------------------------- ### Install Dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/51_clip_image.ipynb Install the necessary libraries for raster processing and mapping. ```python # !pip install leafmap ``` ```python # !pip install rasterio fiona ``` -------------------------------- ### Configure Map View and Controls Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/16_heremap.ipynb Examples of setting map center, zoom, controls, and dimensions. ```python m = leafmap.Map(api_key=api_key, center=[50, 19], zoom=4) # center=[lat, lon] m ``` ```python m = leafmap.Map(api_key=api_key, fullscreen_control=False) m ``` ```python m = leafmap.Map(api_key=api_key, height="450px") m ``` -------------------------------- ### Install leafmap Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/H3.ipynb Uncomment and run this command to install the leafmap library if it is not already present in your environment. ```python # %pip install leafmap ``` -------------------------------- ### Launch Jupyter Notebook Source: https://github.com/opengeos/leafmap/blob/master/docs/get-started.md Activate the environment and start the Jupyter server. ```bash conda activate env_name jupyter notebook ``` -------------------------------- ### Install Leafmap Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/86_add_markers.ipynb Uncomment to install the leafmap package with vector support. ```python # %pip install -U "leafmap[vector]" ``` -------------------------------- ### Install dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/52_netcdf.ipynb Install the necessary packages for handling NetCDF and geospatial data. ```python # !pip install leafmap ``` ```python # !pip install xarray rioxarray netcdf4 localtileserver ``` -------------------------------- ### Start TiTiler server Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/local_titiler.ipynb Launch the local TiTiler server instance. Set show_logs to False to suppress server output. ```python leafmap.run_titiler(show_logs=False) ``` -------------------------------- ### Install Leafmap dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/wms_to_geotiff.ipynb Uncomment and run this command to install the necessary packages for WMS and raster processing. ```python # %pip install "leafmap[maplibre]" owslib rasterio ``` -------------------------------- ### Install Leafmap Dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/AGU_2025.ipynb Uncomment and run this command to install the necessary packages for the leafmap MapLibre GL backend. ```python # %pip install -U leafmap localtileserver rioxarray mapclassify pmtiles ``` -------------------------------- ### Install Leafmap dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/copernicus.ipynb Uncomment and run this command to install the necessary packages for Leafmap and Copernicus data access. ```python # %pip install -U leafmap localtileserver jupyter-server-proxy xarray ``` -------------------------------- ### Set up conda environment Source: https://github.com/opengeos/leafmap/blob/master/docs/contributing.md Commands to create and activate a conda environment and install the package in editable mode. ```bash conda create -n leafmap-test python ``` ```bash conda activate leafmap-test ``` ```bash cd leafmap/ ``` ```bash pip install -e . ``` -------------------------------- ### Install environment via Conda Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/SIGSPATIAL_2021.ipynb Commands to create a fresh Conda environment and install the required geospatial stack. ```bash conda create -n geo python=3.8 conda activate geo conda install geopandas conda install mamba -c conda-forge mamba install leafmap keplergl pydeck xarray_leaflet -c conda-forge mamba install osmnx pygeos imageio tifffile -c conda-forge jupyter lab ``` -------------------------------- ### Start a local TiTiler-XArray server Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/111_zarr.ipynb Launch a local server to serve Zarr datasets as tiles, returning the endpoint URL for use in visualization. ```python # Start the local titiler-xarray server # This will return the endpoint URL endpoint = leafmap.run_titiler_xarray() print(f"TiTiler-XArray endpoint: {endpoint}") ``` -------------------------------- ### Install geopandas Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/00_key_features.ipynb Check for and install geopandas if missing. ```python try: import geopandas except ImportError: print("Installing geopandas ...") subprocess.check_call(["python", "-m", "pip", "install", "geopandas"]) ``` -------------------------------- ### Prepare output directory Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/56_download_ned.ipynb Create a directory to store downloaded files. ```python out_dir = "data" os.makedirs(out_dir, exist_ok=True) ``` -------------------------------- ### Install optional dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/installation.md Installs specific feature sets for vector, raster, LiDAR, AI, or mapping backend support. ```bash pip install "leafmap[vector]" # Vector analysis tools pip install "leafmap[raster]" # Raster data support pip install "leafmap[lidar]" # LiDAR data analysis pip install "leafmap[backends]" # All mapping backends pip install "leafmap[maplibre]" # MapLibre GL backend pip install "leafmap[ai]" # AI/ML features ``` -------------------------------- ### Initialize WhiteboxTools Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/55_lidar.ipynb Set up the WhiteboxTools environment. ```python wbt = whitebox.WhiteboxTools() wbt.set_working_dir(os.getcwd()) wbt.set_verbose_mode(False) ``` -------------------------------- ### Initialize Map and Add Controls Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/fullscreen.ipynb Create a map instance and add navigation and fullscreen controls to the specified positions. ```python m = leafmap.Map(center=[11.255, 43.77], zoom=13, style="streets", controls={}) m.add_control("navigation", position="top-left") m.add_control("fullscreen", position="top-right") m ``` -------------------------------- ### Show tutorial video Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/64_stac_search.ipynb Display a YouTube video tutorial within the notebook. ```python leafmap.show_youtube_video("https://youtu.be/7OEraGYOWiU") ``` -------------------------------- ### Initialize map and layer Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/animate_point_along_line.ipynb Sets up the map instance and adds the initial point source and layer. ```python m = leafmap.Map(center=[0, 0], zoom=2, style="streets") radius = 20 source = {"type": "geojson", "data": point_on_circle(0, radius)} m.add_source("point", source) layer = { "id": "point", "source": "point", "type": "circle", "paint": {"circle-radius": 10, "circle-color": "#007cbf"}, } m.add_layer(layer) m ``` -------------------------------- ### Install dependencies via Conda Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/13_geopandas.ipynb Commands to set up a conda environment with necessary geospatial libraries. ```bash conda create geo -n python=3.8 conda activate geo conda install geopandas conda install mamba -c conda-forge mamba install leafmap -c conda-forge ``` -------------------------------- ### Import Leafmap Colormaps Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/SIGSPATIAL_2021.ipynb Initial setup required to access colormap functionality. ```python import leafmap import leafmap.colormaps as cm ``` -------------------------------- ### Install Polars support Source: https://github.com/opengeos/leafmap/blob/master/docs/installation.md Enables the add_polars() method for visualizing Polars DataFrames with geometry columns. ```bash pip install "leafmap[polars]" ``` -------------------------------- ### Initialize interactive map GUI Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/88_nasa_earth_data.ipynb Create a map instance and add the NASA Earth data search tool. ```python m = leafmap.Map() m.add("nasa_earth_data") m ``` -------------------------------- ### Create conda environment with dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/installation.md Recommended approach for installing leafmap and optional dependencies like geopandas and localtileserver in a fresh environment. ```bash conda install -n base mamba -c conda-forge mamba create -n geo leafmap geopandas localtileserver python -c conda-forge ``` -------------------------------- ### Initialize maps with OpenFreeMap styles Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/openfreemap.ipynb Create map instances using different OpenFreeMap style presets. ```python m = leafmap.Map(style="liberty") m ``` ```python m = leafmap.Map(style="bright") m ``` ```python m = leafmap.Map(style="positron2") m ``` -------------------------------- ### Install Leafmap Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/duckdb_layer.ipynb Uncomment to install the leafmap package with DuckDB support. ```python # %pip install "leafmap[duckdb]" ``` -------------------------------- ### Initialize map and add NASA OPERA control Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/nasa_opera.ipynb Create a map instance and add the NASA OPERA search control. ```python m = leafmap.Map( center=[-114.6581, 36.1711], zoom=10, sidebar_visible=True, sidebar_width=460 ) m.add_basemap("Satellite") m.add("NASA_OPERA") m.add_draw_control() m ``` -------------------------------- ### Install leafmap Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/3d_buildings.ipynb Uncomment to install the leafmap package with maplibre support. ```python # %pip install "leafmap[maplibre]" ``` -------------------------------- ### Initialize map and add navigation controls Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/navigation.ipynb Create a map instance and add the navigation control to the top-right corner. ```python m = leafmap.Map(center=[-74.5, 40], zoom=9, style="streets", controls={}) m.add_control("navigation", position="top-right") m ``` -------------------------------- ### Install required packages Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/ICRW_2023.ipynb Uncomment and execute this command to install leafmap and its dependencies. ```python # %pip install leafmap[raster] geopandas ``` -------------------------------- ### Initialize map and add search control Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/search_control.ipynb Create a map instance and enable the search control functionality. ```python m = leafmap.Map(center=[-100, 40], zoom=3, style="streets") m.add_search_control() m ``` -------------------------------- ### Install leafmap dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/90_pixel_inspector.ipynb Install the necessary dependencies for raster data support. ```python # %pip install "leafmap[raster]" ``` -------------------------------- ### Install leafmap and pmtiles Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/82_pmtiles.ipynb Install the necessary packages for PMTiles support in leafmap. ```python # %pip install -U leafmap pmtiles ``` -------------------------------- ### Install Dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/47_numpy_to_cog.ipynb Install leafmap and rio-cogeo via pip if not using conda. ```python # !pip install leafmap ``` ```python # !pip install rio-cogeo ``` -------------------------------- ### Install Leafmap and Dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/48_lidar.ipynb Commands to install the necessary packages for LiDAR processing. ```python # !pip install leafmap ``` ```python # !pip install leafmap[lidar] open3d ``` -------------------------------- ### Install leafmap package Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/103_raster_colormap.ipynb Uncomment to install the leafmap package with raster support. ```python # %pip install -U "leafmap[raster]" ``` -------------------------------- ### Initialize environment and map Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/03_cog_stac.ipynb Set up the TiTiler endpoint and initialize the interactive map. ```python import os import leafmap ``` ```python # Use the TiTiler demo endpoint. Replace this if needed. os.environ["TITILER_ENDPOINT"] = "https://titiler.opengeos.org" ``` ```python Map = leafmap.Map() ``` -------------------------------- ### Install leafmap via conda-forge Source: https://github.com/opengeos/leafmap/blob/master/docs/installation.md Installation command for users with Anaconda or Miniconda. ```bash conda install leafmap -c conda-forge ``` -------------------------------- ### Initialize Map and Controls Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/create_vector.ipynb Create a map instance, add a satellite basemap, Mapillary layer, layer control, and drawing tools. ```python m = leafmap.Map(center=[-74.1935, 40.6681], zoom=15, style="liberty") m.add_basemap("Satellite") m.add_mapillary() m.add_layer_control() m.add_draw_control( controls=["point", "polygon", "line_string", "trash"], position="top-right" ) ``` -------------------------------- ### Initialize and display the map Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/openstreetmap.ipynb Create a map instance using the defined style and display it. ```python m = leafmap.Map(style=style) m ``` -------------------------------- ### Initialize interactive map Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/101_nasa_opera.ipynb Create a map instance and add the NASA OPERA data exploration tool. ```python m = leafmap.Map(center=[36.1711, -114.6581], zoom=10, height="700px") m.add_basemap("Satellite") m.add("NASA_OPERA") m ``` -------------------------------- ### Install packages in Google Colab Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/55_lidar.ipynb Uncomment these lines to install dependencies in a Colab environment. ```python # !pip install leafmap ``` ```python # !pip install laspy[lazrs] ``` -------------------------------- ### Install dependencies via pip Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/13_geopandas.ipynb Commands to install leafmap and geopandas using pip. ```python # !pip install leafmap ``` ```python # !pip install geopandas ``` -------------------------------- ### Initialize Map and Add Layers Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/layer_manager.ipynb Create a map instance with 3D terrain and globe projection, then add an Earth Engine layer, a legend, and 3D buildings. ```python m = leafmap.Map( style="3d-terrain", projection="globe", height="700px", sidebar_visible=True ) m.add_ee_layer(asset_id="ESA/WorldCover/v200", opacity=0.5) m.add_legend(builtin_legend="ESA_WorldCover", title="ESA Landcover") m.add_overture_3d_buildings() m ``` -------------------------------- ### Install leafmap and Polars dependencies Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/110_polars.ipynb Install the necessary packages for leafmap and Polars integration. ```bash pip install leafmap polars geopandas ``` ```bash pip install polars-st ``` -------------------------------- ### Install and Import Leafmap Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/overture.ipynb Install the required leafmap package and import the maplibregl module. ```python # %pip install -U "leafmap[maplibre]" ``` ```python import leafmap.maplibregl as leafmap ``` -------------------------------- ### Initialize map and add layers Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/add_3d_buildings.ipynb Configures the map view, adds 3D buildings, and overlays GIF images and text labels. ```python m = leafmap.Map( center=[114.16204636, 22.3053044], zoom=15.7, pitch=45, bearing=50, style="basic-v2" ) m.add_basemap("Satellite", visible=False) m.add_3d_buildings(min_zoom=15) image = "https://i.imgur.com/KeiAsTv.gif" m.add_image(image=image, width=250, height=250, position="bottom-right") text = "Hong Kong!🦥" m.add_text(text, fontsize=34, padding="20px") image2 = "https://i.imgur.com/kZC2tpr.gif" m.add_image(image=image2, bg_color="transparent", position="bottom-left") m.add_layer_control() m ``` -------------------------------- ### Install Jupyter notebook extensions Source: https://github.com/opengeos/leafmap/blob/master/docs/installation.md Optional installation of productivity-enhancing extensions for the Jupyter environment. ```bash conda install jupyter_contrib_nbextensions -c conda-forge ``` -------------------------------- ### Initialize and display a map Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/01_leafmap_intro.ipynb Create and render a default map instance. ```python m = leafmap.Map() m ``` -------------------------------- ### Install required packages Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/65_sagemaker.ipynb Commands to install GDAL, leafmap, and dependencies. Restart the kernel after execution. ```python # %pip install --find-links=https://girder.github.io/large_image_wheels --no-cache GDAL ``` ```python # pip install leafmap localtileserver matplotlib==3.6.3 folium==0.13.0 ``` -------------------------------- ### Initialize Map and Add Layers Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/floating_sidebar.ipynb Create a map instance with a visible sidebar and add GeoJSON layers. ```python m = leafmap.Map( center=[-100, 40], zoom=2, style="liberty", sidebar_visible=True, projection="globe" ) m.add_basemap("USGS.Imagery") states_url = ( "https://github.com/opengeos/datasets/releases/download/us/us_states.geojson" ) m.add_geojson(states_url, name="US States", fit_bounds=False) cities_url = ( "https://github.com/opengeos/datasets/releases/download/world/world_cities.geojson" ) m.add_geojson(cities_url, name="World Cities", fit_bounds=False) m ``` -------------------------------- ### Install required packages Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/111_zarr.ipynb Install the necessary dependencies including leafmap, titiler-xarray, and supporting libraries. ```python # %pip install -U leafmap "titiler.xarray[full]" uvicorn xarray zarr fsspec aiohttp ``` -------------------------------- ### Install leafmap with TiTiler support Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/local_titiler.ipynb Uncomment this command to install the necessary dependencies for TiTiler integration. ```python # %pip install "leafmap[titiler]" ``` -------------------------------- ### Initialize and display the map Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/map_tiles.ipynb Create a map instance using the defined style and center coordinates. ```python m = leafmap.Map(center=[-74.5, 40], zoom=2, style=style) m ``` -------------------------------- ### Initialize Map and Add Basemap Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/63_arcgis.ipynb Create a map instance and set the base layer to terrain. ```python m = leafmap.Map() m.add_basemap("TERRAIN") m ``` -------------------------------- ### Initialize and display a MapLibre map Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/_template.ipynb Create a map instance with specified center coordinates, zoom level, and style, then display it. ```python m = leafmap.Map(center=[-100, 40], zoom=3, style="streets") m ``` -------------------------------- ### Install ipyleaflet for JupyterLab Source: https://github.com/opengeos/leafmap/blob/master/docs/faq.md Command to install the jupyter-leaflet extension for JupyterLab within a conda environment. ```bash jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-leaflet ``` -------------------------------- ### Initialize map with catalog source Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/73_custom_stac.ipynb Create an interactive map instance with the catalog_source parameter configured. ```python m = leafmap.Map(center=[40, -100], zoom=4, catalog_source=catalogs) m ``` -------------------------------- ### Initialize and Display Map Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/19_map_to_html.ipynb Create a map instance and add a hybrid basemap for visualization. ```python m = leafmap.Map() m.add_basemap("HYBRID") m ``` -------------------------------- ### Install ipyleaflet for Jupyter Notebook Source: https://github.com/opengeos/leafmap/blob/master/docs/faq.md Commands to install and enable the ipyleaflet nbextension within a conda environment. ```bash jupyter nbextension install --py --symlink --sys-prefix ipyleaflet jupyter nbextension enable --py --sys-prefix ipyleaflet ``` -------------------------------- ### Connect to Actinia server Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/87_actinia.ipynb Initialize the Actinia client and retrieve server version information. ```python # connect to the actinia server from actinia import Actinia # connect to default actinia server (https://actinia.mundialis.de) actinia_mundialis = Actinia() # retrieve metadata about actinia server and related software versions version = actinia_mundialis.get_version() print_dict(version, "Version is:") ``` -------------------------------- ### Initialize Planet API Environment Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/YouthMappers_2021.ipynb Imports necessary libraries and sets the Planet API key in the environment variables if not already present. ```python import os import leafmap ``` ```python if os.environ.get("PLANET_API_KEY") is None: os.environ["PLANET_API_KEY"] = "your-api-key" ``` -------------------------------- ### Install dependencies in Google Colab Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/SIGSPATIAL_2021.ipynb Checks if the environment is Google Colab and installs the required list of geospatial packages. ```python pkgs = [ "leafmap", "geopandas", "keplergl", "pydeck", "xarray_leaflet", "osmnx", "pygeos", "imageio", "tifffile", ] if "google.colab" in sys.modules: for pkg in pkgs: install(pkg) ``` -------------------------------- ### Initialize map and add symbols Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/center_on_symbol.ipynb Create a map instance, add a custom marker image, and define a GeoJSON source with symbol layers. ```python m = leafmap.Map(center=[-90.96, -0.47], zoom=7.5, style="streets") image = "https://maplibre.org/maplibre-gl-js/docs/assets/custom_marker.png" m.add_image("custom-marker", image) source = { "type": "geojson", "data": { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [-91.395263671875, -0.9145729757782163], }, }, { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [-90.32958984375, -0.6344474832838974], }, }, { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [-91.34033203125, 0.01647949196029245], }, }, ], }, } m.add_source("points", source) layer = { "id": "symbols", "type": "symbol", "source": "points", "layout": {"icon-image": "custom-marker"}, } m.add_layer(layer) m ``` -------------------------------- ### Initialize map and add geolocate control Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/locate_user.ipynb Create a map instance and add the geolocate control to the top-right corner. ```python m = leafmap.Map(center=[-96, 37.8], zoom=3, style="streets", controls={}) m.add_control("geolocate", position="top-right") m ``` -------------------------------- ### Initialize Redux Store for Kepler.gl Source: https://github.com/opengeos/leafmap/blob/master/docs/html/kepler.html Sets up the initial state and combines reducers for the Kepler.gl application. ```javascript var c=o.keplerGlReducer.initialState({uiState:{currentModal:null,activeSidePanel:null}}),u=Object(n.combineReducers)({keplerGl:c}),p=function(e){var t=Object(a.enhanceReduxMiddleware)([function(t){return function(r){return function(n){var o=r(n);return"function"==typeof e&&e(n,t),o}}]),r=[n.applyMiddleware.apply(void 0,i(t))];return Object(n.createStore)(u,{},n.compose.apply(void 0,r))} ``` -------------------------------- ### Initialize Dashboard Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/dashboard.ipynb Configure the tabbed interface, customize the help dialog, and embed a MapLibre map into the dashboard container. ```python tw = leafmap.TabWidget( title="Dashboard", tabs=("Home", "Map", "Settings"), icons=("mdi-home", "mdi-map", "mdi-cog"), show_panel_titles=False, ) # Customize dialog tw.set_help_title("About this dashboard") tw.set_help_content(widgets.HTML("""
Shortcuts
This is the home tab.
""")
settings_tab = widgets.HTML("""
This is the settings tab.
""") tw.set_tab_content(0, home_tab) tw.set_tab_content(1, m.container) tw.set_tab_content(2, settings_tab) display(tw.widget) ``` -------------------------------- ### Define package installation function Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/SIGSPATIAL_2021.ipynb A helper function to install Python packages using the current interpreter's pip module. ```python def install(package): subprocess.check_call([sys.executable, "-m", "pip", "install", package]) ``` -------------------------------- ### Initialize Map Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/06_legend.ipynb Create a new map instance. ```python Map = leafmap.Map() ``` -------------------------------- ### Execute animation Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/animate_point_along_line.ipynb Starts the animation process with the defined parameters. ```python animate_marker(duration, frame_rate, radius) ``` -------------------------------- ### Import required libraries Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/copernicus.ipynb Initialize the environment by importing os, rasterio, and the leafmap MapLibre module. ```python import os import rasterio import leafmap.maplibregl as leafmap ``` -------------------------------- ### Get image metadata Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/ICRW_2023.ipynb Retrieve metadata for the raster file. ```python metadata = leafmap.image_metadata("dem.tif") metadata ``` -------------------------------- ### Initialize Leafmap and Save to HTML Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/YouthMappers_2021.ipynb Import the library, initialize a map, and export it to an HTML file or string. ```python import leafmap ``` ```python m = leafmap.Map() m.add_basemap("Esri.NatGeoWorldMap") m ``` ```python m.to_html("mymap.html") ``` ```python html = m.to_html() ``` ```python # print(html) ``` -------------------------------- ### Get band statistics Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/ICRW_2023.ipynb Access band information from the metadata dictionary. ```python metadata["bands"] ``` -------------------------------- ### Get First Item Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/78_read_raster.ipynb Retrieve the first item from the search results. ```python name, item = next(iter(search.items())) name ``` -------------------------------- ### Download Sample Raster Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/51_clip_image.ipynb Define the source URL and local filename, then download the raster dataset. ```python url = "https://opengeos.org/data/raster/srtm90.tif" dem = "dem.tif" ``` ```python leafmap.download_file(url, dem, overwrite=True) ``` -------------------------------- ### Initialize map and add GeoJSON source Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/live_geojson.ipynb Create a map instance and add a point source with a symbol layer to represent the moving object. ```python m = leafmap.Map(center=[0, 20], zoom=1, style="streets") source = { "type": "geojson", "data": {"type": "Feature", "geometry": {"type": "Point", "coordinates": [0, 0]}}, } m.add_source("drone", source) layer = { "id": "drone", "type": "symbol", "source": "drone", "layout": {"icon-image": "rocket_15"}, } m.add_layer(layer) m ``` -------------------------------- ### Import Datapane and Leafmap Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/FOSS4G_2021.ipynb Setup imports for publishing maps to Datapane. ```python import datapane as dp import leafmap.foliumap as leafmap ``` -------------------------------- ### Load Example Data Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/53_choropleth.ipynb Load the built-in countries GeoJSON dataset. ```python data = leafmap.examples.datasets.countries_geojson ``` -------------------------------- ### Conditional leafmap import Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/SIGSPATIAL_2021.ipynb Attempts to import leafmap and installs it if the import fails. ```python try: import leafmap except ImportError: install("leafmap") ``` -------------------------------- ### Initialize Map with AlphaEarth GUI Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/AlphaEarth.ipynb Create a globe-projection map and add the AlphaEarth GUI component. ```python m = leafmap.Map(projection="globe", sidebar_visible=True) m.add_basemap("USGS.Imagery") m.add_alphaearth_gui() m ``` -------------------------------- ### leafmap.run_titiler_xarray() Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/111_zarr.ipynb Starts a local titiler-xarray server for processing and serving Zarr data. ```APIDOC ## leafmap.run_titiler_xarray() ### Description Starts a local titiler-xarray server to facilitate the serving of Zarr datasets. ``` -------------------------------- ### Get COG Statistics Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/EarthCube_2023.ipynb Retrieves statistical information from a remote COG file. ```python leafmap.cog_stats(url) ``` -------------------------------- ### Import colormaps module Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/FOSS4G_2021.ipynb Initializes the colormaps module, which requires the ipyleaflet backend. ```python import leafmap.colormaps as cm ``` -------------------------------- ### Get palette with classes Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/23_colormaps.ipynb Retrieve a specific palette with a defined number of classes. ```python cm.get_palette("terrain", n_class=8) ``` -------------------------------- ### Initialize 3D Ocean Map Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/ocean_bathymetry.ipynb Create a map instance with the 3d-ocean style and add layer controls. ```python m = leafmap.Map(style="3d-ocean", exaggeration=1.5, hillshade=True) m.add_layer_control(bg_layers=True) m ``` -------------------------------- ### Initialize Map and Set Attribution Position Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/attribution_position.ipynb Create a map instance and add the attribution control at the top-left position. ```python m = leafmap.Map(center=[-77.04, 38.907], zoom=11, style="streets", controls={}) m.add_control("attribution", position="top-left") m ``` -------------------------------- ### Configure map and sidebar widgets Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/sidebar.ipynb Initialize a map instance and add various interactive widgets to the sidebar container. ```python m = leafmap.Map(style="3d-terrain", projection="globe", height="700px") m.add_ee_layer(asset_id="ESA/WorldCover/v200", opacity=0.5) m.add_overture_3d_buildings() container = m.create_container() m.add_legend_to_sidebar( builtin_legend="ESA_WorldCover", title="Land Cover Type", shape_type="rectangle" ) m.add_colorbar_to_sidebar(cmap="terrain", label="Elevation") image = "https://i.imgur.com/KeiAsTv.gif" m.add_image_to_sidebar(image=image, expanded=False) video = "https://static-assets.mapbox.com/mapbox-gl-js/drone.mp4" m.add_video_to_sidebar(video, expanded=False) m.set_sidebar_width(680) m ``` -------------------------------- ### Set Date Range Source: https://github.com/opengeos/leafmap/blob/master/docs/notebooks/85_gedi.ipynb Define the start and end dates for the GEDI data search. ```python start_date = "2020-07-01" end_date = "2020-07-31" ``` -------------------------------- ### Get STAC Bands Source: https://github.com/opengeos/leafmap/blob/master/docs/workshops/EarthCube_2023.ipynb Lists the available bands for a given STAC asset URL. ```python leafmap.stac_bands(url) ``` -------------------------------- ### Initialize map and add marker Source: https://github.com/opengeos/leafmap/blob/master/docs/maplibre/add_a_marker.ipynb Create a map instance centered at specific coordinates and add a marker to the map. ```python m = leafmap.Map(center=[12.550343, 55.665957], zoom=8, style="positron") m.add_marker(lng_lat=[12.550343, 55.665957]) m ```