{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import ee\n", "import geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Upgrade geemap to the latest version" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# geemap.update_package()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Add Earth Engine dataset\n", "dem = ee.Image('USGS/SRTMGL1_003')\n", "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003')\n", "\n", "# Set visualization parameters.\n", "vis_params = {\n", " 'min': 0,\n", " 'max': 4000,\n", " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n", "\n", "# Add Earth Eninge layers to Map\n", "Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7')\n", "Map.addLayer(dem, vis_params, 'SRTM DEM', True, 1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Download sample data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "work_dir = os.path.expanduser('~/Downloads')\n", "in_shp = os.path.join(work_dir, 'us_cities.shp')\n", "if not os.path.exists(in_shp):\n", " data_url = 'https://github.com/giswqs/data/raw/main/us/us_cities.zip'\n", " geemap.download_from_url(data_url, out_dir=work_dir )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "in_fc = geemap.shp_to_ee(in_shp)\n", "Map.addLayer(in_fc, {}, 'Cities')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Export pixel values as a shapefile" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "out_shp = os.path.join(work_dir, 'dem.shp')\n", "geemap.extract_values_to_points(in_fc, dem, out_shp)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Export pixel values as a csv" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "out_csv = os.path.join(work_dir, 'landsat.csv')\n", "geemap.extract_values_to_points(in_fc, landsat7, out_csv)" ] } ], "metadata": { "hide_input": false, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }