{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualizing Geospatial Data\n", "\n", "```{contents}\n", ":local:\n", ":depth: 2\n", "```\n", "\n", "## Introduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Technical requirements\n", "\n", "```bash\n", "conda create -n gee python\n", "conda activate gee\n", "conda install -c conda-forge mamba\n", "mamba install -c conda-forge pygis\n", "```\n", "\n", "```bash\n", "jupyter lab\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# %pip install pygis" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.ee_initialize()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using the plotting tool" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40, -100], zoom=4)\n", "\n", "landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(\n", " ['B1', 'B2', 'B3', 'B4', 'B5', 'B7']\n", ")\n", "\n", "landsat_vis = {'bands': ['B4', 'B3', 'B2'], 'gamma': 1.4}\n", "Map.addLayer(landsat7, landsat_vis, \"Landsat\")\n", "\n", "hyperion = ee.ImageCollection('EO1/HYPERION').filter(\n", " ee.Filter.date('2016-01-01', '2017-03-01')\n", ")\n", "\n", "hyperion_vis = {\n", " 'min': 1000.0,\n", " 'max': 14000.0,\n", " 'gamma': 2.5,\n", "}\n", "Map.addLayer(hyperion, hyperion_vis, 'Hyperion')\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.set_plot_options(add_marker_cluster=True, overlay=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Changing layer opacity" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=(40, -100), zoom=4)\n", "\n", "dem = ee.Image('USGS/SRTMGL1_003')\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],\n", "}\n", "\n", "Map.addLayer(dem, vis_params, 'SRTM DEM', True, 1)\n", "Map.addLayer(states, {}, \"US States\", True)\n", "\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualizing raster data\n", "\n", "### Single-band images" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[12, 69], zoom=3)\n", "dem = ee.Image('USGS/SRTMGL1_003')\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],\n", "}\n", "Map.addLayer(dem, vis_params, 'SRTM DEM')\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vis_params = {\n", " 'bands': ['elevation'],\n", " 'palette': ['333399', ' 00b2b2', ' 99eb85', ' ccbe7d', ' 997c76', ' ffffff'],\n", " 'min': 0.0,\n", " 'max': 6000.0,\n", " 'opacity': 1.0,\n", " 'gamma': 1.0,\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Multi-band images" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003')\n", "vis_params = {\n", " 'min': 20,\n", " 'max': 200,\n", " 'gamma': 2,\n", " 'bands': ['B4', 'B3', 'B2'],\n", "}\n", "Map.addLayer(landsat7, vis_params, 'Landsat 7')\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualizing vector data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "Map.addLayer(states, {}, \"US States\")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vis_params = {\n", " 'color': 'ff0000ff',\n", " 'width': 2,\n", " 'lineType': 'solid',\n", " 'fillColor': '00000000',\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40, -100], zoom=4)\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "Map.addLayer(states.style(**vis_params), {}, \"US States\")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating legends\n", "\n", "### Built-in legends" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from geemap.legends import builtin_legends\n", "\n", "for legend in builtin_legends:\n", " print(legend)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.add_legend(builtin_legend='NLCD')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40, -100], zoom=4)\n", "Map.add_basemap('HYBRID')\n", "\n", "nlcd = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2019')\n", "landcover = nlcd.select('landcover')\n", "\n", "Map.addLayer(landcover, {}, 'NLCD Land Cover 2019')\n", "Map.add_legend(\n", " title=\"NLCD Land Cover Classification\", builtin_legend='NLCD', height='465px'\n", ")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Custom legends" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(add_google_map=False)\n", "\n", "labels = ['One', 'Two', 'Three', 'Four', 'etc']\n", "\n", "# colors can be defined using either hex code or RGB (0-255, 0-255, 0-255)\n", "colors = ['#8DD3C7', '#FFFFB3', '#BEBADA', '#FB8072', '#80B1D3']\n", "# legend_colors = [(255, 0, 0), (127, 255, 0), (127, 18, 25), (36, 70, 180), (96, 68 123)]\n", "\n", "Map.add_legend(\n", " labels=labels, colors=colors, position='bottomright'\n", ")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40, -100], zoom=4)\n", "\n", "legend_dict = {\n", " '11 Open Water': '466b9f',\n", " '12 Perennial Ice/Snow': 'd1def8',\n", " '21 Developed, Open Space': 'dec5c5',\n", " '22 Developed, Low Intensity': 'd99282',\n", " '23 Developed, Medium Intensity': 'eb0000',\n", " '24 Developed High Intensity': 'ab0000',\n", " '31 Barren Land (Rock/Sand/Clay)': 'b3ac9f',\n", " '41 Deciduous Forest': '68ab5f',\n", " '42 Evergreen Forest': '1c5f2c',\n", " '43 Mixed Forest': 'b5c58f',\n", " '51 Dwarf Scrub': 'af963c',\n", " '52 Shrub/Scrub': 'ccb879',\n", " '71 Grassland/Herbaceous': 'dfdfc2',\n", " '72 Sedge/Herbaceous': 'd1d182',\n", " '73 Lichens': 'a3cc51',\n", " '74 Moss': '82ba9e',\n", " '81 Pasture/Hay': 'dcd939',\n", " '82 Cultivated Crops': 'ab6c28',\n", " '90 Woody Wetlands': 'b8d9eb',\n", " '95 Emergent Herbaceous Wetlands': '6c9fb8',\n", "}\n", "\n", "nlcd = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2019')\n", "landcover = nlcd.select('landcover')\n", "\n", "Map.addLayer(landcover, {}, 'NLCD Land Cover 2019')\n", "Map.add_legend(title=\"NLCD Land Cover Classification\", legend_dict=legend_dict)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Earth Engine class table" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "dataset = ee.ImageCollection(\"ESA/WorldCover/v100\").first()\n", "Map.addLayer(dataset, {'bands': ['Map']}, \"Landcover\")\n", "\n", "ee_class_table = \"\"\"\n", "Value\tColor\tDescription\n", "10\t006400\tTrees\n", "20\tffbb22\tShrubland\n", "30\tffff4c\tGrassland\n", "40\tf096ff\tCropland\n", "50\tfa0000\tBuilt-up\n", "60\tb4b4b4\tBarren / sparse vegetation\n", "70\tf0f0f0\tSnow and ice\n", "80\t0064c8\tOpen water\n", "90\t0096a0\tHerbaceous wetland\n", "95\t00cf75\tMangroves\n", "100\tfae6a0\tMoss and lichen\n", "\"\"\"\n", "\n", "legend_dict = geemap.legend_from_ee(ee_class_table)\n", "Map.add_legend(title=\"ESA Land Cover\", legend_dict=legend_dict)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating color bars" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "dem = ee.Image('USGS/SRTMGL1_003')\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],\n", "}\n", "Map.addLayer(dem, vis_params, 'SRTM DEM')\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.add_colorbar(vis_params, label=\"Elevation (m)\", layer_name=\"SRTM DEM\")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.add_colorbar(\n", " vis_params, label=\"Elevation (m)\", layer_name=\"SRTM DEM\", orientation=\"vertical\"\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.add_colorbar(\n", " vis_params,\n", " label=\"Elevation (m)\",\n", " layer_name=\"SRTM DEM\",\n", " orientation=\"vertical\",\n", " transparent_bg=True,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Displaying labels" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40, -100], zoom=4, add_google_map=False)\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "style = {'color': 'black', 'fillColor': \"00000000\"}\n", "Map.addLayer(states.style(**style), {}, \"US States\")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.add_labels(\n", " data=states,\n", " column=\"STUSPS\",\n", " font_size=\"12pt\",\n", " font_color=\"blue\",\n", " font_family=\"arial\",\n", " font_weight=\"bold\",\n", " draggable=True,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.remove_labels()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "centroids = geemap.vector_centroids(states)\n", "df = geemap.ee_to_df(centroids)\n", "df" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.add_labels(\n", " data=df,\n", " column=\"STUSPS\",\n", " font_size=\"12pt\",\n", " font_color=\"blue\",\n", " font_family=\"arial\",\n", " font_weight=\"bold\",\n", " x='longitude',\n", " y='latitude',\n", ")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Image overlay" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=(25, -115), zoom=5)\n", "url = 'https://i.imgur.com/06Q1fSz.png'\n", "image = geemap.ImageOverlay(url=url, bounds=((13, -130), (32, -100)))\n", "Map.add_layer(image)\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image.url = 'https://i.imgur.com/U0axit9.png'\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'https://i.imgur.com/06Q1fSz.png'\n", "filename = 'hurricane.png'\n", "geemap.download_file(url, filename)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=(25, -115), zoom=5)\n", "image = geemap.ImageOverlay(url=filename, bounds=((13, -130), (32, -100)))\n", "Map.add_layer(image)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Video overlay" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=(25, -115), zoom=5)\n", "url = 'https://labs.mapbox.com/bites/00188/patricia_nasa.webm'\n", "bounds = ((13, -130), (32, -100))\n", "Map.video_overlay(url, bounds)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Split-panel maps" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.split_map(left_layer='HYBRID', right_layer='TERRAIN')\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "list(geemap.basemaps.keys())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=(40, -100), zoom=4, height=600)\n", "\n", "nlcd_2001 = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2001').select('landcover')\n", "nlcd_2019 = ee.Image('USGS/NLCD_RELEASES/2019_REL/NLCD/2019').select('landcover')\n", "\n", "left_layer = geemap.ee_tile_layer(nlcd_2001, {}, 'NLCD 2001')\n", "right_layer = geemap.ee_tile_layer(nlcd_2019, {}, 'NLCD 2019')\n", "\n", "Map.split_map(left_layer, right_layer, add_close_button=True)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Linked maps" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image = (\n", " ee.ImageCollection('COPERNICUS/S2')\n", " .filterDate('2018-09-01', '2018-09-30')\n", " .map(lambda img: img.divide(10000))\n", " .median()\n", ")\n", "\n", "vis_params = [\n", " {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 0.3, 'gamma': 1.3},\n", " {'bands': ['B8', 'B11', 'B4'], 'min': 0, 'max': 0.3, 'gamma': 1.3},\n", " {'bands': ['B8', 'B4', 'B3'], 'min': 0, 'max': 0.3, 'gamma': 1.3},\n", " {'bands': ['B12', 'B12', 'B4'], 'min': 0, 'max': 0.3, 'gamma': 1.3},\n", "]\n", "\n", "labels = [\n", " 'Natural Color (B4/B3/B2)',\n", " 'Land/Water (B8/B11/B4)',\n", " 'Color Infrared (B8/B4/B3)',\n", " 'Vegetation (B12/B11/B4)',\n", "]\n", "\n", "geemap.linked_maps(\n", " rows=2,\n", " cols=2,\n", " height=\"300px\",\n", " center=[38.4151, 21.2712],\n", " zoom=12,\n", " ee_objects=[image],\n", " vis_params=vis_params,\n", " labels=labels,\n", " label_position=\"topright\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Timeseries inspector\n", "\n", "### Visualizing image collections" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40, -100], zoom=4)\n", "collection = ee.ImageCollection('USGS/NLCD_RELEASES/2019_REL/NLCD').select('landcover')\n", "vis_params = {'bands': ['landcover']}\n", "years = collection.aggregate_array('system:index').getInfo()\n", "years" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.ts_inspector(\n", " left_ts=collection,\n", " right_ts=collection,\n", " left_names=years,\n", " right_names=years,\n", " left_vis=vis_params,\n", " right_vis=vis_params,\n", " width='80px',\n", ")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Visualizing planet.com imagery" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "os.environ[\"PLANET_API_KEY\"] = \"your-api-key\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "monthly_tiles = geemap.planet_monthly_tiles()\n", "geemap.ts_inspector(monthly_tiles)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "quarterly_tiles = geemap.planet_quarterly_tiles()\n", "geemap.ts_inspector(quarterly_tiles)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tiles = geemap.planet_tiles()\n", "geemap.ts_inspector(tiles)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Time slider\n", "\n", "### Visualizing vegetation data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "collection = (\n", " ee.ImageCollection('MODIS/MCD43A4_006_NDVI')\n", " .filter(ee.Filter.date('2018-06-01', '2018-07-01'))\n", " .select(\"NDVI\")\n", ")\n", "vis_params = {\n", " 'min': 0.0,\n", " 'max': 1.0,\n", " 'palette': 'ndvi',\n", "}\n", "\n", "Map.add_time_slider(collection, vis_params, time_interval=2)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Visualizing weather data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "collection = (\n", " ee.ImageCollection('NOAA/GFS0P25')\n", " .filterDate('2018-12-22', '2018-12-23')\n", " .limit(24)\n", " .select('temperature_2m_above_ground')\n", ")\n", "\n", "vis_params = {\n", " 'min': -40.0,\n", " 'max': 35.0,\n", " 'palette': ['blue', 'purple', 'cyan', 'green', 'yellow', 'red'],\n", "}\n", "\n", "labels = [str(n).zfill(2) + \":00\" for n in range(0, 24)]\n", "Map.add_time_slider(collection, vis_params, labels=labels, time_interval=1, opacity=0.8)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Visualizing Sentinel-2 imagery" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[37.75, -122.45], zoom=12)\n", "\n", "collection = (\n", " ee.ImageCollection('COPERNICUS/S2_SR')\n", " .filterBounds(ee.Geometry.Point([-122.45, 37.75]))\n", " .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 10)\n", ")\n", "\n", "vis_params = {\"min\": 0, \"max\": 4000, \"bands\": [\"B8\", \"B4\", \"B3\"]}\n", "\n", "Map.add_time_slider(collection, vis_params)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Shaded relief maps" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import geemap.colormaps as cm\n", "\n", "Map = geemap.Map()\n", "\n", "dem = ee.Image(\"USGS/SRTMGL1_003\")\n", "hillshade = ee.Terrain.hillshade(dem)\n", "\n", "vis = {'min': 0, 'max': 6000, 'palette': cm.palettes.terrain}\n", "blend = geemap.blend(top_layer=dem, top_vis=vis)\n", "\n", "Map.addLayer(hillshade, {}, 'Hillshade')\n", "Map.addLayer(blend, {}, 'Shaded relief')\n", "\n", "Map.add_colorbar(vis, label='Elevation (m)')\n", "Map.setCenter(91.4206, 27.3225, zoom=9)\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "left_layer = geemap.ee_tile_layer(blend, {}, \"Shaded relief\")\n", "right_layer = geemap.ee_tile_layer(hillshade, {}, \"Hillshade\")\n", "Map.split_map(left_layer, right_layer)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "nlcd = ee.Image(\"USGS/NLCD_RELEASES/2019_REL/NLCD/2019\").select('landcover')\n", "nlcd_vis = {'bands': ['landcover']}\n", "blend = geemap.blend(nlcd, dem, top_vis=nlcd_vis, expression='a*b')\n", "Map.addLayer(blend, {}, 'Blend NLCD')\n", "Map.add_legend(builtin_legend='NLCD', title='NLCD Land Cover')\n", "Map.setCenter(-118.1310, 35.6816, 10)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Elevation contours" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import geemap.colormaps as cm" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "image = ee.Image(\"USGS/SRTMGL1_003\")\n", "hillshade = ee.Terrain.hillshade(image)\n", "Map.addLayer(hillshade, {}, \"Hillshade\")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vis_params = {'min': 0, \"max\": 5000, \"palette\": cm.palettes.dem}\n", "Map.addLayer(image, vis_params, \"dem\", True, 0.5)\n", "Map.add_colorbar(vis_params, label='Elevation (m)')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "contours = geemap.create_contours(image, 0, 5000, 100, region=None)\n", "Map.addLayer(contours, {'palette': 'black'}, 'contours')\n", "Map.setCenter(-119.3678, 37.1671, 12)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualizing NetCDF data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'https://github.com/gee-community/geemap/raw/master/examples/data/wind_global.nc'\n", "filename = 'wind_global.nc'\n", "geemap.download_file(url, output=filename)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = geemap.read_netcdf(filename)\n", "data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(layers_control=True)\n", "Map.add_netcdf(\n", " filename,\n", " variables=['v_wind'],\n", " palette='coolwarm',\n", " shift_lon=True,\n", " layer_name='v_wind',\n", ")\n", "\n", "geojson = 'https://github.com/gee-community/geemap/raw/master/examples/data/countries.geojson'\n", "Map.add_geojson(geojson, layer_name='Countries')\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(layers_control=True)\n", "Map.add_basemap('CartoDB.DarkMatter')\n", "Map.add_velocity(filename, zonal_speed='u_wind', meridional_speed='v_wind')\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualizing LiDAR data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install \"geemap[lidar]\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "url = (\n", " 'https://drive.google.com/file/d/1H_X1190vL63BoFYa_cVBDxtIa8rG-Usb/view?usp=sharing'\n", ")\n", "filename = 'madison.las'\n", "\n", "if not os.path.exists(filename):\n", " geemap.download_file(url, 'madison.zip', unzip=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "las = geemap.read_lidar(filename)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "las.header" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "las.header.point_count" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "list(las.point_format.dimension_names)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "las.X" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "las.intensity" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.view_lidar(filename, cmap='terrain', backend='pyvista', background='gray')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.view_lidar(filename, backend='ipygany', background='white')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualizing raster data in 3D" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'https://github.com/giswqs/data/raw/main/raster/srtm90.tif'\n", "image = 'srtm90.tif'\n", "if not os.path.exists(image):\n", " geemap.download_file(url, image)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.plot_raster(image, cmap='terrain', figsize=(15, 10))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.plot_raster_3d('srtm90.tif', factor=2, cmap='terrain', background='gray')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating choropleth maps" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = geemap.examples.datasets.countries_geojson" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.add_data(\n", " data, column='POP_EST', scheme='Quantiles', cmap='Blues', legend_title='Population'\n", ")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.add_data(\n", " data,\n", " column='POP_EST',\n", " scheme='EqualInterval',\n", " cmap='Blues',\n", " legend_title='Population',\n", ")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.add_data(\n", " data,\n", " column='POP_EST',\n", " scheme='FisherJenks',\n", " cmap='Blues',\n", " legend_title='Population',\n", ")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.add_data(\n", " data,\n", " column='POP_EST',\n", " scheme='JenksCaspall',\n", " cmap='Blues',\n", " legend_title='Population',\n", ")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Summary" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }