### Install geemap and Gradio Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/133_gradio.ipynb Install the geemap and gradio libraries using pip. This is a prerequisite for running the examples. ```python # !pip install -U geemap gradio ``` -------------------------------- ### Install geemap and localtileserver Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/83_local_tile.ipynb Install the necessary libraries if they are not already present. Uncomment the line to run the installation. ```python # !pip install geemap localtileserver ``` -------------------------------- ### Install geemap Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/107_pydeck.ipynb Uncomment and run this line to install the geemap library if it's not already installed. ```python # !pip install -U geemap ``` -------------------------------- ### Install geemap Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/01_geemap_intro.ipynb Uncomment this line to install the geemap library if it is not already installed. ```python # !pip install geemap ``` -------------------------------- ### Install geemap and scikit-learn Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/46_local_rf_training.ipynb Install the necessary libraries for geemap and local machine learning tasks. Uncomment the line to run the installation. ```python # !pip install geemap scikit-learn ``` -------------------------------- ### Install geemap using uv Source: https://github.com/gee-community/geemap/blob/master/docs/installation.md Install geemap using the uv package manager. Ensure uv is installed first. ```bash uv pip install geemap ``` -------------------------------- ### Install geemap and Dependencies Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/105_netcdf.ipynb Install the geemap library and necessary packages for handling NetCDF and raster data. Uncomment the line to run the installation. ```python # !pip install geemap xarray rioxarray netcdf4 localtileserver ``` -------------------------------- ### Install geemap Package Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/137_create_grid.ipynb Use this command to install the geemap package from GitHub if needed. Restart the kernel after installation. ```python # %pip install git+https://github.com/gee-community/geemap.git ``` -------------------------------- ### Install geemap Library Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/84_openstreetmap.ipynb Uncomment this line to install the geemap library and its dependencies if needed. ```python # !pip install geopandas osmnx geemap ``` -------------------------------- ### Create and activate a conda environment for geemap Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/Alaska_2024_Part1.ipynb Recommended installation steps using conda. Create a new environment, activate it, install mamba, and then install geemap and pygis. ```bash conda create -n gee python=3.11 conda activate gee conda install -c conda-forge mamba mamba install -c conda-forge geemap pygis ``` -------------------------------- ### Set up conda environment and install geemap Source: https://github.com/gee-community/geemap/blob/master/docs/installation.md Create a new conda environment named 'gee' with Python 3.13, activate it, install mamba, and then install geemap and its optional dependencies. ```bash conda create -n gee python=3.13 conda activate gee conda install -n base mamba -c conda-forge mamba install geemap -c conda-forge mamba install geopandas localtileserver -c conda-forge ``` -------------------------------- ### Install geemap with AI support Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/151_dataset_explorer.ipynb Install the latest version of the geemap package with AI support. Remember to restart the kernel after installation. ```python # %pip install -U "geemap[ai]" ``` -------------------------------- ### Import geemap and ee Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/147_chart_array_list.ipynb Import necessary libraries: ee for Earth Engine and geemap for geospatial visualization and analysis. This setup is required for all subsequent examples. ```python import ee import geemap from geemap import chart ``` -------------------------------- ### List Example Names and Content Lengths Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/125_example_code.ipynb Iterate through the 'examples' section of the loaded JSON to display the name and the number of contents for each example category. ```python [(x["name"], len(x["contents"])) for x in functions["examples"]] ``` -------------------------------- ### Install geemap Locally Source: https://github.com/gee-community/geemap/blob/master/docs/contributing.md Install the geemap package in editable mode after navigating to the project directory. ```bash pip install -e . ``` -------------------------------- ### Install geemap and cartopy Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/50_cartoee_quickstart.ipynb Use these commands to install the necessary libraries via conda/mamba. Cartopy can be challenging to install, and Google Colab is suggested as an alternative if installation fails. ```bash conda create -n carto python=3.8 conda activate carto conda install mamba -c conda-forge mamba install cartopy scipy -c conda-forge mamba install geemap -c conda-forge jupyter notebook ``` ```python # !pip install cartopy scipy # !pip install geemap ``` -------------------------------- ### Install geemap and retry packages Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/96_image_chips.ipynb Use this command to install the necessary Python packages for the notebook. Uncomment the line to execute. ```python # !pip install geemap retry ``` -------------------------------- ### Install geemap and cartopy Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/112_cartoee_basemap.ipynb Use these conda/mamba commands to install geemap and cartopy. Cartopy installation can be challenging; Google Colab is an alternative if local installation fails. ```bash conda create -n gee python=3.9 conda activate gee conda install mamba -c conda-forge mamba install cartopy scipy -c conda-forge mamba install geemap -c conda-forge ``` -------------------------------- ### Install geemap from GitHub Source: https://github.com/gee-community/geemap/blob/master/docs/installation.md Install the development version of geemap directly from its GitHub repository using pip and Git. ```bash pip install git+https://github.com/gee-community/geemap ``` -------------------------------- ### Install geemap and cartopy with pip Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/57_cartoee_blend.ipynb Alternative installation commands for geemap and cartopy using pip. ```python # !pip install cartopy scipy # !pip install geemap ``` -------------------------------- ### Install geemap from PyPI Source: https://github.com/gee-community/geemap/blob/master/docs/cheatsheet.md Use this command to install the geemap package using pip. ```console pip install geemap ``` -------------------------------- ### Run Tests Source: https://github.com/gee-community/geemap/blob/master/docs/contributing.md Execute the project tests using the setup.py script or pytest. Ensure pytest is installed (`pip install pytest`). ```bash python setup.py test or pytest ``` -------------------------------- ### Install geemap and Initialize Earth Engine Source: https://github.com/gee-community/geemap/blob/master/tutorials/Image/01_image_overview.ipynb This script checks for the geemap installation and installs it if necessary. It also handles Earth Engine authentication and initialization, adapting for Google Colab environments. ```python # Installs geemap package import subprocess try: import geemap except ImportError: print("geemap package not installed. Installing ...") subprocess.check_call(["python", "-m", "pip", "install", "geemap"]) # Checks whether this notebook is running on Google Colab try: import google.colab import geemap.foliumap as emap except: import geemap as emap # Authenticates and initializes Earth Engine import ee try: ee.Initialize() except Exception as e: ee.Authenticate() ee.Initialize() ``` -------------------------------- ### Install geemap and related packages Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/IPPN_2024.ipynb Uncomment and run this code to install the required packages for the workshop. This includes geemap with workshop extras, leafmap, d2spy, and mapclassify. ```python # %pip install -U "geemap[workshop]" leafmap d2spy mapclassify ``` -------------------------------- ### Install geemap and cartopy Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/52_cartoee_gif.ipynb Use these conda/mamba commands to create an environment and install geemap and cartopy. Cartopy installation can be challenging; consider Google Colab if you encounter issues. ```bash conda create -n carto python=3.8 conda activate carto conda install mamba -c conda-forge mamba install cartopy scipy -c conda-forge mamba install geemap -c conda-forge jupyter notebook ``` -------------------------------- ### Install geemap with workshop dependencies Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/Alaska_2024_Part1.ipynb Use this command to install geemap with workshop dependencies. It is recommended to use a conda environment for installation. ```python # %pip install -U "geemap[workshop]" ``` -------------------------------- ### Install geemap Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/SRM_Workshop_2022.ipynb Installs the geemap library if it is not already present. This is a prerequisite for using geemap functionalities. ```python import subprocess try: import geemap except ImportError: print("Installing geemap ...") subprocess.check_call(["python", "-m", "pip", "install", "geemap"]) ``` -------------------------------- ### Install geemap and cartopy Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/69_cartoee_vector.ipynb Use these commands to install the necessary libraries via conda/mamba. Cartopy can be challenging to install, so Google Colab is recommended if you encounter issues. ```bash conda create -n carto python=3.8 conda activate carto conda install cartopy scipy -c conda-forge conda install geemap -c conda-forge jupyter notebook ``` -------------------------------- ### Install ipyleaflet for JupyterLab Source: https://github.com/gee-community/geemap/blob/master/docs/faq.md Run this command to install the necessary extensions for JupyterLab if the interactive map does not show up. ```bash jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-leaflet ``` -------------------------------- ### Install geemap and cartopy Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/143_precipitation_timelapse.ipynb Install necessary libraries for geemap and cartopy. Ensure you have the correct versions if specific features are required. ```python # !pip install . # !pip install cartopy scipy ``` -------------------------------- ### Download Example GIF Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/GEE_Workshop_2022_Part1.ipynb Downloads an example GIF from a URL to a local file. This is often a prerequisite for further GIF manipulation. ```python url = "https://github.com/gee-community/geemap/raw/master/examples/data/animation.gif" filename = "animation.gif" geemap.download_file(url, filename) ``` ```python geemap.show_image(filename) ``` -------------------------------- ### Install Segment Anything and pycrs Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/135_segmentation.ipynb Install the segment-geospatial and pycrs libraries, which are required for the segmentation process. ```python # %pip install segment-geospatial pycrs ``` -------------------------------- ### Install geemap with pip Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/100_numpy_to_cog.ipynb Alternatively, install geemap and rio-cogeo using pip. ```python # !pip install geemap rio-cogeo ``` -------------------------------- ### Install geemap and geedim Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/136_download_parallel.ipynb Install the geemap and geedim libraries using pip. This is a prerequisite for using the geemap functionalities. ```python # !pip install -U geemap geedim ``` -------------------------------- ### Install geemap and Dependencies Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/85_postgis.ipynb Set up your conda environment by installing necessary packages like geopandas, geemap, sqlalchemy, and psycopg2. ```bash conda create -n geo python=3.8 conda activate geo conda install geopandas conda install mamba -c conda-forge mamba install geemap sqlalchemy psycopg2 -c conda-forge ``` -------------------------------- ### Install ipyleaflet for Jupyter Notebook Source: https://github.com/gee-community/geemap/blob/master/docs/faq.md Run these commands to install the ipyleaflet extension for Jupyter Notebook if the interactive map does not show up. ```bash jupyter nbextension install --py --symlink --sys-prefix ipyleaflet jupyter nbextension enable --py --sys-prefix ipyleaflet ``` -------------------------------- ### Install geemap and dependencies Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/100_numpy_to_cog.ipynb Create a new conda environment and install geemap, rio-cogeo, and other necessary packages. ```bash conda create -n cog python=3.9 conda install mamba -c conda-forge mamba install geemap rio-cogeo -c conda-forge ``` -------------------------------- ### Demonstrate Basemap Demo Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/02_using_basemaps.ipynb Initialize a map and open the basemap switcher to demonstrate available basemaps. ```python m = geemap.Map() m.basemap_demo() m ``` -------------------------------- ### Get image system time start Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/Japan_2022.ipynb Retrieve the system start time of an Earth Engine image. ```python image.get("system:time_start").getInfo() ``` -------------------------------- ### Install geemap Package Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/AmericaView_2023.ipynb Installs the geemap Python package. Ensure you have a stable internet connection. ```python %pip install geemap ``` -------------------------------- ### Get Specific Image Property Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/NCSU_2023.ipynb Retrieve the value of a specific property from an Earth Engine image. For example, get the 'CLOUD_COVER' property. ```python image.get("CLOUD_COVER") ``` -------------------------------- ### Install geemap and pygis Packages Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/GEE_Workshop_2024.ipynb Install necessary packages for geemap and pygis. Use conda for environment management. ```bash conda create -n gee python=3.11 conda activate gee conda install -c conda-forge mamba mamba install -c conda-forge pygis ``` ```python # %pip install geemap pygis mapclassify ``` -------------------------------- ### Install geemap Package Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/GEE_Workshop_2022_Part2.ipynb Install the geemap library using pip. This is a prerequisite for using the library's functionalities. ```python # pip install geemap ``` -------------------------------- ### Get STAC Item Statistics (Commented) Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/91_planetary_computer.ipynb Calculate statistics for a STAC item. This function is commented out in the example. ```python # geemap.stac_stats(url) ``` -------------------------------- ### Get STAC Item Information (Commented) Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/91_planetary_computer.ipynb Retrieve detailed information about a STAC item. This function is commented out in the example. ```python # geemap.stac_info(url) ``` -------------------------------- ### Install geemap Package Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/City_Plus_2023.ipynb Use this command to install the geemap package with workshop support if running in Google Colab. Ensure you uncomment the line before execution. ```python # %pip install geemap[workshop] ``` -------------------------------- ### Install and Import geemap and Earth Engine Source: https://github.com/gee-community/geemap/blob/master/tutorials/FeatureCollection/us_census_data.ipynb This script checks if the geemap package is installed and installs it if necessary. It then imports the appropriate geemap module based on the environment (Google Colab or local Jupyter) and initializes the Earth Engine API. ```python import subprocess try: import geemap except ImportError: print("geemap package not installed. Installing ...") subprocess.check_call(["python", "-m", "pip", "install", "geemap"]) # Checks whether this notebook is running on Google Colab try: import google.colab import geemap.foliumap as emap except: import geemap as emap # Authenticates and initializes Earth Engine import ee try: ee.Initialize() except Exception as e: ee.Authenticate() ee.Initialize() ``` -------------------------------- ### Prepare GIF paths and output directory Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/16_add_animated_text.ipynb Sets up the file paths for the input and output GIF files, and creates the output directory if it doesn't exist. ```python in_gif = os.path.abspath("../data/animation.gif") out_dir = os.path.join(os.path.expanduser("~"), "Downloads") out_gif = os.path.join(out_dir, "output.gif") if not os.path.exists(out_dir): os.makedirs(out_dir) ``` -------------------------------- ### Get Image Timestamp Source: https://github.com/gee-community/geemap/blob/master/tutorials/Image/03_image_metadata.ipynb Retrieves and prints the start timestamp of an Earth Engine image. The result is an `ee.Date` object. ```python date = ee.Date(image.get("system:time_start")) print("Timestamp: ", date.getInfo()) # ee.Date ``` -------------------------------- ### Install geemap Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/00_ee_auth_colab.ipynb Install or upgrade the geemap library to version 0.29.3 or later to enable automatic authentication. Ensure you are using a compatible version. ```python %pip install -U geemap ``` -------------------------------- ### Install geemap development version Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/149_gemini.ipynb Use this command to install the development version of geemap along with geedim. Ensure you uncomment the line before running. ```python # %pip install -U git+https://github.com/gee-community/geemap.git geedim ``` -------------------------------- ### Prepare for Tiled Image Download Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/118_download_image.ipynb Initialize a map, load a Landsat image, and define visualization parameters. This sets up the context for downloading the image in tiles. ```python Map = geemap.Map() image = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003") landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 2} Map.addLayer(image, landsat_vis, "LE7_TOA_5YEAR/1999_2003", True, 1) Map ``` -------------------------------- ### Get STAC tile with specified bands Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/44_cog_stac.ipynb Get a tile from a STAC item, specifying the bands to use for visualization. This example uses bands ["B3", "B2", "B1"]. ```python geemap.stac_tile(url, bands=["B3", "B2", "B1"]) ``` -------------------------------- ### Install geemap and dependencies Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/76_osm_to_ee.ipynb Install geemap and its dependencies, including geopandas, cartopy, and osmnx. This step is optional and may require administrative privileges. ```python # %%capture # # optional # ! sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable # ! sudo apt-get update # ! sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev # ! sudo apt-get install libprotobuf-dev protobuf-compiler libv8-dev libjq-dev # # packages # ! pip install geopandas cartopy osmnx geemap ``` -------------------------------- ### Import geemap and initialize Earth Engine Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/150_maplibre.ipynb Import the necessary geemap modules and initialize Earth Engine. Ensure Earth Engine is properly set up before proceeding. ```python import ee import geemap.maplibregl as geemap ``` ```python geemap.ee_initialize() ``` -------------------------------- ### Visualize 3D Terrain with pydeck Source: https://github.com/gee-community/geemap/blob/master/docs/tutorials.md This example demonstrates how to use Earth Engine data with pydeck for interactive 3D terrain visualization. It requires installing pydeck and potentially other dependencies. ```python import ee import geemap import pydeck as pdk ee.Initialize() m = geemap.Map() # Load an elevation image. image = ee.Image('USGS/SRTMGL1_003') # Define visualization parameters for elevation. vis_params = { 'min': 0, 'max': 3000, 'palette': [ '006633', 'E5FFCC', '662200', '993300', 'CC6600', 'FFCC00', 'FFEECC', '444444', '666666', '999999', 'CCCCCC', 'FFFFFF' ] } # Add the elevation layer to the map. m.addLayer(image, vis_params, 'SRTM Elevation') # Center the map on a specific location. m.setCenter(-110, 40, 6) # Create a pydeck layer for 3D visualization. layer = pdk.Layer( 'TerrainLayer', data=None, elevation_scale=2, get_position='[lng, lat]', โปe='[elevation]', ) # Add the pydeck layer to the map. m.add_layer(layer) m ``` -------------------------------- ### Install geemap and pygis packages Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/Alaska_2024_Part2.ipynb Install the geemap and pygis libraries using pip. This is a prerequisite for using the geemap library. ```python # %pip install geemap pygis ``` -------------------------------- ### Convert Earth Engine JavaScripts to Python Scripts Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/08_ee_js_to_ipynb.ipynb This script converts Earth Engine JavaScript files in a specified directory to Python scripts. It first gets example JavaScript files and saves them to a working directory, then performs the conversion. ```python import os from geemap.conversion import * # Create a temporary working directory work_dir = os.path.join(os.path.expanduser("~"), "geemap") # Get Earth Engine JavaScript examples. There are five examples in the geemap package folder. # Change js_dir to your own folder containing your Earth Engine JavaScripts, # such as js_dir = '/path/to/your/js/folder' js_dir = get_js_examples(out_dir=work_dir) # Convert all Earth Engine JavaScripts in a folder recursively to Python scripts. js_to_python_dir(in_dir=js_dir, out_dir=js_dir, use_qgis=True) print("Python scripts saved at: {}".format(js_dir)) ``` -------------------------------- ### Install geemap with LiDAR support Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/101_lidar.ipynb Install the geemap library with the lidar extra and open3d for LiDAR visualization capabilities. This is a prerequisite for using LiDAR functionalities. ```python # !pip install geemap[lidar] open3d ``` -------------------------------- ### Use geemap and Earth Engine in Google Colab Source: https://github.com/gee-community/geemap/blob/master/docs/tutorials.md Demonstrates how to set up and use the geemap library with Google Earth Engine within a Google Colab environment. No specific setup instructions are provided here, but it's a foundational example for Colab users. ```python import ee import geemap ee.Initialize() m = geemap.Map() m ``` -------------------------------- ### Develop an Earth Engine App for Mapping Surface Water Dynamics Source: https://github.com/gee-community/geemap/blob/master/docs/tutorials.md This example guides the development of a Google Earth Engine application focused on mapping surface water dynamics. It likely involves time-series analysis of satellite imagery to detect changes in water extent. ```python import ee import geemap ee.Initialize() m = geemap.Map() # Load a Landsat 8 image collection. collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2') \ .filterDate('2020-01-01', '2020-12-31') \ .filterBounds(ee.Geometry.Point([-122.375, 37.625])) # Calculate NDWI for each image. def calculate_ndwi(image): return image.normalizedDifference(['SR_B3', 'SR_B5']).set('system:time_start', image.get('system:time_start')) ndwi_collection = collection.map(calculate_ndwi) # Create a mosaic of the NDWI images. ndwi_mosaic = ndwi_collection.qualityMosaic('ND') # Define visualization parameters for NDWI. vis_params = { 'min': 0.0, 'max': 1.0, 'palette': ['0000FF', '00FFFF', 'FFFFFF'] } # Add the NDWI mosaic to the map. m.addLayer(ndwi_mosaic, vis_params, 'NDWI Mosaic') m.centerObject(ee.Geometry.Point([-122.375, 37.625]), 8) m ``` -------------------------------- ### Initialize Earth Engine and geemap Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/143_precipitation_timelapse.ipynb Authenticate and initialize the Earth Engine library, then import geemap and print its version. Replace 'YOUR-PROJECT-ID' with your actual Google Cloud project ID. ```python import geemap import ee ee.Authenticate() ee.Initialize(project="YOUR-PROJECT-ID") print(geemap.__version__) ``` -------------------------------- ### Install geemap and dependencies Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/104_clip_image.ipynb Install the geemap library and its dependencies using pip. This is a prerequisite for using geemap functionalities. ```python # !pip install geemap rasterio fiona ``` -------------------------------- ### Install geemap with MapLibre support Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/150_maplibre.ipynb Install the geemap library with MapLibre support. This is required to use MapLibre-based map functionalities. ```python # %pip install "geemap[maplibre]" ``` -------------------------------- ### Import geemap and initialize Earth Engine Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/145_chart_image.ipynb Import necessary libraries and initialize the Earth Engine. ```python import calendar import ee import geemap from geemap import chart ``` ```python geemap.ee_initialize() ``` -------------------------------- ### Install geemap sql dependencies Source: https://github.com/gee-community/geemap/blob/master/docs/installation.md Install optional dependencies for geemap related to SQL database interaction, including psycopg2 and sqlalchemy. ```bash pip install geemap[sql] ``` -------------------------------- ### Check geemap Installation and Install if Needed Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/41_water_app.ipynb This script checks if the geemap package is installed and installs it using pip if it's missing. It utilizes subprocess to run the installation command. ```python # Check geemap installation import subprocess try: import geemap except ImportError: print("geemap package is not installed. Installing ...") subprocess.check_call(["python", "-m", "pip", "install", "geemap"]) ``` -------------------------------- ### Install geemap backends dependencies Source: https://github.com/gee-community/geemap/blob/master/docs/installation.md Install optional dependencies for geemap related to visualization backends like keplergl and pydeck. ```bash pip install geemap[backends] ``` -------------------------------- ### Initialize geemap and import libraries Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/112_cartoee_basemap.ipynb Initialize Earth Engine and import necessary libraries including geemap, cartoee, and cartopy image tile providers. ```python %pylab inline import ee import geemap # import the cartoee functionality from geemap from geemap import cartoee import cartopy.io.img_tiles as cimgt ``` -------------------------------- ### Install geemap and dependencies with Conda Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/Alaska_2024_Part3.ipynb Use Conda to create a new environment and install necessary packages including pygis, cartopy, and solara. ```bash conda create -n gee python=3.11 conda activate gee conda install -c conda-forge mamba mamba install -c conda-forge pygis cartopy solara ``` -------------------------------- ### Download Earth Engine Example JSON Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/125_example_code.ipynb Download the 'gee_f.json' file from the geemap GitHub repository, which contains Earth Engine code examples. ```python url = "https://github.com/gee-community/geemap/blob/master/geemap/data/gee_f.json" geemap.download_file(url) ``` -------------------------------- ### Create Training Samples for Classification Source: https://github.com/gee-community/geemap/blob/master/examples/README.md Guides on creating training samples for machine learning and supervised image classification. Essential for building classification models. ```python import ee import geemap ee.Initialize() Map = geemap.Map() # Load an image image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_0440322014092997RWT00') # Create training samples interactively using the map interface # (This typically involves using geemap's drawing tools or specific functions) Map ``` -------------------------------- ### Install geemap with workshop extras Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/GEE_Workshop_2025.ipynb Installs the geemap library with additional packages required for workshops. This is an alternative to the conda installation. ```python # %pip install "geemap[workshop]" leafmap maplibre ``` -------------------------------- ### Install geemap Package Source: https://github.com/gee-community/geemap/blob/master/examples/template/template.ipynb Installs the geemap package if it is not already present. This script checks for the import and uses subprocess to install if necessary. ```python import subprocess try: import geemap except ImportError: print("geemap package not installed. Installing ...") subprocess.check_call(["python", "-m", "pip", "install", "geemap"]) ``` -------------------------------- ### Import Libraries and Initialize Earth Engine Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/120_javascript.ipynb Import the necessary libraries, ee and geemap, and initialize Earth Engine. ```python import ee import geemap ``` ```python geemap.ee_initialize() ``` -------------------------------- ### Deploy Web App with ngrok Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/GeoPython_2021.ipynb Use this command to deploy a Voila app with ngrok. Ensure ngrok is installed and running. ```bash ngrok http 8866 ``` -------------------------------- ### Demonstrate Basemaps Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/00_geemap_key_features.ipynb Display a demo of available basemaps. This is useful for exploring different map tile options. ```python Map = geemap.Map() Map.basemap_demo() Map ``` -------------------------------- ### Get First Training Sample Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/33_accuracy_assessment.ipynb Retrieves and prints the first training sample. ```python training.first().getInfo() ``` -------------------------------- ### Install geemap in Colab Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/00_geemap_colab.ipynb Use this command to install or update the geemap package in a Google Colab environment. Uncomment the line to run the installation. ```python # %pip install -U geemap ``` -------------------------------- ### Extract Dataset Example Details Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/125_example_code.ipynb Extract the name and code for datasets from the 'examples' section of the JSON, specifically filtering for examples where the name is 'Datasets'. ```python details = [ (dataset["name"], dataset["code"]) for x in functions["examples"] for dataset in x["contents"] if x["name"] == "Datasets" ] details[0] ``` -------------------------------- ### Define Output Directory and File Path Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/32_supervised_classification.ipynb Sets up the output directory to the user's Downloads folder and defines the output filename for an exported image. Requires the 'os' module. ```python import os out_dir = os.path.join(os.path.expanduser("~"), "Downloads") out_file = os.path.join(out_dir, "landcover.tif") ``` -------------------------------- ### Download and Use Local Image Overlay Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/86_image_overlay.ipynb This snippet downloads a sample PNG image and then adds it as an overlay to the map. Ensure the filepath is correct. ```python filepath = "06Q1fSz.png" if not os.path.exists(filepath): geemap.download_from_url("https://i.imgur.com/06Q1fSz.png", filepath) ``` ```python m = geemap.Map(center=(25, -115), zoom=4) image = geemap.ImageOverlay(url=filepath, bounds=((13, -130), (32, -100))) m.add_layer(image) m ``` -------------------------------- ### Load example dataset Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/110_choropleth.ipynb Loads the countries_geojson dataset from geemap examples. ```python data = geemap.examples.datasets.countries_geojson ``` -------------------------------- ### Get Collection Size Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/90_naip_timelapse.ipynb Get the total number of images in the collection. ```python size = images.size().getInfo() ``` -------------------------------- ### Initialize DatasetExplorer Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/151_dataset_explorer.ipynb Create an instance of the DatasetExplorer. This may take a few seconds to load datasets and embeddings. ```python explorer = DatasetExplorer() ``` -------------------------------- ### Use Earth Engine Datasets Example Code Source: https://github.com/gee-community/geemap/blob/master/examples/README.md Use example code for various Earth Engine datasets. This provides practical examples for working with different data sources. ```python import ee import geemap ee.Initialize() m = geemap.Map() # Load an example dataset. image = ee.Image('MODIS/061/MODIS_Terra_NDVI/2020_01_01') # Add the dataset to the map. m.addLayer(image, {'min': 0, 'max': 1}, 'MODIS NDVI') m.centerMap(0, 0, 2) m ``` -------------------------------- ### Initialize Map and Add Layers (Landcover) Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/FOSS4GNA_2024.ipynb Initializes an interactive map, adds an imagery basemap, and layers for land cover and US states. Includes a custom land cover legend. ```python m = geemap.Map() m.add_basemap("Esri.WorldImagery") fc = ee.FeatureCollection("TIGER/2018/States") dataset = ee.ImageCollection("ESA/WorldCover/v200").first().clipToCollection(fc) visualization = {"bands": ["Map"]} m.add_layer(dataset, visualization, "Landcover") m.add_legend(title="Land Cover Type", builtin_legend="ESA_WorldCover") m.add_layer(fc, {}, "United States") m.center_object(fc, 4) m ``` -------------------------------- ### List Excess Examples Without 'FeatureView' Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/125_example_code.ipynb Display the set of excess code example names after removing the '_FeatureView' suffix, indicating examples that might require manual mapping. ```python (excess_no_featureview - known_datasets) ``` -------------------------------- ### Initialize Map and add layers with Plotting GUI Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/AGU_2023.ipynb Initializes a map and adds Landsat 7 and Hyperion image collections. It then enables the plotting GUI for interactive data visualization. ```python m = geemap.Map(center=[40, -100], zoom=4) landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003").select( ["B1", "B2", "B3", "B4", "B5", "B7" ] ) landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 1.4} m.add_layer(landsat7, landsat_vis, "Landsat") hyperion = ee.ImageCollection("EO1/HYPERION").filter( ee.Filter.date("2016-01-01", "2017-03-01") ) hyperion_vis = { "min": 1000.0, "max": 14000.0, "gamma": 2.5, } m.add_layer(hyperion, hyperion_vis, "Hyperion") m.add_plot_gui() m ``` -------------------------------- ### Install geemap with pip Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/Alaska_2024_Part3.ipynb Install the geemap package and its dependencies using pip. ```python # %pip install geemap pygis cartopy solara ``` -------------------------------- ### Initialize WhiteboxTools Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/122_lidar.ipynb Initialize WhiteboxTools and set the working directory and verbosity. ```python wbt = whitebox.WhiteboxTools() wbt.set_working_dir(os.getcwd()) wbt.set_verbose_mode(False) ``` -------------------------------- ### Create Time-Series Cloud-Free Composites Source: https://github.com/gee-community/geemap/blob/master/examples/README.md Demonstrates creating time-series cloud-free composites with a few clicks. Useful for generating consistent imagery over time by removing cloud cover. ```python import geemap Map = geemap.Map() # Create a cloud-free composite timelapse Map.add_time_series_gui(mosaic_type='cloud-free') Map ``` -------------------------------- ### Get COG tile Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/44_cog_stac.ipynb Get a tile from a COG file using its URL. ```python geemap.cog_tile(url) ``` -------------------------------- ### Initialize Map with center and zoom, add Landsat and Hyperion layers, and plotting GUI Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/City_Plus_2023.ipynb Initializes a geemap Map, adds Landsat 7 and Hyperion image collection layers with specific visualization parameters, and then enables the plotting GUI for interactive data analysis. ```python Map = geemap.Map(center=[40, -100], zoom=4) landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003").select( ["B1", "B2", "B3", "B4", "B5", "B7"] ) landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 1.4} Map.addLayer(landsat7, landsat_vis, "Landsat") hyperion = ee.ImageCollection("EO1/HYPERION").filter( ee.Filter.date("2016-01-01", "2017-03-01") ) hyperion_vis = { "min": 1000.0, "max": 14000.0, "gamma": 2.5, } Map.addLayer(hyperion, hyperion_vis, "Hyperion") Map.add_plot_gui() Map ``` -------------------------------- ### Use Earth Engine Datasets Example Code with geemap Source: https://github.com/gee-community/geemap/blob/master/docs/tutorials.md Access and use example code for various Earth Engine datasets with geemap. This provides practical examples for working with specific datasets. ```python import ee import geemap ee.Initialize() m = geemap.Map() # Example: Load and display MODIS land cover data # modis_landcover = ee.ImageCollection('MODIS/061/MCD12Q1') # classification = modis_landcover.first().select('LC_Type1') # m.addLayer(classification, {{'min': 0, 'max': 17}}, 'MODIS Land Cover') ``` -------------------------------- ### Initialize map and add layers with plotting GUI Source: https://github.com/gee-community/geemap/blob/master/docs/workshops/G4G_2023.ipynb Initializes a map and adds Landsat 7 and Hyperion layers. The plot GUI is then enabled for interactive plotting of the data. ```python m = geemap.Map(center=[40, -100], zoom=4) landsat7 = ee.Image("LANDSAT/LE7_TOA_5YEAR/1999_2003").select( ["B1", "B2", "B3", "B4", "B5", "B7"Ма] ) landsat_vis = {"bands": ["B4", "B3", "B2"], "gamma": 1.4} m.add_layer(landsat7, landsat_vis, "Landsat") hyperion = ee.ImageCollection("EO1/HYPERION").filter( ee.Filter.date("2016-01-01", "2017-03-01") ) hyperion_vis = { "min": 1000.0, "max": 14000.0, "gamma": 2.5, } m.add_layer(hyperion, hyperion_vis, "Hyperion") m.add_plot_gui() ``` -------------------------------- ### Install geemap from conda-forge Source: https://github.com/gee-community/geemap/blob/master/docs/cheatsheet.md Use this command to install the geemap package from the conda-forge channel. ```console conda install geemap -c conda-forge ``` -------------------------------- ### Get STAC center Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/44_cog_stac.ipynb Get the center coordinates of a STAC item using its URL. ```python geemap.stac_center(url) ``` -------------------------------- ### Get STAC bounds Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/44_cog_stac.ipynb Get the bounding box of a STAC item using its URL. ```python geemap.stac_bounds(url) ``` -------------------------------- ### Get COG bands Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/44_cog_stac.ipynb Get the band names of a COG file using its URL. ```python geemap.cog_bands(url) ``` -------------------------------- ### Get COG center Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/44_cog_stac.ipynb Get the center coordinates of a COG file using its URL. ```python geemap.cog_center(url) ``` -------------------------------- ### Create Training Samples for Supervised Classification Source: https://github.com/gee-community/geemap/blob/master/docs/tutorials.md Guides the creation of training samples for machine learning and supervised image classification. This is a crucial step in building classification models. ```python import ee import geemap Map = geemap.Map() # Load an image image = ee.Image('USGS/SRTMGL1_003') # Add the image to the map Map.addLayer(image, {'min': 0, 'max': 3000}, 'SRTM') # Add a drawing tool for creating training samples Map.add_drawing_control(polygonOptions=[ {'name': 'Training Samples', 'fill': True, 'stroke': True, 'strokeWeight': 2, 'color': 'FF0000', 'fillColor': 'FF0000', 'fillOpacity': 0.3} ]) Map ``` -------------------------------- ### Get COG bounds Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/44_cog_stac.ipynb Get the bounding box of a COG file using its URL. ```python geemap.cog_bounds(url) ``` -------------------------------- ### Plot Demo (Commented Out) Source: https://github.com/gee-community/geemap/blob/master/docs/notebooks/09_plotting.ipynb This is a commented-out example for plotting a demonstration. Uncomment to use. ```python # m.plot_demo() ```