{ "cells": [ { "cell_type": "markdown", "id": "c8f27d2e", "metadata": {}, "source": [ "# Using `geom_imshow()` to draw DEM on map\n", "\n", "[SRTM1N00E012V3](https://earthexplorer.usgs.gov/scene/metadata/full/5e83a3ee1af480c5/SRTM1N00E012V3/) courtesy of the U.S. Geological Survey" ] }, { "cell_type": "code", "execution_count": 1, "id": "86e9b69b", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:33:37.177221Z", "iopub.status.busy": "2024-04-17T07:33:37.177087Z", "iopub.status.idle": "2024-04-17T07:33:37.518844Z", "shell.execute_reply": "2024-04-17T07:33:37.518325Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).\n" ] } ], "source": [ "import numpy as np\n", "from PIL import Image\n", "\n", "from lets_plot import *\n", "from lets_plot.geo_data import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "fe649753", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:33:37.520270Z", "iopub.status.busy": "2024-04-17T07:33:37.520115Z", "iopub.status.idle": "2024-04-17T07:33:37.522471Z", "shell.execute_reply": "2024-04-17T07:33:37.522292Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "43462276", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:33:37.523434Z", "iopub.status.busy": "2024-04-17T07:33:37.523351Z", "iopub.status.idle": "2024-04-17T07:33:37.524965Z", "shell.execute_reply": "2024-04-17T07:33:37.524780Z" } }, "outputs": [], "source": [ "def get_dem_data(url):\n", " import requests\n", " from osgeo import gdal\n", " r = requests.get(url)\n", " vsipath = '/vsimem/dem'\n", " gdal.FileFromMemBuffer(vsipath, r.content)\n", " return gdal.Open(vsipath)" ] }, { "cell_type": "code", "execution_count": 4, "id": "198ce722", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:33:37.525808Z", "iopub.status.busy": "2024-04-17T07:33:37.525735Z", "iopub.status.idle": "2024-04-17T07:33:37.526995Z", "shell.execute_reply": "2024-04-17T07:33:37.526827Z" } }, "outputs": [], "source": [ "plot_size = 600\n", "subplot_size = 500" ] }, { "cell_type": "code", "execution_count": 5, "id": "73c3ab3c", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:33:37.527773Z", "iopub.status.busy": "2024-04-17T07:33:37.527661Z", "iopub.status.idle": "2024-04-17T07:33:38.541877Z", "shell.execute_reply": "2024-04-17T07:33:38.541405Z" } }, "outputs": [], "source": [ "# Data from geocoding\n", "states = geocode_states().scope(\"Gabon\").inc_res(4).get_boundaries()\n", "cities = geocode_cities().scope(\"Gabon\").get_centroids()" ] }, { "cell_type": "code", "execution_count": 6, "id": "45972976", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:33:38.543174Z", "iopub.status.busy": "2024-04-17T07:33:38.543087Z", "iopub.status.idle": "2024-04-17T07:33:40.975569Z", "shell.execute_reply": "2024-04-17T07:33:40.975087Z" } }, "outputs": [], "source": [ "# Data from DEM\n", "dataset = get_dem_data(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/ivindo_river.tif\")\n", "dataset_array = dataset.ReadAsArray()\n", "transform = dataset.GetGeoTransform()\n", "lon_min = transform[0]\n", "lon_max = lon_min + (transform[1] * dataset_array.shape[1])\n", "lat_max = transform[3]\n", "lat_min = lat_max + (transform[5] * dataset_array.shape[0])" ] }, { "cell_type": "code", "execution_count": 7, "id": "c233fae5", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:33:40.977055Z", "iopub.status.busy": "2024-04-17T07:33:40.976965Z", "iopub.status.idle": "2024-04-17T07:33:42.113835Z", "shell.execute_reply": "2024-04-17T07:33:42.113403Z" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "