Created
August 1, 2020 12:51
-
-
Save giswqs/7a0e1694c787de73610748a50928f1f1 to your computer and use it in GitHub Desktop.
geemap geotiff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "To follow this tutorial, you need to install the [geemap] and [xarray_leaflet](https://github.com/davidbrochart/xarray_leaflet/tree/master/xarray_leaflet) Python packages. Use the following conda commmands to create a conda env and install packages:\n\n- `conda create -n gee python`\n- `conda activate gee`\n- `conda install mamba -c conda-forge`\n- `mamba install geemap xarray_leaflet -c conda-forge`" | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Import libraries" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "!conda list", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "# packages in environment at /home/qiusheng/.conda/envs/gee:\r\n#\r\n# Name Version Build Channel\r\n_libgcc_mutex 0.1 conda_forge conda-forge\r\n_openmp_mutex 4.5 0_gnu conda-forge\r\naffine 2.3.0 py_0 conda-forge\r\nargon2-cffi 20.1.0 py38h1e0a361_0 conda-forge\r\nattrs 19.3.0 py_0 conda-forge\r\nbackcall 0.2.0 pyh9f0ad1d_0 conda-forge\r\nbackports 1.0 py_2 conda-forge\r\nbackports.functools_lru_cache 1.6.1 py_0 conda-forge\r\nbeautifulsoup4 4.9.1 py38h32f6830_0 conda-forge\r\nbleach 3.1.5 pyh9f0ad1d_0 conda-forge\r\nboost-cpp 1.72.0 h8e57a91_0 conda-forge\r\nbqplot 0.12.14 pyh9f0ad1d_0 conda-forge\r\nbranca 0.3.1 py_0 conda-forge\r\nbrotlipy 0.7.0 py38h1e0a361_1000 conda-forge\r\nbzip2 1.0.8 h516909a_2 conda-forge\r\nc-ares 1.16.1 h516909a_0 conda-forge\r\nca-certificates 2020.6.20 hecda079_0 conda-forge\r\ncachetools 4.1.1 py_0 conda-forge\r\ncairo 1.16.0 hcf35c78_1003 conda-forge\r\ncertifi 2020.6.20 py38h32f6830_0 conda-forge\r\ncffi 1.14.1 py38h5bae8af_0 conda-forge\r\ncfitsio 3.470 hce51eda_6 conda-forge\r\nchardet 3.0.4 py38h32f6830_1006 conda-forge\r\nclick 7.1.2 pyh9f0ad1d_0 conda-forge\r\nclick-plugins 1.1.1 py_0 conda-forge\r\ncligj 0.5.0 py_0 conda-forge\r\ncolour 0.1.5 py_0 conda-forge\r\nconda 4.8.3 py38h32f6830_2 conda-forge\r\nconda-package-handling 1.6.0 py38h1e0a361_2 conda-forge\r\ncryptography 3.0 py38h766eaa4_0 conda-forge\r\ncurl 7.71.1 he644dc0_4 conda-forge\r\ncycler 0.10.0 py_2 conda-forge\r\ndecorator 4.4.2 py_0 conda-forge\r\ndefusedxml 0.6.0 py_0 conda-forge\r\nearthengine-api 0.1.229 pyh9f0ad1d_0 conda-forge\r\nentrypoints 0.3 py38h32f6830_1001 conda-forge\r\nexpat 2.2.9 he1b5a44_2 conda-forge\r\nffmpeg 4.3 h167e202_0 conda-forge\r\nffmpeg-python 0.2.0 py_0 conda-forge\r\nfolium 0.11.0 py_0 conda-forge\r\nfontconfig 2.13.1 h86ecdb6_1001 conda-forge\r\nfreetype 2.10.2 he06d7ca_0 conda-forge\r\nfreexl 1.0.5 h516909a_1002 conda-forge\r\nfuture 0.18.2 py38h32f6830_1 conda-forge\r\ngeeadd 0.5.0 py_0 conda-forge\r\ngeemap 0.7.9 pyh9f0ad1d_0 conda-forge\r\ngeocoder 1.38.1 py_1 conda-forge\r\ngeos 3.8.1 he1b5a44_0 conda-forge\r\ngeotiff 1.6.0 h05acad5_0 conda-forge\r\ngettext 0.19.8.1 hc5be6a0_1002 conda-forge\r\ngiflib 5.2.1 h516909a_2 conda-forge\r\nglib 2.65.0 h6f030ca_0 conda-forge\r\ngmp 6.2.0 he1b5a44_2 conda-forge\r\ngnutls 3.6.13 h79a8f9a_0 conda-forge\r\ngoogle-api-core 1.22.0 py38h32f6830_1 conda-forge\r\ngoogle-api-python-client 1.10.0 pyh9f0ad1d_0 conda-forge\r\ngoogle-auth 1.20.0 py_0 conda-forge\r\ngoogle-auth-httplib2 0.0.3 py_3 conda-forge\r\ngoogle-cloud-core 1.3.0 py_0 conda-forge\r\ngoogle-cloud-storage 1.30.0 pyh9f0ad1d_0 conda-forge\r\ngoogle-crc32c 0.1.0 py38h6d3b9ce_1 conda-forge\r\ngoogle-resumable-media 0.7.0 pyh9f0ad1d_0 conda-forge\r\ngoogleapis-common-protos 1.51.0 py38h32f6830_2 conda-forge\r\nhdf4 4.2.13 hf30be14_1003 conda-forge\r\nhdf5 1.10.6 nompi_h3c11f04_101 conda-forge\r\nhttplib2 0.18.1 pyh9f0ad1d_0 conda-forge\r\nicu 64.2 he1b5a44_1 conda-forge\r\nidna 2.10 pyh9f0ad1d_0 conda-forge\r\nimportlib-metadata 1.7.0 py38h32f6830_0 conda-forge\r\nimportlib_metadata 1.7.0 0 conda-forge\r\nipyfilechooser 0.3.4 pyh9f0ad1d_0 conda-forge\r\nipykernel 5.3.4 py38h23f93f0_0 conda-forge\r\nipyleaflet 0.13.3 pyh9f0ad1d_0 conda-forge\r\nipynb-py-convert 0.4.6 pyh9f0ad1d_0 conda-forge\r\nipython 7.17.0 py38h1cdfbd6_0 conda-forge\r\nipython_genutils 0.2.0 py_1 conda-forge\r\nipytree 0.1.8 py_0 conda-forge\r\nipywidgets 7.5.1 py_0 conda-forge\r\njedi 0.17.2 py38h32f6830_0 conda-forge\r\njinja2 2.11.2 pyh9f0ad1d_0 conda-forge\r\njpeg 9d h516909a_0 conda-forge\r\njson-c 0.13.1 hbfbb72e_1002 conda-forge\r\njsonschema 3.2.0 py38h32f6830_1 conda-forge\r\njupyter_client 6.1.6 py_0 conda-forge\r\njupyter_contrib_core 0.3.3 py_2 conda-forge\r\njupyter_contrib_nbextensions 0.5.1 py38_0 conda-forge\r\njupyter_core 4.6.3 py38h32f6830_1 conda-forge\r\njupyter_highlight_selected_word 0.2.0 py38_1000 conda-forge\r\njupyter_latex_envs 1.4.6 py38_1000 conda-forge\r\njupyter_nbextensions_configurator 0.4.1 py38h32f6830_1 conda-forge\r\njupyter_server 0.2.1 py38h32f6830_1 conda-forge\r\nkealib 1.4.13 h33137a7_1 conda-forge\r\nkiwisolver 1.2.0 py38hbf85e49_0 conda-forge\r\nkrb5 1.17.1 hfafb76e_2 conda-forge\r\nlame 3.100 h14c3975_1001 conda-forge\r\nlcms2 2.11 hbd6801e_0 conda-forge\r\nld_impl_linux-64 2.34 hc38a660_9 conda-forge\r\nlibarchive 3.3.3 h3a8160c_1008 conda-forge\r\nlibblas 3.8.0 17_openblas conda-forge\r\nlibcblas 3.8.0 17_openblas conda-forge\r\nlibcrc32c 1.1.1 he1b5a44_2 conda-forge\r\nlibcurl 7.71.1 hcdd3856_4 conda-forge\r\nlibdap4 3.20.6 h1d1bd15_1 conda-forge\r\nlibedit 3.1.20191231 h46ee950_1 conda-forge\r\nlibev 4.33 h516909a_0 conda-forge\r\nlibffi 3.2.1 he1b5a44_1007 conda-forge\r\nlibgcc-ng 9.3.0 h24d8f2e_13 conda-forge\r\nlibgdal 3.0.4 he6a97d6_10 conda-forge\r\nlibgfortran-ng 7.5.0 hdf63c60_13 conda-forge\r\nlibgomp 9.3.0 h24d8f2e_13 conda-forge\r\nlibiconv 1.15 h516909a_1006 conda-forge\r\nlibkml 1.3.0 hb574062_1011 conda-forge\r\nliblapack 3.8.0 17_openblas conda-forge\r\nlibnetcdf 4.7.4 nompi_h84807e1_105 conda-forge\r\nlibnghttp2 1.41.0 hab1572f_1 conda-forge\r\nlibopenblas 0.3.10 pthreads_hb3c22a3_4 conda-forge\r\nlibpng 1.6.37 hed695b0_1 conda-forge\r\nlibpq 12.3 h5513abc_0 conda-forge\r\nlibprotobuf 3.12.3 h8b12597_2 conda-forge\r\nlibsodium 1.0.18 h516909a_0 conda-forge\r\nlibsolv 0.7.14 h8b12597_4 conda-forge\r\nlibspatialite 4.3.0a h2482549_1038 conda-forge\r\nlibssh2 1.9.0 hab1572f_5 conda-forge\r\nlibstdcxx-ng 9.3.0 hdf63c60_13 conda-forge\r\nlibtiff 4.1.0 hc7e4089_6 conda-forge\r\nlibuuid 2.32.1 h14c3975_1000 conda-forge\r\nlibwebp-base 1.1.0 h516909a_3 conda-forge\r\nlibxcb 1.13 h14c3975_1002 conda-forge\r\nlibxml2 2.9.10 hee79883_0 conda-forge\r\nlibxslt 1.1.33 h31b3aaa_0 conda-forge\r\nlogzero 1.5.0 py38h32f6830_1002 conda-forge\r\nlxml 4.5.2 py38hbb43d70_0 conda-forge\r\nlz4-c 1.9.2 he1b5a44_1 conda-forge\r\nlzo 2.10 h14c3975_1000 conda-forge\r\nmamba 0.4.4 py38h6fd9b40_0 conda-forge\r\nmarkupsafe 1.1.1 py38h1e0a361_1 conda-forge\r\nmatplotlib 3.3.0 1 conda-forge\r\nmatplotlib-base 3.3.0 py38h91b0d89_1 conda-forge\r\nmercantile 1.1.5 pyh9f0ad1d_0 conda-forge\r\nmistune 0.8.4 py38h1e0a361_1001 conda-forge\r\nnbconvert 5.6.1 py38h32f6830_1 conda-forge\r\nnbformat 5.0.7 py_0 conda-forge\r\nncurses 6.2 he1b5a44_1 conda-forge\r\nnettle 3.4.1 h14c3975_1002 conda-forge\r\nnotebook 6.1.0 py38h32f6830_0 conda-forge\r\nnumpy 1.19.1 py38h8854b6b_0 conda-forge\r\nolefile 0.46 py_0 conda-forge\r\nopenh264 2.1.1 h8b12597_0 conda-forge\r\nopenjpeg 2.3.1 h981e76c_3 conda-forge\r\nopenssl 1.1.1g h516909a_1 conda-forge\r\npackaging 20.4 pyh9f0ad1d_0 conda-forge\r\npandas 1.1.0 py38h950e882_0 conda-forge\r\npandoc 2.10.1 h516909a_0 conda-forge\r\npandocfilters 1.4.2 py_1 conda-forge\r\nparso 0.7.1 pyh9f0ad1d_0 conda-forge\r\npcre 8.44 he1b5a44_0 conda-forge\r\npexpect 4.8.0 py38h32f6830_1 conda-forge\r\npickleshare 0.7.5 py38h32f6830_1001 conda-forge\r\npillow 7.2.0 py38h9776b28_1 conda-forge\r\npip 20.2 py_0 conda-forge\r\npixman 0.38.0 h516909a_1003 conda-forge\r\npoppler 0.87.0 h4190859_1 conda-forge\r\npoppler-data 0.4.9 0 conda-forge\r\npostgresql 12.3 h8573dbc_0 conda-forge\r\nproj 7.0.0 h966b41f_5 conda-forge\r\nprometheus_client 0.8.0 pyh9f0ad1d_0 conda-forge\r\nprompt-toolkit 3.0.5 py_1 conda-forge\r\nprotobuf 3.12.3 py38h950e882_0 conda-forge\r\npthread-stubs 0.4 h14c3975_1001 conda-forge\r\nptyprocess 0.6.0 py_1001 conda-forge\r\npyasn1 0.4.8 py_0 conda-forge\r\npyasn1-modules 0.2.7 py_0 conda-forge\r\npycosat 0.6.3 py38h1e0a361_1004 conda-forge\r\npycparser 2.20 pyh9f0ad1d_2 conda-forge\r\npygments 2.6.1 py_0 conda-forge\r\npyopenssl 19.1.0 py_1 conda-forge\r\npyparsing 2.4.7 pyh9f0ad1d_0 conda-forge\r\npyproj 2.6.1.post1 py38h7521cb9_0 conda-forge\r\npyrsistent 0.16.0 py38h1e0a361_0 conda-forge\r\npyshp 2.1.0 py_0 conda-forge\r\npysocks 1.7.1 py38h32f6830_1 conda-forge\r\npython 3.8.5 h4d41432_2_cpython conda-forge\r\npython-dateutil 2.8.1 py_0 conda-forge\r\npython-mss 6.0.0 pyh9f0ad1d_0 conda-forge\r\npython_abi 3.8 1_cp38 conda-forge\r\npytz 2020.1 pyh9f0ad1d_0 conda-forge\r\npyyaml 5.3.1 py38h1e0a361_0 conda-forge\r\npyzmq 19.0.2 py38ha71036d_0 conda-forge\r\nrasterio 1.1.5 py38h033e0f6_1 conda-forge\r\nratelim 0.1.6 py_2 conda-forge\r\nreadline 8.0 he28a2e2_2 conda-forge\r\nrequests 2.24.0 pyh9f0ad1d_0 conda-forge\r\nrioxarray 0.0.31 py_0 conda-forge\r\nrsa 4.6 pyh9f0ad1d_0 conda-forge\r\nruamel_yaml 0.15.80 py38h1e0a361_1001 conda-forge\r\nscipy 1.5.2 py38h8c5af15_0 conda-forge\r\nsend2trash 1.5.0 py_0 conda-forge\r\nsetuptools 49.2.0 py38h32f6830_0 conda-forge\r\nsimplejson 3.17.2 py38h1e0a361_0 conda-forge\r\nsix 1.15.0 pyh9f0ad1d_0 conda-forge\r\nsnuggs 1.4.7 py_0 conda-forge\r\nsoupsieve 2.0.1 py38h32f6830_0 conda-forge\r\nsqlite 3.32.3 hcee41ef_1 conda-forge\r\ntbb 2020.1 hc9558a2_0 conda-forge\r\nterminado 0.8.3 py38h32f6830_1 conda-forge\r\ntestpath 0.4.4 py_0 conda-forge\r\ntiledb 1.7.7 h8efa9f0_3 conda-forge\r\ntk 8.6.10 hed695b0_0 conda-forge\r\ntornado 6.0.4 py38h1e0a361_1 conda-forge\r\ntqdm 4.48.0 pyh9f0ad1d_0 conda-forge\r\ntraitlets 4.3.3 py38h32f6830_1 conda-forge\r\ntraittypes 0.2.1 py_1 conda-forge\r\ntzcode 2020a h516909a_0 conda-forge\r\nuritemplate 3.0.1 py_0 conda-forge\r\nurllib3 1.25.10 py_0 conda-forge\r\nwcwidth 0.2.5 pyh9f0ad1d_1 conda-forge\r\nwebencodings 0.5.1 py_1 conda-forge\r\nwheel 0.34.2 py_1 conda-forge\r\nwidgetsnbextension 3.5.1 py38h32f6830_1 conda-forge\r\nx264 1!152.20180806 h14c3975_0 conda-forge\r\nxarray 0.16.0 py_0 conda-forge\r\nxarray_leaflet 0.1.10 pyh9f0ad1d_0 conda-forge\r\nxerces-c 3.2.2 h8412b87_1004 conda-forge\r\nxorg-kbproto 1.0.7 h14c3975_1002 conda-forge\r\nxorg-libice 1.0.10 h516909a_0 conda-forge\r\nxorg-libsm 1.2.3 h84519dc_1000 conda-forge\r\nxorg-libx11 1.6.10 h516909a_0 conda-forge\r\nxorg-libxau 1.0.9 h14c3975_0 conda-forge\r\nxorg-libxdmcp 1.1.3 h516909a_0 conda-forge\r\nxorg-libxext 1.3.4 h516909a_0 conda-forge\r\nxorg-libxrender 0.9.10 h516909a_1002 conda-forge\r\nxorg-renderproto 0.11.1 h14c3975_1002 conda-forge\r\nxorg-xextproto 7.3.0 h14c3975_1002 conda-forge\r\nxorg-xproto 7.0.31 h14c3975_1007 conda-forge\r\nxz 5.2.5 h516909a_1 conda-forge\r\nyaml 0.2.5 h516909a_0 conda-forge\r\nzeromq 4.3.2 he1b5a44_3 conda-forge\r\nzipp 3.1.0 py_0 conda-forge\r\nzlib 1.2.11 h516909a_1006 conda-forge\r\nzstd 1.4.5 h6597ccf_2 conda-forge\r\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import os\nimport geemap", | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Specify input raster datasets" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')\nlandsat = os.path.join(out_dir, 'landsat.tif')\ndem = os.path.join(out_dir, 'dem.tif')", | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Download samples raster datasets\n\nMore datasets can be downloaded from https://viewer.nationalmap.gov/basic/" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "if not os.path.exists(landsat):\n landsat_url = 'https://drive.google.com/file/d/1EV38RjNxdwEozjc9m0FcO3LFgAoAX1Uw/view?usp=sharing'\n geemap.download_from_gdrive(landsat_url, 'landsat.tif', out_dir, unzip=False)", | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "if not os.path.exists(dem):\n dem_url = 'https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing'\n geemap.download_from_gdrive(dem_url, 'dem.tif', out_dir, unzip=False)", | |
"execution_count": 5, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Create an interactive map" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "Map = geemap.Map()", | |
"execution_count": 6, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Add local raster datasets to the map\n\nMore colormap can be found at https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "Map.add_raster(dem, colormap='terrain', layer_name='DEM')", | |
"execution_count": 7, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "Map.add_raster(landsat, bands=[5, 4, 3], layer_name='Landsat')", | |
"execution_count": 8, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Display the map" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "Map", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"text/plain": "Map(center=[40, -100], controls=(WidgetControl(options=['position'], widget=HBox(children=(ToggleButton(value=…", | |
"application/vnd.jupyter.widget-view+json": { | |
"version_major": 2, | |
"version_minor": 0, | |
"model_id": "13ec418f1e0b49c7ab2ef98fa0566dcc" | |
} | |
}, | |
"metadata": {} | |
} | |
] | |
} | |
], | |
"metadata": { | |
"hide_input": false, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.8.5", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"number_sections": true, | |
"sideBar": true, | |
"skip_h1_title": true, | |
"base_numbering": 1, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Table of Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": true, | |
"toc_window_display": false | |
}, | |
"varInspector": { | |
"window_display": false, | |
"cols": { | |
"lenName": 16, | |
"lenType": 16, | |
"lenVar": 40 | |
}, | |
"kernels_config": { | |
"python": { | |
"library": "var_list.py", | |
"delete_cmd_prefix": "del ", | |
"delete_cmd_postfix": "", | |
"varRefreshCmd": "print(var_dic_list())" | |
}, | |
"r": { | |
"library": "var_list.r", | |
"delete_cmd_prefix": "rm(", | |
"delete_cmd_postfix": ") ", | |
"varRefreshCmd": "cat(var_dic_list()) " | |
} | |
}, | |
"types_to_exclude": [ | |
"module", | |
"function", | |
"builtin_function_or_method", | |
"instance", | |
"_Feature" | |
] | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "geemap geotiff", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment