├── .gitignore
├── LICENSE
├── Procfile
├── README.md
├── config_vars.py
├── data
├── animation.gif
├── countries.cpg
├── countries.dbf
├── countries.json
├── countries.prj
├── countries.shp
├── countries.shx
├── ee_logo.png
├── noaa_logo.jpg
├── rf_example.csv
├── temperature.gif
├── us-cities.cpg
├── us-cities.dbf
├── us-cities.json
├── us-cities.prj
├── us-cities.shp
├── us-cities.shx
├── us-states.cpg
├── us-states.dbf
├── us-states.json
├── us-states.prj
├── us-states.shp
├── us-states.shx
└── wind-global.nc
├── javascripts
├── ClippedComposite.js
├── FromName.js
├── ModisQaBands.js
├── NormalizedDifference.js
└── QualityMosaic.js
├── notebooks
├── 00_geemap_key_features.ipynb
├── 01_geemap_intro.ipynb
├── 02_using_basemaps.ipynb
├── 03_inspector_tool.ipynb
├── 04_split_panel_map.ipynb
├── 05_drawing_tools.ipynb
├── 06_marker_cluster.ipynb
├── 07_geojson.ipynb
├── 08_ee_js_to_ipynb.ipynb
├── 09_plotting.ipynb
├── 10_shapefiles.ipynb
├── 11_export_image.ipynb
├── 12_zonal_statistics.ipynb
├── 13_zonal_statistics_by_group.ipynb
├── 14_legends.ipynb
├── 15_convert_js_to_py.ipynb
├── 16_add_animated_text.ipynb
├── 17_add_colorbar_to_gif.ipynb
├── 18_create_landsat_timelapse.ipynb
├── 19_search_places_and_datasets.ipynb
├── 20_timeseries_inspector.ipynb
├── 21_export_map_to_html_png.ipynb
├── 22_import_scripts.ipynb
├── 23_import_assets.ipynb
├── 24_publish_maps.ipynb
├── 25_load_rasters.ipynb
├── 26_heroku.ipynb
├── 27_timelapse_app.ipynb
├── 28_voila.ipynb
├── 29_pydeck.ipynb
├── 30_image_props_stats.ipynb
├── 31_unsupervised_classification.ipynb
├── 32_supervised_classification.ipynb
├── 33_accuracy_assessment.ipynb
├── 34_extract_values.ipynb
├── 35_geemap_colab.ipynb
├── 36_quality_mosaic.ipynb
├── 37_pydeck_3d.ipynb
├── 38_cloud_geotiff.ipynb
├── 39_timelapse.ipynb
├── 40_ipywidgets.ipynb
├── 41_water_app.ipynb
├── 42_upload_data.ipynb
├── 43_extract_values_to_points.ipynb
├── 44_cog_stac.ipynb
├── 45_cog_mosaic.ipynb
├── 46_local_rf_training.ipynb
├── 47_image_thumbnails.ipynb
├── 48_folium_legend.ipynb
├── 49_colorbar.ipynb
├── 50_cartoee_quickstart.ipynb
├── 51_cartoee_projections.ipynb
├── 52_cartoee_gif.ipynb
├── 53_layer_vis.ipynb
├── 54_vector_vis.ipynb
├── 55_raster_vis.ipynb
├── 56_local_data.ipynb
├── 57_cartoee_blend.ipynb
├── 58_shp_kml.ipynb
├── 59_whitebox.ipynb
├── cartoee_colab.ipynb
├── cartoee_projections.ipynb
├── cartoee_quickstart.ipynb
├── cartoee_scalebar.ipynb
├── cartoee_subplots.ipynb
├── file_browser.ipynb
├── geemap_and_earthengine.ipynb
├── geemap_and_folium.ipynb
├── geemap_and_ipyleaflet.ipynb
├── geemap_and_ipywidgets.ipynb
├── geemap_colab.ipynb
├── geopandas.ipynb
├── image_overlay.ipynb
├── ipyleaflet_draw_control.ipynb
├── ipyleaflet_tutorials.ipynb
├── ipywidgets_demo.ipynb
├── kml_kmz.ipynb
├── local_rf_training.ipynb
├── mouse_click_coordinates.ipynb
├── netcdf.ipynb
├── notebook_template.ipynb
├── oil_palm_and_rubber_plantation.ipynb
├── qgis_layer_style_file.ipynb
├── select_features.ipynb
├── select_features_old.ipynb
├── surface_water_mapping.ipynb
├── template.ipynb
├── tn_surface_water.ipynb
├── us_census_data.ipynb
├── usda_naip_imagery.ipynb
├── velocity.ipynb
├── video_overlay.ipynb
├── water_app.ipynb
└── xy_to_points.ipynb
├── python
├── earthengine_js_to_ipynb.py
├── earthengine_py_to_ipynb.py
├── geemap_and_earthengine.py
└── javascript_to_python.py
├── requirements.txt
├── runtime.txt
└── template
├── template.ipynb
└── template.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 | Aptfile
9 |
10 | # Distribution / packaging
11 | .Python
12 | build/
13 | develop-eggs/
14 | dist/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib/
19 | lib64/
20 | parts/
21 | sdist/
22 | var/
23 | wheels/
24 | pip-wheel-metadata/
25 | share/python-wheels/
26 | *.egg-info/
27 | .installed.cfg
28 | *.egg
29 | MANIFEST
30 |
31 | # PyInstaller
32 | # Usually these files are written by a python script from a template
33 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
34 | *.manifest
35 | *.spec
36 |
37 | # Installer logs
38 | pip-log.txt
39 | pip-delete-this-directory.txt
40 |
41 | # Unit test / coverage reports
42 | htmlcov/
43 | .tox/
44 | .nox/
45 | .coverage
46 | .coverage.*
47 | .cache
48 | nosetests.xml
49 | coverage.xml
50 | *.cover
51 | *.py,cover
52 | .hypothesis/
53 | .pytest_cache/
54 |
55 | # Translations
56 | *.mo
57 | *.pot
58 |
59 | # Django stuff:
60 | *.log
61 | local_settings.py
62 | db.sqlite3
63 | db.sqlite3-journal
64 |
65 | # Flask stuff:
66 | instance/
67 | .webassets-cache
68 |
69 | # Scrapy stuff:
70 | .scrapy
71 |
72 | # Sphinx documentation
73 | docs/_build/
74 |
75 | # PyBuilder
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | .python-version
87 |
88 | # pipenv
89 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
90 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
91 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
92 | # install all needed dependencies.
93 | #Pipfile.lock
94 |
95 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
96 | __pypackages__/
97 |
98 | # Celery stuff
99 | celerybeat-schedule
100 | celerybeat.pid
101 |
102 | # SageMath parsed files
103 | *.sage.py
104 |
105 | # Environments
106 | .env
107 | .venv
108 | env/
109 | venv/
110 | ENV/
111 | env.bak/
112 | venv.bak/
113 |
114 | # Spyder project settings
115 | .spyderproject
116 | .spyproject
117 |
118 | # Rope project settings
119 | .ropeproject
120 |
121 | # mkdocs documentation
122 | /site
123 |
124 | # mypy
125 | .mypy_cache/
126 | .dmypy.json
127 | dmypy.json
128 |
129 | # Pyre type checker
130 | .pyre/
131 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Qiusheng Wu
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Procfile:
--------------------------------------------------------------------------------
1 | web: voila --port=$PORT --no-browser --strip_sources=False --enable_nbextensions=True --MappingKernelManager.cull_interval=60 --MappingKernelManager.cull_idle_timeout=120 notebooks/
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # geemap-heroku
2 |
3 | Python scripts for deploying Earth Engine Apps to heroku, try it out:
4 |
5 | ## How to deploy your own Earth Engine Apps?
6 |
7 | - [Sign up](https://signup.heroku.com/) for a free heroku account.
8 | - Follow the [instructions](https://devcenter.heroku.com/articles/getting-started-with-python#set-up) to install [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and Heroku Command Line Interface (CLI).
9 | - Authenticate heroku using the `heroku login` command.
10 | - Clone this repository:
11 | - Create your own Earth Engine notebook and put it under the `notebooks` directory.
12 | - Add Python dependencies in the `requirements.txt` file if needed.
13 | - Edit the `Procfile` file by replacing `notebooks/geemap.ipynb` with the path to your own notebook.
14 | - Commit changes to the repository by using `git add . && git commit -am "message"`.
15 | - Create a heroku app: `heroku create`
16 | - Run the `config_vars.py` script to extract Earth Engine token from your computer and set it as an environment variable on heroku: `python config_vars.py`
17 | - Deploy your code to heroku: `git push heroku master`
18 | - Open your heroku app: `heroku open`
19 |
20 | ## Optional steps
21 |
22 | - To specify a name for your app, use `heroku apps:create example`
23 | - To preview your app locally, use `heroku local web`
24 | - To hide code cells from your app, you can edit the `Procfile` file and set `--strip_sources=True`
25 | - To periodically check for idle kernels, you can edit the `Procfile` file and set `--MappingKernelManager.cull_interval=60 --MappingKernelManager.cull_idle_timeout=120`
26 | - To view information about your running app, use `heroku logs --tail`
27 | - To set an environment variable on heroku, use `heroku config:set NAME=VALUE`
28 | - To view environment variables for your app, use `heroku config`
29 |
30 | ## Credits
31 |
32 | The instructions above on how to deploy a voila application on heroku are adapted from [voila-dashboards/voila-heroku](https://github.com/voila-dashboards/voila-heroku).
33 |
--------------------------------------------------------------------------------
/config_vars.py:
--------------------------------------------------------------------------------
1 | import os
2 | import platform
3 | from subprocess import DEVNULL, STDOUT, check_call
4 |
5 | def set_heroku_vars(token_name='EARTHENGINE_TOKEN'):
6 | """Extracts Earth Engine token from the local computer and sets it as an environment variable on heroku.
7 |
8 | Args:
9 | token_name (str, optional): Name of the Earth Engine token. Defaults to 'EARTHENGINE_TOKEN'.
10 | """
11 | try:
12 |
13 | ee_token_dir = os.path.expanduser("~/.config/earthengine/")
14 | ee_token_file = os.path.join(ee_token_dir, 'credentials')
15 |
16 | if not os.path.exists(ee_token_file):
17 | print('The credentials file does not exist.')
18 | else:
19 | with open(ee_token_file) as f:
20 | content = f.read()
21 | token = content.split(':')[1].strip()[1:-2]
22 | # if platform.system() == 'Linux':
23 | # token = content.split(':')[1][1:-3]
24 | # else:
25 | # token = content.split(':')[1][2:-2]
26 | secret = '{}={}'.format(token_name, token)
27 | if platform.system() == 'Windows':
28 | check_call(['heroku', 'config:set', secret], stdout=DEVNULL, stderr=STDOUT, shell=True)
29 | else:
30 | check_call(['heroku', 'config:set', secret], stdout=DEVNULL, stderr=STDOUT)
31 |
32 | except Exception as e:
33 | print(e)
34 | return
35 |
36 | if __name__ == '__main__':
37 |
38 | set_heroku_vars(token_name='EARTHENGINE_TOKEN')
--------------------------------------------------------------------------------
/data/animation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/animation.gif
--------------------------------------------------------------------------------
/data/countries.cpg:
--------------------------------------------------------------------------------
1 | UTF-8
--------------------------------------------------------------------------------
/data/countries.dbf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/countries.dbf
--------------------------------------------------------------------------------
/data/countries.prj:
--------------------------------------------------------------------------------
1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
--------------------------------------------------------------------------------
/data/countries.shp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/countries.shp
--------------------------------------------------------------------------------
/data/countries.shx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/countries.shx
--------------------------------------------------------------------------------
/data/ee_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/ee_logo.png
--------------------------------------------------------------------------------
/data/noaa_logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/noaa_logo.jpg
--------------------------------------------------------------------------------
/data/temperature.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/temperature.gif
--------------------------------------------------------------------------------
/data/us-cities.cpg:
--------------------------------------------------------------------------------
1 | UTF-8
--------------------------------------------------------------------------------
/data/us-cities.dbf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/us-cities.dbf
--------------------------------------------------------------------------------
/data/us-cities.prj:
--------------------------------------------------------------------------------
1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
--------------------------------------------------------------------------------
/data/us-cities.shp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/us-cities.shp
--------------------------------------------------------------------------------
/data/us-cities.shx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/us-cities.shx
--------------------------------------------------------------------------------
/data/us-states.cpg:
--------------------------------------------------------------------------------
1 | UTF-8
--------------------------------------------------------------------------------
/data/us-states.dbf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/us-states.dbf
--------------------------------------------------------------------------------
/data/us-states.prj:
--------------------------------------------------------------------------------
1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
--------------------------------------------------------------------------------
/data/us-states.shp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/us-states.shp
--------------------------------------------------------------------------------
/data/us-states.shx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/us-states.shx
--------------------------------------------------------------------------------
/data/wind-global.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/giswqs/geemap-tutorials/946cef105b14b3fd565c5dbfe6c82547efafd219/data/wind-global.nc
--------------------------------------------------------------------------------
/javascripts/ClippedComposite.js:
--------------------------------------------------------------------------------
1 | // Composite an image collection and clip it to a boundary.
2 |
3 | // Load Landsat 7 raw imagery and filter it to April-July 2000.
4 | var collection = ee.ImageCollection('LANDSAT/LE07/C01/T1')
5 | .filterDate('2000-04-01', '2000-07-01');
6 |
7 | // Reduce the collection by taking the median.
8 | var median = collection.median();
9 |
10 | // Load a table of state boundaries and filter.
11 | var fc = ee.FeatureCollection('TIGER/2016/States')
12 | .filter(ee.Filter.or(
13 | ee.Filter.eq('NAME', 'Nevada'),
14 | ee.Filter.eq('NAME', 'Arizona')));
15 |
16 | // Clip to the output image to the Nevada and Arizona state boundaries.
17 | var clipped = median.clipToCollection(fc);
18 |
19 | // Display the result.
20 | Map.setCenter(-110, 40, 5);
21 | var visParams = {bands: ['B3', 'B2', 'B1'], gain: [1.4, 1.4, 1.1]};
22 | Map.addLayer(clipped, visParams, 'clipped composite');
23 |
--------------------------------------------------------------------------------
/javascripts/FromName.js:
--------------------------------------------------------------------------------
1 | // Display an image given its ID.
2 |
3 | var image = ee.Image('CGIAR/SRTM90_V4');
4 | // Center the Map.
5 | Map.setCenter(-110, 40, 5);
6 | // Display the image.
7 | Map.addLayer(image, {min: 0, max: 3000}, 'SRTM');
8 |
--------------------------------------------------------------------------------
/javascripts/ModisQaBands.js:
--------------------------------------------------------------------------------
1 | // Extract MODIS QA information from the "state_1km" QA band
2 | // and use it to mask out cloudy and deep ocean areas.
3 | //
4 | // QA Band information is available at:
5 | // https://lpdaac.usgs.gov/products/modis_products_table/mod09ga
6 | // Table 1: 1-kilometer State QA Descriptions (16-bit)
7 |
8 |
9 | /**
10 | * Returns an image containing just the specified QA bits.
11 | *
12 | * Args:
13 | * image - The QA Image to get bits from.
14 | * start - The first bit position, 0-based.
15 | * end - The last bit position, inclusive.
16 | * name - A name for the output image.
17 | */
18 | var getQABits = function(image, start, end, newName) {
19 | // Compute the bits we need to extract.
20 | var pattern = 0;
21 | for (var i = start; i <= end; i++) {
22 | pattern += Math.pow(2, i);
23 | }
24 | return image.select([0], [newName])
25 | .bitwiseAnd(pattern)
26 | .rightShift(start);
27 | };
28 |
29 | // Reference a single MODIS MOD09GA image.
30 | var image = ee.Image('MODIS/006/MOD09GA/2012_10_11');
31 |
32 | // Select the QA band
33 | var QA = image.select('state_1km');
34 |
35 | // Get the cloud_state bits and find cloudy areas.
36 | var cloud = getQABits(QA, 0, 1, 'cloud_state')
37 | .expression("b(0) == 1 || b(0) == 2");
38 |
39 | // Get the land_water_flag bits.
40 | var landWaterFlag = getQABits(QA, 3, 5, 'land_water_flag');
41 |
42 | // Create a mask that filters out deep ocean and cloudy areas.
43 | var mask = landWaterFlag.neq(7).and(cloud.not());
44 |
45 | // Add a map layer with the deep ocean and clouds areas masked out.
46 | Map.addLayer(image.updateMask(mask),
47 | {
48 | bands: ['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03'],
49 | min: -100,
50 | max: 2000
51 | }, 'MOD09GA 143'
52 | );
53 |
54 | // Add a semi-transparent map layer that displays the clouds.
55 | Map.addLayer(
56 | cloud.updateMask(cloud),
57 | {palette: 'FFFFFF', opacity: 0.8},
58 | 'clouds'
59 | );
60 |
--------------------------------------------------------------------------------
/javascripts/NormalizedDifference.js:
--------------------------------------------------------------------------------
1 | // NormalizedDifference example.
2 | //
3 | // Compute Normalized Difference Vegetation Index over MOD09GA product.
4 | // NDVI = (NIR - RED) / (NIR + RED), where
5 | // RED is sur_refl_b01, 620-670nm
6 | // NIR is sur_refl_b02, 841-876nm
7 |
8 | // Load a MODIS image.
9 | var img = ee.Image('MODIS/006/MOD09GA/2012_03_09');
10 |
11 | // Use the normalizedDifference(A, B) to compute (A - B) / (A + B)
12 | var ndvi = img.normalizedDifference(['sur_refl_b02', 'sur_refl_b01']);
13 |
14 | // Make a palette: a list of hex strings.
15 | var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
16 | '74A901', '66A000', '529400', '3E8601', '207401', '056201',
17 | '004C00', '023B01', '012E01', '011D01', '011301'];
18 |
19 | // Center the map
20 | Map.setCenter(-94.84497, 39.01918, 8);
21 |
22 | // Display the input image and the NDVI derived from it.
23 | Map.addLayer(img.select(['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03']),
24 | {gain: [0.1, 0.1, 0.1]}, 'MODIS bands 1/4/3');
25 | Map.addLayer(ndvi, {min: 0, max: 1, palette: palette}, 'NDVI');
26 |
--------------------------------------------------------------------------------
/javascripts/QualityMosaic.js:
--------------------------------------------------------------------------------
1 | // Array-based quality mosaic.
2 |
3 | // Returns a mosaic built by sorting each stack of pixels by the first band
4 | // in descending order, and taking the highest quality pixel.
5 | function qualityMosaic(bands) {
6 | // Convert to an array, and declare names for the axes and indices along the
7 | // band axis.
8 | var array = bands.toArray();
9 | var imageAxis = 0;
10 | var bandAxis = 1;
11 | var qualityIndex = 0;
12 | var valuesIndex = 1;
13 |
14 | // Slice the quality and values off the main array, and sort the values by the
15 | // quality in descending order.
16 | var quality = array.arraySlice(bandAxis, qualityIndex, qualityIndex + 1);
17 | var values = array.arraySlice(bandAxis, valuesIndex);
18 | var valuesByQuality = values.arraySort(quality.multiply(-1));
19 |
20 | // Get an image where each pixel is the array of band values where the quality
21 | // band is greatest. Note that while the array is 2-D, the first axis is
22 | // length one.
23 | var best = valuesByQuality.arraySlice(imageAxis, 0, 1);
24 |
25 | // Project the best 2D array down to a single dimension, and convert it back
26 | // to a regular scalar image by naming each position along the axis. Note we
27 | // provide the original band names, but slice off the first band since the
28 | // quality band is not part of the result. Also note to get at the band names,
29 | // we have to do some kind of reduction, but it won't really calculate pixels
30 | // if we only access the band names.
31 | var bandNames = bands.min().bandNames().slice(1);
32 | return best.arrayProject([bandAxis]).arrayFlatten([bandNames]);
33 | }
34 |
35 | // Load the l7_l1t collection for the year 2000, and make sure the first band
36 | // is our quality measure, in this case the normalized difference values.
37 | var l7 = ee.ImageCollection('LANDSAT/LE07/C01/T1')
38 | .filterDate('2000-01-01', '2001-01-01');
39 | var withNd = l7.map(function(image) {
40 | return image.normalizedDifference(['B4', 'B3']).addBands(image);
41 | });
42 |
43 | // Build a mosaic using the NDVI of bands 4 and 3, essentially showing the
44 | // greenest pixels from the year 2000.
45 | var greenest = qualityMosaic(withNd);
46 |
47 | // Select out the color bands to visualize. An interesting artifact of this
48 | // approach is that clouds are greener than water. So all the water is white.
49 | var rgb = greenest.select(['B3', 'B2', 'B1']);
50 |
51 | Map.addLayer(rgb, {gain: [1.4, 1.4, 1.1]}, 'Greenest');
52 | Map.setCenter(-90.08789, 16.38339, 11);
53 |
54 |
--------------------------------------------------------------------------------
/notebooks/01_geemap_intro.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "toc": true
7 | },
8 | "source": [
9 | "
"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {},
15 | "source": [
16 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
17 | ]
18 | },
19 | {
20 | "cell_type": "code",
21 | "execution_count": null,
22 | "metadata": {},
23 | "outputs": [],
24 | "source": [
25 | "# !pip install geemap"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": null,
31 | "metadata": {},
32 | "outputs": [],
33 | "source": [
34 | "import geemap"
35 | ]
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": null,
40 | "metadata": {},
41 | "outputs": [],
42 | "source": [
43 | "geemap.show_youtube('h0pz3S6Tvx0')"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": null,
49 | "metadata": {},
50 | "outputs": [],
51 | "source": [
52 | "Map = geemap.Map(center=(40, -100), zoom=4)\n",
53 | "Map"
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "execution_count": null,
59 | "metadata": {},
60 | "outputs": [],
61 | "source": [
62 | "Map.add_basemap('HYBRID')"
63 | ]
64 | },
65 | {
66 | "cell_type": "code",
67 | "execution_count": null,
68 | "metadata": {},
69 | "outputs": [],
70 | "source": [
71 | "basemaps = geemap.ee_basemaps\n",
72 | "for basemap in basemaps:\n",
73 | " print(basemap)"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": null,
79 | "metadata": {},
80 | "outputs": [],
81 | "source": [
82 | "Map.add_basemap('OpenTopoMap')"
83 | ]
84 | }
85 | ],
86 | "metadata": {
87 | "hide_input": false,
88 | "kernelspec": {
89 | "display_name": "Python 3",
90 | "language": "python",
91 | "name": "python3"
92 | },
93 | "language_info": {
94 | "codemirror_mode": {
95 | "name": "ipython",
96 | "version": 3
97 | },
98 | "file_extension": ".py",
99 | "mimetype": "text/x-python",
100 | "name": "python",
101 | "nbconvert_exporter": "python",
102 | "pygments_lexer": "ipython3",
103 | "version": "3.8.5"
104 | },
105 | "toc": {
106 | "base_numbering": 1,
107 | "nav_menu": {},
108 | "number_sections": true,
109 | "sideBar": true,
110 | "skip_h1_title": true,
111 | "title_cell": "Table of Contents",
112 | "title_sidebar": "Contents",
113 | "toc_cell": true,
114 | "toc_position": {},
115 | "toc_section_display": true,
116 | "toc_window_display": true
117 | },
118 | "varInspector": {
119 | "cols": {
120 | "lenName": 16,
121 | "lenType": 16,
122 | "lenVar": 40
123 | },
124 | "kernels_config": {
125 | "python": {
126 | "delete_cmd_postfix": "",
127 | "delete_cmd_prefix": "del ",
128 | "library": "var_list.py",
129 | "varRefreshCmd": "print(var_dic_list())"
130 | },
131 | "r": {
132 | "delete_cmd_postfix": ") ",
133 | "delete_cmd_prefix": "rm(",
134 | "library": "var_list.r",
135 | "varRefreshCmd": "cat(var_dic_list()) "
136 | }
137 | },
138 | "types_to_exclude": [
139 | "module",
140 | "function",
141 | "builtin_function_or_method",
142 | "instance",
143 | "_Feature"
144 | ],
145 | "window_display": false
146 | }
147 | },
148 | "nbformat": 4,
149 | "nbformat_minor": 4
150 | }
151 |
--------------------------------------------------------------------------------
/notebooks/02_using_basemaps.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "# !pip install geemap"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": null,
29 | "metadata": {},
30 | "outputs": [],
31 | "source": [
32 | "import geemap"
33 | ]
34 | },
35 | {
36 | "cell_type": "code",
37 | "execution_count": null,
38 | "metadata": {},
39 | "outputs": [],
40 | "source": [
41 | "geemap.show_youtube('6J5ZCIUPXfI')"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": null,
47 | "metadata": {},
48 | "outputs": [],
49 | "source": [
50 | "Map = geemap.Map(center=[40, -100], zoom=4)\n",
51 | "Map"
52 | ]
53 | },
54 | {
55 | "cell_type": "code",
56 | "execution_count": null,
57 | "metadata": {},
58 | "outputs": [],
59 | "source": [
60 | "Map.add_basemap('HYBRID')"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "naip_url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'\n",
70 | "Map.add_wms_layer(url=naip_url, layers='0', name='NAIP Imagery', format='image/png', shown=True)"
71 | ]
72 | },
73 | {
74 | "cell_type": "code",
75 | "execution_count": null,
76 | "metadata": {},
77 | "outputs": [],
78 | "source": [
79 | "url = 'https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'\n",
80 | "Map.add_tile_layer(url, name='Google Map', attribution='Google')"
81 | ]
82 | },
83 | {
84 | "cell_type": "code",
85 | "execution_count": null,
86 | "metadata": {},
87 | "outputs": [],
88 | "source": [
89 | "m = geemap.Map()\n",
90 | "m.basemap_demo()\n",
91 | "m"
92 | ]
93 | }
94 | ],
95 | "metadata": {
96 | "hide_input": false,
97 | "kernelspec": {
98 | "display_name": "Python 3",
99 | "language": "python",
100 | "name": "python3"
101 | },
102 | "language_info": {
103 | "codemirror_mode": {
104 | "name": "ipython",
105 | "version": 3
106 | },
107 | "file_extension": ".py",
108 | "mimetype": "text/x-python",
109 | "name": "python",
110 | "nbconvert_exporter": "python",
111 | "pygments_lexer": "ipython3",
112 | "version": "3.8.5"
113 | },
114 | "toc": {
115 | "base_numbering": 1,
116 | "nav_menu": {},
117 | "number_sections": true,
118 | "sideBar": true,
119 | "skip_h1_title": true,
120 | "title_cell": "Table of Contents",
121 | "title_sidebar": "Table of Contents",
122 | "toc_cell": false,
123 | "toc_position": {},
124 | "toc_section_display": true,
125 | "toc_window_display": true
126 | },
127 | "varInspector": {
128 | "cols": {
129 | "lenName": 16,
130 | "lenType": 16,
131 | "lenVar": 40
132 | },
133 | "kernels_config": {
134 | "python": {
135 | "delete_cmd_postfix": "",
136 | "delete_cmd_prefix": "del ",
137 | "library": "var_list.py",
138 | "varRefreshCmd": "print(var_dic_list())"
139 | },
140 | "r": {
141 | "delete_cmd_postfix": ") ",
142 | "delete_cmd_prefix": "rm(",
143 | "library": "var_list.r",
144 | "varRefreshCmd": "cat(var_dic_list()) "
145 | }
146 | },
147 | "types_to_exclude": [
148 | "module",
149 | "function",
150 | "builtin_function_or_method",
151 | "instance",
152 | "_Feature"
153 | ],
154 | "window_display": false
155 | }
156 | },
157 | "nbformat": 4,
158 | "nbformat_minor": 4
159 | }
160 |
--------------------------------------------------------------------------------
/notebooks/03_inspector_tool.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "# !pip install geemap"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": null,
29 | "metadata": {},
30 | "outputs": [],
31 | "source": [
32 | "import ee\n",
33 | "import geemap"
34 | ]
35 | },
36 | {
37 | "cell_type": "code",
38 | "execution_count": null,
39 | "metadata": {},
40 | "outputs": [],
41 | "source": [
42 | "geemap.show_youtube('k477ksjkaXw')"
43 | ]
44 | },
45 | {
46 | "cell_type": "markdown",
47 | "metadata": {},
48 | "source": [
49 | "## Create an interactive map"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": null,
55 | "metadata": {},
56 | "outputs": [],
57 | "source": [
58 | "Map = geemap.Map(center=(40, -100), zoom=4)"
59 | ]
60 | },
61 | {
62 | "cell_type": "markdown",
63 | "metadata": {},
64 | "source": [
65 | "## Add Earth Engine Python script"
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": null,
71 | "metadata": {},
72 | "outputs": [],
73 | "source": [
74 | "# Add Earth Engine dataset\n",
75 | "dem = ee.Image('USGS/SRTMGL1_003')\n",
76 | "landcover = ee.Image(\"ESA/GLOBCOVER_L4_200901_200912_V2_3\").select('landcover')\n",
77 | "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003').select(['B1', 'B2', 'B3', 'B4', 'B5', 'B7'])\n",
78 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
79 | "\n",
80 | "# Set visualization parameters.\n",
81 | "vis_params = {\n",
82 | " 'min': 0,\n",
83 | " 'max': 4000,\n",
84 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
85 | "\n",
86 | "# Add Earth Eninge layers to Map\n",
87 | "Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)\n",
88 | "Map.addLayer(landcover, {}, 'Land cover')\n",
89 | "Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7')\n",
90 | "Map.addLayer(states, {}, \"US States\")\n",
91 | "\n",
92 | "Map"
93 | ]
94 | }
95 | ],
96 | "metadata": {
97 | "hide_input": false,
98 | "kernelspec": {
99 | "display_name": "Python 3",
100 | "language": "python",
101 | "name": "python3"
102 | },
103 | "language_info": {
104 | "codemirror_mode": {
105 | "name": "ipython",
106 | "version": 3
107 | },
108 | "file_extension": ".py",
109 | "mimetype": "text/x-python",
110 | "name": "python",
111 | "nbconvert_exporter": "python",
112 | "pygments_lexer": "ipython3",
113 | "version": "3.8.5"
114 | },
115 | "toc": {
116 | "base_numbering": 1,
117 | "nav_menu": {},
118 | "number_sections": true,
119 | "sideBar": true,
120 | "skip_h1_title": true,
121 | "title_cell": "Table of Contents",
122 | "title_sidebar": "Table of Contents",
123 | "toc_cell": false,
124 | "toc_position": {},
125 | "toc_section_display": true,
126 | "toc_window_display": true
127 | },
128 | "varInspector": {
129 | "cols": {
130 | "lenName": 16,
131 | "lenType": 16,
132 | "lenVar": 40
133 | },
134 | "kernels_config": {
135 | "python": {
136 | "delete_cmd_postfix": "",
137 | "delete_cmd_prefix": "del ",
138 | "library": "var_list.py",
139 | "varRefreshCmd": "print(var_dic_list())"
140 | },
141 | "r": {
142 | "delete_cmd_postfix": ") ",
143 | "delete_cmd_prefix": "rm(",
144 | "library": "var_list.r",
145 | "varRefreshCmd": "cat(var_dic_list()) "
146 | }
147 | },
148 | "types_to_exclude": [
149 | "module",
150 | "function",
151 | "builtin_function_or_method",
152 | "instance",
153 | "_Feature"
154 | ],
155 | "window_display": false
156 | }
157 | },
158 | "nbformat": 4,
159 | "nbformat_minor": 4
160 | }
161 |
--------------------------------------------------------------------------------
/notebooks/04_split_panel_map.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "# !pip install geemap"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": null,
29 | "metadata": {},
30 | "outputs": [],
31 | "source": [
32 | "import geemap"
33 | ]
34 | },
35 | {
36 | "cell_type": "code",
37 | "execution_count": null,
38 | "metadata": {},
39 | "outputs": [],
40 | "source": [
41 | "geemap.show_youtube('9EUTX8j-YVM')"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": null,
47 | "metadata": {},
48 | "outputs": [],
49 | "source": [
50 | "Map = geemap.Map()\n",
51 | "Map.split_map()\n",
52 | "Map"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": null,
58 | "metadata": {},
59 | "outputs": [],
60 | "source": [
61 | "Map = geemap.Map()\n",
62 | "Map.split_map(left_layer='HYBRID', right_layer='ROADMAP')\n",
63 | "Map"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "basemaps = geemap.ee_basemaps.keys()\n",
73 | "print(basemaps)"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": null,
79 | "metadata": {},
80 | "outputs": [],
81 | "source": [
82 | "for basemap in basemaps:\n",
83 | " print(basemap)"
84 | ]
85 | },
86 | {
87 | "cell_type": "code",
88 | "execution_count": null,
89 | "metadata": {},
90 | "outputs": [],
91 | "source": [
92 | "Map = geemap.Map()\n",
93 | "Map.split_map(left_layer='NLCD 2016 CONUS Land Cover', right_layer='NLCD 2001 CONUS Land Cover')\n",
94 | "Map"
95 | ]
96 | },
97 | {
98 | "cell_type": "code",
99 | "execution_count": null,
100 | "metadata": {},
101 | "outputs": [],
102 | "source": [
103 | "import ee"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "metadata": {},
110 | "outputs": [],
111 | "source": [
112 | "# https://developers.google.com/earth-engine/datasets/catalog/USGS_NLCD\n",
113 | "collection = ee.ImageCollection(\"USGS/NLCD\")\n",
114 | "print(collection.aggregate_array('system:id').getInfo())"
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": null,
120 | "metadata": {},
121 | "outputs": [],
122 | "source": [
123 | "nlcd_2001 = ee.Image('USGS/NLCD/NLCD2001').select('landcover')\n",
124 | "nlcd_2016 = ee.Image('USGS/NLCD/NLCD2016').select('landcover')\n",
125 | "\n",
126 | "left_layer = geemap.ee_tile_layer(nlcd_2001, {}, 'NLCD 2001')\n",
127 | "right_layer = geemap.ee_tile_layer(nlcd_2016, {}, 'NLCD 2016')\n",
128 | "\n",
129 | "Map = geemap.Map()\n",
130 | "Map.split_map(left_layer, right_layer)\n",
131 | "Map"
132 | ]
133 | },
134 | {
135 | "cell_type": "code",
136 | "execution_count": null,
137 | "metadata": {},
138 | "outputs": [],
139 | "source": []
140 | }
141 | ],
142 | "metadata": {
143 | "hide_input": false,
144 | "kernelspec": {
145 | "display_name": "Python 3",
146 | "language": "python",
147 | "name": "python3"
148 | },
149 | "language_info": {
150 | "codemirror_mode": {
151 | "name": "ipython",
152 | "version": 3
153 | },
154 | "file_extension": ".py",
155 | "mimetype": "text/x-python",
156 | "name": "python",
157 | "nbconvert_exporter": "python",
158 | "pygments_lexer": "ipython3",
159 | "version": "3.8.5"
160 | },
161 | "toc": {
162 | "base_numbering": 1,
163 | "nav_menu": {},
164 | "number_sections": true,
165 | "sideBar": true,
166 | "skip_h1_title": true,
167 | "title_cell": "Table of Contents",
168 | "title_sidebar": "Table of Contents",
169 | "toc_cell": false,
170 | "toc_position": {},
171 | "toc_section_display": true,
172 | "toc_window_display": true
173 | },
174 | "varInspector": {
175 | "cols": {
176 | "lenName": 16,
177 | "lenType": 16,
178 | "lenVar": 40
179 | },
180 | "kernels_config": {
181 | "python": {
182 | "delete_cmd_postfix": "",
183 | "delete_cmd_prefix": "del ",
184 | "library": "var_list.py",
185 | "varRefreshCmd": "print(var_dic_list())"
186 | },
187 | "r": {
188 | "delete_cmd_postfix": ") ",
189 | "delete_cmd_prefix": "rm(",
190 | "library": "var_list.r",
191 | "varRefreshCmd": "cat(var_dic_list()) "
192 | }
193 | },
194 | "types_to_exclude": [
195 | "module",
196 | "function",
197 | "builtin_function_or_method",
198 | "instance",
199 | "_Feature"
200 | ],
201 | "window_display": false
202 | }
203 | },
204 | "nbformat": 4,
205 | "nbformat_minor": 4
206 | }
207 |
--------------------------------------------------------------------------------
/notebooks/05_drawing_tools.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import ee\n",
28 | "import geemap"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": null,
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "geemap.show_youtube('N7rK2aV1R4c')"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": null,
43 | "metadata": {},
44 | "outputs": [],
45 | "source": [
46 | "Map = geemap.Map()\n",
47 | "Map"
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": null,
53 | "metadata": {},
54 | "outputs": [],
55 | "source": [
56 | "# Add Earth Engine dataset\n",
57 | "image = ee.Image('USGS/SRTMGL1_003')\n",
58 | "\n",
59 | "# Set visualization parameters.\n",
60 | "vis_params = {\n",
61 | " 'min': 0,\n",
62 | " 'max': 4000,\n",
63 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
64 | "\n",
65 | "# Add Earth Engine DEM to map\n",
66 | "Map.addLayer(image, vis_params, 'SRTM DEM')\n",
67 | "\n",
68 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
69 | "Map.addLayer(states, {}, 'US States')"
70 | ]
71 | },
72 | {
73 | "cell_type": "code",
74 | "execution_count": null,
75 | "metadata": {},
76 | "outputs": [],
77 | "source": [
78 | "Map.draw_features"
79 | ]
80 | },
81 | {
82 | "cell_type": "code",
83 | "execution_count": null,
84 | "metadata": {},
85 | "outputs": [],
86 | "source": [
87 | "Map.draw_last_feature"
88 | ]
89 | },
90 | {
91 | "cell_type": "code",
92 | "execution_count": null,
93 | "metadata": {},
94 | "outputs": [],
95 | "source": [
96 | "roi = ee.FeatureCollection(Map.draw_features)\n",
97 | "selected_states = states.filterBounds(roi)\n",
98 | "Map.addLayer(selected_states, {}, \"Selected states\")"
99 | ]
100 | },
101 | {
102 | "cell_type": "code",
103 | "execution_count": null,
104 | "metadata": {},
105 | "outputs": [],
106 | "source": [
107 | "clipped_image = image.clip(selected_states)\n",
108 | "Map.addLayer(clipped_image, vis_params, 'Clipped image')"
109 | ]
110 | }
111 | ],
112 | "metadata": {
113 | "hide_input": false,
114 | "kernelspec": {
115 | "display_name": "Python 3",
116 | "language": "python",
117 | "name": "python3"
118 | },
119 | "language_info": {
120 | "codemirror_mode": {
121 | "name": "ipython",
122 | "version": 3
123 | },
124 | "file_extension": ".py",
125 | "mimetype": "text/x-python",
126 | "name": "python",
127 | "nbconvert_exporter": "python",
128 | "pygments_lexer": "ipython3",
129 | "version": "3.8.5"
130 | },
131 | "toc": {
132 | "base_numbering": 1,
133 | "nav_menu": {},
134 | "number_sections": true,
135 | "sideBar": true,
136 | "skip_h1_title": true,
137 | "title_cell": "Table of Contents",
138 | "title_sidebar": "Table of Contents",
139 | "toc_cell": false,
140 | "toc_position": {},
141 | "toc_section_display": true,
142 | "toc_window_display": true
143 | },
144 | "varInspector": {
145 | "cols": {
146 | "lenName": 16,
147 | "lenType": 16,
148 | "lenVar": 40
149 | },
150 | "kernels_config": {
151 | "python": {
152 | "delete_cmd_postfix": "",
153 | "delete_cmd_prefix": "del ",
154 | "library": "var_list.py",
155 | "varRefreshCmd": "print(var_dic_list())"
156 | },
157 | "r": {
158 | "delete_cmd_postfix": ") ",
159 | "delete_cmd_prefix": "rm(",
160 | "library": "var_list.r",
161 | "varRefreshCmd": "cat(var_dic_list()) "
162 | }
163 | },
164 | "types_to_exclude": [
165 | "module",
166 | "function",
167 | "builtin_function_or_method",
168 | "instance",
169 | "_Feature"
170 | ],
171 | "window_display": false
172 | }
173 | },
174 | "nbformat": 4,
175 | "nbformat_minor": 4
176 | }
177 |
--------------------------------------------------------------------------------
/notebooks/06_marker_cluster.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": 15,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 16,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import geemap\n",
28 | "import json\n",
29 | "import os\n",
30 | "import requests\n",
31 | "from geemap import geojson_to_ee, ee_to_geojson\n",
32 | "from ipyleaflet import GeoJSON, Marker, MarkerCluster"
33 | ]
34 | },
35 | {
36 | "cell_type": "code",
37 | "execution_count": 17,
38 | "metadata": {},
39 | "outputs": [
40 | {
41 | "data": {
42 | "application/vnd.jupyter.widget-view+json": {
43 | "model_id": "",
44 | "version_major": 2,
45 | "version_minor": 0
46 | },
47 | "text/plain": [
48 | "Output(layout=Layout(width='815px'))"
49 | ]
50 | },
51 | "metadata": {},
52 | "output_type": "display_data"
53 | }
54 | ],
55 | "source": [
56 | "geemap.show_youtube('4HycJPrwpuo')"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": 18,
62 | "metadata": {},
63 | "outputs": [
64 | {
65 | "data": {
66 | "application/vnd.jupyter.widget-view+json": {
67 | "model_id": "193ef1981dbf43e384eb3f4ddfb102db",
68 | "version_major": 2,
69 | "version_minor": 0
70 | },
71 | "text/plain": [
72 | "Map(center=[40, -100], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=HBox(children=(T…"
73 | ]
74 | },
75 | "metadata": {},
76 | "output_type": "display_data"
77 | }
78 | ],
79 | "source": [
80 | "Map = geemap.Map()\n",
81 | "Map"
82 | ]
83 | },
84 | {
85 | "cell_type": "code",
86 | "execution_count": 19,
87 | "metadata": {},
88 | "outputs": [],
89 | "source": [
90 | "file_path = os.path.abspath('../data/us-cities.json')\n",
91 | "\n",
92 | "if not os.path.exists(file_path):\n",
93 | " url = 'https://github.com/giswqs/geemap/raw/master/examples/data/us-cities.json'\n",
94 | " r = requests.get(url)\n",
95 | " with open(file_path, 'w') as f:\n",
96 | " f.write(r.content.decode(\"utf-8\")) \n",
97 | "\n",
98 | "with open(file_path) as f:\n",
99 | " json_data = json.load(f)"
100 | ]
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": 20,
105 | "metadata": {},
106 | "outputs": [],
107 | "source": [
108 | "maker_cluster = MarkerCluster(\n",
109 | " markers=[Marker(location=feature['geometry']['coordinates'][::-1]) for feature in json_data['features']],\n",
110 | " name = 'Markers')"
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "execution_count": 21,
116 | "metadata": {},
117 | "outputs": [],
118 | "source": [
119 | "Map.add_layer(maker_cluster)"
120 | ]
121 | },
122 | {
123 | "cell_type": "code",
124 | "execution_count": 22,
125 | "metadata": {},
126 | "outputs": [],
127 | "source": [
128 | "ee_fc = geojson_to_ee(json_data)\n",
129 | "Map.addLayer(ee_fc, {}, \"US Cities EE\")"
130 | ]
131 | }
132 | ],
133 | "metadata": {
134 | "hide_input": false,
135 | "kernelspec": {
136 | "display_name": "Python 3",
137 | "language": "python",
138 | "name": "python3"
139 | },
140 | "language_info": {
141 | "codemirror_mode": {
142 | "name": "ipython",
143 | "version": 3
144 | },
145 | "file_extension": ".py",
146 | "mimetype": "text/x-python",
147 | "name": "python",
148 | "nbconvert_exporter": "python",
149 | "pygments_lexer": "ipython3",
150 | "version": "3.8.5"
151 | },
152 | "toc": {
153 | "base_numbering": 1,
154 | "nav_menu": {},
155 | "number_sections": true,
156 | "sideBar": true,
157 | "skip_h1_title": true,
158 | "title_cell": "Table of Contents",
159 | "title_sidebar": "Table of Contents",
160 | "toc_cell": false,
161 | "toc_position": {},
162 | "toc_section_display": true,
163 | "toc_window_display": true
164 | },
165 | "varInspector": {
166 | "cols": {
167 | "lenName": 16,
168 | "lenType": 16,
169 | "lenVar": 40
170 | },
171 | "kernels_config": {
172 | "python": {
173 | "delete_cmd_postfix": "",
174 | "delete_cmd_prefix": "del ",
175 | "library": "var_list.py",
176 | "varRefreshCmd": "print(var_dic_list())"
177 | },
178 | "r": {
179 | "delete_cmd_postfix": ") ",
180 | "delete_cmd_prefix": "rm(",
181 | "library": "var_list.r",
182 | "varRefreshCmd": "cat(var_dic_list()) "
183 | }
184 | },
185 | "types_to_exclude": [
186 | "module",
187 | "function",
188 | "builtin_function_or_method",
189 | "instance",
190 | "_Feature"
191 | ],
192 | "window_display": false
193 | }
194 | },
195 | "nbformat": 4,
196 | "nbformat_minor": 4
197 | }
198 |
--------------------------------------------------------------------------------
/notebooks/07_geojson.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import geemap\n",
28 | "import json\n",
29 | "import os\n",
30 | "import requests\n",
31 | "from geemap import geojson_to_ee, ee_to_geojson\n",
32 | "from ipyleaflet import GeoJSON"
33 | ]
34 | },
35 | {
36 | "cell_type": "code",
37 | "execution_count": null,
38 | "metadata": {},
39 | "outputs": [],
40 | "source": [
41 | "geemap.show_youtube('DbK_SRgrCHw')"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": null,
47 | "metadata": {},
48 | "outputs": [],
49 | "source": [
50 | "Map = geemap.Map()\n",
51 | "Map"
52 | ]
53 | },
54 | {
55 | "cell_type": "code",
56 | "execution_count": null,
57 | "metadata": {},
58 | "outputs": [],
59 | "source": [
60 | "file_path = os.path.abspath('../data/us-states.json')\n",
61 | "\n",
62 | "if not os.path.exists(file_path):\n",
63 | " url = 'https://github.com/giswqs/geemap/raw/master/examples/data/us-states.json'\n",
64 | " r = requests.get(url)\n",
65 | " with open(file_path, 'w') as f:\n",
66 | " f.write(r.content.decode(\"utf-8\")) \n",
67 | "\n",
68 | "with open(file_path) as f:\n",
69 | " json_data = json.load(f)"
70 | ]
71 | },
72 | {
73 | "cell_type": "code",
74 | "execution_count": null,
75 | "metadata": {},
76 | "outputs": [],
77 | "source": [
78 | "json_layer = GeoJSON(data=json_data, name='US States JSON', hover_style={'fillColor': 'red' , 'fillOpacity': 0.5})\n",
79 | "Map.add_layer(json_layer)"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": null,
85 | "metadata": {},
86 | "outputs": [],
87 | "source": [
88 | "ee_data = geojson_to_ee(json_data)\n",
89 | "Map.addLayer(ee_data, {}, \"US States EE\")"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {},
96 | "outputs": [],
97 | "source": [
98 | "json_data_2 = ee_to_geojson(ee_data)\n",
99 | "json_layer_2 = GeoJSON(data=json_data_2, name='US States EE JSON', hover_style={'fillColor': 'red' , 'fillOpacity': 0.5})\n",
100 | "Map.add_layer(json_layer_2)"
101 | ]
102 | },
103 | {
104 | "cell_type": "code",
105 | "execution_count": null,
106 | "metadata": {},
107 | "outputs": [],
108 | "source": [
109 | "file_path = os.path.abspath('../data/countries.json')\n",
110 | "\n",
111 | "if not os.path.exists(file_path):\n",
112 | " url = 'https://github.com/giswqs/geemap/raw/master/examples/data/countries.json'\n",
113 | " r = requests.get(url)\n",
114 | " with open(file_path, 'w') as f:\n",
115 | " f.write(r.content.decode(\"utf-8\")) \n",
116 | "\n",
117 | "with open(file_path) as f:\n",
118 | " json_data = json.load(f)"
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": null,
124 | "metadata": {},
125 | "outputs": [],
126 | "source": [
127 | "json_layer = GeoJSON(data=json_data, name='Counties', hover_style={'fillColor': 'red' , 'fillOpacity': 0.5})\n",
128 | "Map.add_layer(json_layer)"
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": null,
134 | "metadata": {},
135 | "outputs": [],
136 | "source": [
137 | "from ipywidgets import Text, HTML\n",
138 | "from ipyleaflet import WidgetControl, GeoJSON \n",
139 | "\n",
140 | "html1 = HTML('''\n",
141 | " Country
\n",
142 | " Hover over a country\n",
143 | "''')\n",
144 | "html1.layout.margin = '0px 20px 20px 20px'\n",
145 | "control1 = WidgetControl(widget=html1, position='bottomright')\n",
146 | "Map.add_control(control1)\n",
147 | "\n",
148 | "def update_html(feature, **kwargs):\n",
149 | " html1.value = '''\n",
150 | " Country code: {}
\n",
151 | " Country name: {}\n",
152 | " '''.format(feature['id'], feature['properties']['name'])\n",
153 | "\n",
154 | "json_layer.on_hover(update_html)"
155 | ]
156 | }
157 | ],
158 | "metadata": {
159 | "hide_input": false,
160 | "kernelspec": {
161 | "display_name": "Python 3",
162 | "language": "python",
163 | "name": "python3"
164 | },
165 | "language_info": {
166 | "codemirror_mode": {
167 | "name": "ipython",
168 | "version": 3
169 | },
170 | "file_extension": ".py",
171 | "mimetype": "text/x-python",
172 | "name": "python",
173 | "nbconvert_exporter": "python",
174 | "pygments_lexer": "ipython3",
175 | "version": "3.8.5"
176 | },
177 | "toc": {
178 | "base_numbering": 1,
179 | "nav_menu": {},
180 | "number_sections": true,
181 | "sideBar": true,
182 | "skip_h1_title": true,
183 | "title_cell": "Table of Contents",
184 | "title_sidebar": "Table of Contents",
185 | "toc_cell": false,
186 | "toc_position": {},
187 | "toc_section_display": true,
188 | "toc_window_display": true
189 | },
190 | "varInspector": {
191 | "cols": {
192 | "lenName": 16,
193 | "lenType": 16,
194 | "lenVar": 40
195 | },
196 | "kernels_config": {
197 | "python": {
198 | "delete_cmd_postfix": "",
199 | "delete_cmd_prefix": "del ",
200 | "library": "var_list.py",
201 | "varRefreshCmd": "print(var_dic_list())"
202 | },
203 | "r": {
204 | "delete_cmd_postfix": ") ",
205 | "delete_cmd_prefix": "rm(",
206 | "library": "var_list.r",
207 | "varRefreshCmd": "cat(var_dic_list()) "
208 | }
209 | },
210 | "types_to_exclude": [
211 | "module",
212 | "function",
213 | "builtin_function_or_method",
214 | "instance",
215 | "_Feature"
216 | ],
217 | "window_display": false
218 | }
219 | },
220 | "nbformat": 4,
221 | "nbformat_minor": 4
222 | }
223 |
--------------------------------------------------------------------------------
/notebooks/08_ee_js_to_ipynb.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "## Automatic conversion from Earth Engine JavaScripts to Python scripts\n",
26 | "\n",
27 | "### Install Earth Engine API and geemap\n",
28 | "Install the [Earth Engine Python API](https://developers.google.com/earth-engine/python_install) and [geemap](https://github.com/giswqs/geemap). The **geemap** Python package is built upon the [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) and [folium](https://github.com/python-visualization/folium) packages and implements several methods for interacting with Earth Engine data layers, such as `Map.addLayer()`, `Map.setCenter()`, and `Map.centerObject()`.\n",
29 | "The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its [dependencies](https://github.com/giswqs/geemap#dependencies), including earthengine-api, folium, and ipyleaflet.\n",
30 | "\n",
31 | "**Important note**: A key difference between folium and ipyleaflet is that ipyleaflet is built upon ipywidgets and allows bidirectional communication between the front-end and the backend enabling the use of the map to capture user input, while folium is meant for displaying static data only ([source](https://blog.jupyter.org/interactive-gis-in-jupyter-with-ipyleaflet-52f9657fa7a)). Note that [Google Colab](https://colab.research.google.com/) currently does not support ipyleaflet ([source](https://github.com/googlecolab/colabtools/issues/60#issuecomment-596225619)). Therefore, if you are using geemap with Google Colab, you should use [`import geemap.eefolium`](https://github.com/giswqs/geemap/blob/master/geemap/eefolium.py). If you are using geemap with [binder](https://mybinder.org/) or a local Jupyter notebook server, you can use [`import geemap`](https://github.com/giswqs/geemap/blob/master/geemap/geemap.py), which provides more functionalities for capturing user input (e.g., mouse-clicking and moving)."
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": null,
37 | "metadata": {},
38 | "outputs": [],
39 | "source": [
40 | "import geemap"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {},
47 | "outputs": [],
48 | "source": [
49 | "geemap.show_youtube('RpIaalFk4H8')"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "### Convert Earth Eninge JavaScripts to Python scripts"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": null,
62 | "metadata": {},
63 | "outputs": [],
64 | "source": [
65 | "import os\n",
66 | "from geemap.conversion import *\n",
67 | "\n",
68 | "# Create a temporary working directory\n",
69 | "work_dir = os.path.join(os.path.expanduser('~'), 'geemap')\n",
70 | "# Get Earth Engine JavaScript examples. There are five examples in the geemap package folder. \n",
71 | "# Change js_dir to your own folder containing your Earth Engine JavaScripts, \n",
72 | "# such as js_dir = '/path/to/your/js/folder'\n",
73 | "js_dir = get_js_examples(out_dir=work_dir) \n",
74 | "\n",
75 | "# Convert all Earth Engine JavaScripts in a folder recursively to Python scripts.\n",
76 | "js_to_python_dir(in_dir=js_dir, out_dir=js_dir, use_qgis=True)\n",
77 | "print(\"Python scripts saved at: {}\".format(js_dir))"
78 | ]
79 | },
80 | {
81 | "cell_type": "markdown",
82 | "metadata": {},
83 | "source": [
84 | "### Convert Earth Engine Python scripts to Jupyter Notebooks"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": null,
90 | "metadata": {},
91 | "outputs": [],
92 | "source": [
93 | "# Convert all Earth Engine Python scripts in a folder recursively to Jupyter notebooks.\n",
94 | "nb_template = get_nb_template() # Get the notebook template from the package folder.\n",
95 | "py_to_ipynb_dir(js_dir, nb_template)\n",
96 | "\n",
97 | "# Execute all Jupyter notebooks in a folder recursively and save the output cells.\n",
98 | "execute_notebook_dir(in_dir=js_dir)"
99 | ]
100 | }
101 | ],
102 | "metadata": {
103 | "hide_input": false,
104 | "kernelspec": {
105 | "display_name": "Python 3",
106 | "language": "python",
107 | "name": "python3"
108 | },
109 | "language_info": {
110 | "codemirror_mode": {
111 | "name": "ipython",
112 | "version": 3
113 | },
114 | "file_extension": ".py",
115 | "mimetype": "text/x-python",
116 | "name": "python",
117 | "nbconvert_exporter": "python",
118 | "pygments_lexer": "ipython3",
119 | "version": "3.8.5"
120 | },
121 | "toc": {
122 | "base_numbering": 1,
123 | "nav_menu": {},
124 | "number_sections": true,
125 | "sideBar": true,
126 | "skip_h1_title": true,
127 | "title_cell": "Table of Contents",
128 | "title_sidebar": "Table of Contents",
129 | "toc_cell": false,
130 | "toc_position": {},
131 | "toc_section_display": true,
132 | "toc_window_display": true
133 | },
134 | "varInspector": {
135 | "cols": {
136 | "lenName": 16,
137 | "lenType": 16,
138 | "lenVar": 40
139 | },
140 | "kernels_config": {
141 | "python": {
142 | "delete_cmd_postfix": "",
143 | "delete_cmd_prefix": "del ",
144 | "library": "var_list.py",
145 | "varRefreshCmd": "print(var_dic_list())"
146 | },
147 | "r": {
148 | "delete_cmd_postfix": ") ",
149 | "delete_cmd_prefix": "rm(",
150 | "library": "var_list.r",
151 | "varRefreshCmd": "cat(var_dic_list()) "
152 | }
153 | },
154 | "types_to_exclude": [
155 | "module",
156 | "function",
157 | "builtin_function_or_method",
158 | "instance",
159 | "_Feature"
160 | ],
161 | "window_display": false
162 | }
163 | },
164 | "nbformat": 4,
165 | "nbformat_minor": 4
166 | }
167 |
--------------------------------------------------------------------------------
/notebooks/09_plotting.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import ee\n",
28 | "import geemap"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": null,
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "geemap.show_youtube('PDab8mkAFL0')"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": null,
43 | "metadata": {},
44 | "outputs": [],
45 | "source": [
46 | "Map = geemap.Map()\n",
47 | "Map"
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": null,
53 | "metadata": {},
54 | "outputs": [],
55 | "source": [
56 | "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003') \\\n",
57 | " .select([0, 1, 2, 3, 4, 6])\n",
58 | "landsat_vis = {\n",
59 | " 'bands': ['B4', 'B3', 'B2'], \n",
60 | " 'gamma': 1.4\n",
61 | "}\n",
62 | "Map.addLayer(landsat7, landsat_vis, \"LE7_TOA_5YEAR/1999_2003\")\n",
63 | "\n",
64 | "hyperion = ee.ImageCollection('EO1/HYPERION') \\\n",
65 | " .filter(ee.Filter.date('2016-01-01', '2017-03-01'));\n",
66 | "hyperion_vis = {\n",
67 | " 'min': 1000.0,\n",
68 | " 'max': 14000.0,\n",
69 | " 'gamma': 2.5,\n",
70 | "}\n",
71 | "Map.addLayer(hyperion, hyperion_vis, 'EO1/HYPERION');"
72 | ]
73 | },
74 | {
75 | "cell_type": "code",
76 | "execution_count": null,
77 | "metadata": {},
78 | "outputs": [],
79 | "source": [
80 | "Map.set_plot_options(plot_type='bar', add_marker_cluster=True)"
81 | ]
82 | },
83 | {
84 | "cell_type": "code",
85 | "execution_count": null,
86 | "metadata": {},
87 | "outputs": [],
88 | "source": [
89 | "m = geemap.Map()\n",
90 | "m"
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "execution_count": null,
96 | "metadata": {},
97 | "outputs": [],
98 | "source": [
99 | "m.plot_demo()"
100 | ]
101 | }
102 | ],
103 | "metadata": {
104 | "hide_input": false,
105 | "kernelspec": {
106 | "display_name": "Python 3",
107 | "language": "python",
108 | "name": "python3"
109 | },
110 | "language_info": {
111 | "codemirror_mode": {
112 | "name": "ipython",
113 | "version": 3
114 | },
115 | "file_extension": ".py",
116 | "mimetype": "text/x-python",
117 | "name": "python",
118 | "nbconvert_exporter": "python",
119 | "pygments_lexer": "ipython3",
120 | "version": "3.8.5"
121 | },
122 | "toc": {
123 | "base_numbering": 1,
124 | "nav_menu": {},
125 | "number_sections": true,
126 | "sideBar": true,
127 | "skip_h1_title": true,
128 | "title_cell": "Table of Contents",
129 | "title_sidebar": "Table of Contents",
130 | "toc_cell": false,
131 | "toc_position": {},
132 | "toc_section_display": true,
133 | "toc_window_display": true
134 | },
135 | "varInspector": {
136 | "cols": {
137 | "lenName": 16,
138 | "lenType": 16,
139 | "lenVar": 40
140 | },
141 | "kernels_config": {
142 | "python": {
143 | "delete_cmd_postfix": "",
144 | "delete_cmd_prefix": "del ",
145 | "library": "var_list.py",
146 | "varRefreshCmd": "print(var_dic_list())"
147 | },
148 | "r": {
149 | "delete_cmd_postfix": ") ",
150 | "delete_cmd_prefix": "rm(",
151 | "library": "var_list.r",
152 | "varRefreshCmd": "cat(var_dic_list()) "
153 | }
154 | },
155 | "types_to_exclude": [
156 | "module",
157 | "function",
158 | "builtin_function_or_method",
159 | "instance",
160 | "_Feature"
161 | ],
162 | "window_display": false
163 | }
164 | },
165 | "nbformat": 4,
166 | "nbformat_minor": 4
167 | }
168 |
--------------------------------------------------------------------------------
/notebooks/10_shapefiles.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import geemap"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {},
34 | "outputs": [],
35 | "source": [
36 | "geemap.show_youtube('OlNlqfj4uHo')"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {},
43 | "outputs": [],
44 | "source": [
45 | "Map = geemap.Map()\n",
46 | "Map"
47 | ]
48 | },
49 | {
50 | "cell_type": "code",
51 | "execution_count": null,
52 | "metadata": {},
53 | "outputs": [],
54 | "source": [
55 | "countries_shp = '../data/countries.shp'\n",
56 | "countries = geemap.shp_to_ee(countries_shp)\n",
57 | "Map.addLayer(countries, {}, 'Countries')"
58 | ]
59 | },
60 | {
61 | "cell_type": "code",
62 | "execution_count": null,
63 | "metadata": {},
64 | "outputs": [],
65 | "source": [
66 | "states_shp = '../data/us-states.shp'\n",
67 | "states = geemap.shp_to_ee(states_shp)\n",
68 | "Map.addLayer(states, {}, 'US States')"
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": null,
74 | "metadata": {},
75 | "outputs": [],
76 | "source": [
77 | "cities_shp = '../data/us-cities.shp'\n",
78 | "cities = geemap.shp_to_ee(cities_shp)\n",
79 | "Map.addLayer(cities, {}, 'US Cities')"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": null,
85 | "metadata": {},
86 | "outputs": [],
87 | "source": [
88 | "geemap.ee_to_shp(countries, filename='../data/countries_new.shp')"
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": null,
94 | "metadata": {},
95 | "outputs": [],
96 | "source": [
97 | "geemap.ee_export_vector(states, filename='../data/states.csv')"
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": null,
103 | "metadata": {},
104 | "outputs": [],
105 | "source": [
106 | "geemap.ee_export_vector(states, filename='../data/states.kml')"
107 | ]
108 | },
109 | {
110 | "cell_type": "code",
111 | "execution_count": null,
112 | "metadata": {},
113 | "outputs": [],
114 | "source": [
115 | "geemap.ee_export_vector(states, filename='../data/states.kmz')"
116 | ]
117 | }
118 | ],
119 | "metadata": {
120 | "hide_input": false,
121 | "kernelspec": {
122 | "display_name": "Python 3",
123 | "language": "python",
124 | "name": "python3"
125 | },
126 | "language_info": {
127 | "codemirror_mode": {
128 | "name": "ipython",
129 | "version": 3
130 | },
131 | "file_extension": ".py",
132 | "mimetype": "text/x-python",
133 | "name": "python",
134 | "nbconvert_exporter": "python",
135 | "pygments_lexer": "ipython3",
136 | "version": "3.8.5"
137 | },
138 | "toc": {
139 | "base_numbering": 1,
140 | "nav_menu": {},
141 | "number_sections": true,
142 | "sideBar": true,
143 | "skip_h1_title": true,
144 | "title_cell": "Table of Contents",
145 | "title_sidebar": "Table of Contents",
146 | "toc_cell": false,
147 | "toc_position": {},
148 | "toc_section_display": true,
149 | "toc_window_display": true
150 | },
151 | "varInspector": {
152 | "cols": {
153 | "lenName": 16,
154 | "lenType": 16,
155 | "lenVar": 40
156 | },
157 | "kernels_config": {
158 | "python": {
159 | "delete_cmd_postfix": "",
160 | "delete_cmd_prefix": "del ",
161 | "library": "var_list.py",
162 | "varRefreshCmd": "print(var_dic_list())"
163 | },
164 | "r": {
165 | "delete_cmd_postfix": ") ",
166 | "delete_cmd_prefix": "rm(",
167 | "library": "var_list.r",
168 | "varRefreshCmd": "cat(var_dic_list()) "
169 | }
170 | },
171 | "types_to_exclude": [
172 | "module",
173 | "function",
174 | "builtin_function_or_method",
175 | "instance",
176 | "_Feature"
177 | ],
178 | "window_display": false
179 | }
180 | },
181 | "nbformat": 4,
182 | "nbformat_minor": 4
183 | }
184 |
--------------------------------------------------------------------------------
/notebooks/12_zonal_statistics.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import ee\n",
28 | "import geemap\n",
29 | "import os"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": null,
35 | "metadata": {},
36 | "outputs": [],
37 | "source": [
38 | "geemap.show_youtube('ou-Xm3CLitM')"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "Map = geemap.Map()\n",
48 | "Map"
49 | ]
50 | },
51 | {
52 | "cell_type": "code",
53 | "execution_count": null,
54 | "metadata": {},
55 | "outputs": [],
56 | "source": [
57 | "# Add Earth Engine dataset\n",
58 | "dem = ee.Image('USGS/SRTMGL1_003')\n",
59 | "\n",
60 | "# Set visualization parameters.\n",
61 | "dem_vis = {\n",
62 | " 'min': 0,\n",
63 | " 'max': 4000,\n",
64 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
65 | "\n",
66 | "# Add Earth Engine DEM to map\n",
67 | "Map.addLayer(dem, dem_vis, 'SRTM DEM')\n",
68 | "\n",
69 | "# Add Landsat data to map\n",
70 | "landsat = ee.Image('LE7_TOA_5YEAR/1999_2003')\n",
71 | "\n",
72 | "landsat_vis = {\n",
73 | " 'bands': ['B4', 'B3', 'B2'], \n",
74 | " 'gamma': 1.4\n",
75 | "}\n",
76 | "Map.addLayer(landsat, landsat_vis, \"LE7_TOA_5YEAR/1999_2003\")\n",
77 | "\n",
78 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
79 | "Map.addLayer(states, {}, 'US States')"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": null,
85 | "metadata": {},
86 | "outputs": [],
87 | "source": [
88 | "out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')\n",
89 | "out_dem_stats = os.path.join(out_dir, 'dem_stats.csv') \n",
90 | "\n",
91 | "if not os.path.exists(out_dir):\n",
92 | " os.makedirs(out_dir)\n",
93 | "\n",
94 | "# Allowed output formats: csv, shp, json, kml, kmz\n",
95 | "# Allowed statistics type: MEAN, MAXIMUM, MINIMUM, MEDIAN, STD, MIN_MAX, VARIANCE, SUM\n",
96 | "geemap.zonal_statistics(dem, states, out_dem_stats, statistics_type='MEAN', scale=1000)"
97 | ]
98 | },
99 | {
100 | "cell_type": "code",
101 | "execution_count": null,
102 | "metadata": {
103 | "scrolled": true
104 | },
105 | "outputs": [],
106 | "source": [
107 | "out_landsat_stats = os.path.join(out_dir, 'landsat_stats.csv') \n",
108 | "geemap.zonal_statistics(landsat, states, out_landsat_stats, statistics_type='SUM', scale=1000)"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": null,
114 | "metadata": {},
115 | "outputs": [],
116 | "source": [
117 | "geemap.create_download_link(out_dem_stats)"
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "execution_count": null,
123 | "metadata": {},
124 | "outputs": [],
125 | "source": [
126 | "geemap.create_download_link(out_landsat_stats)"
127 | ]
128 | }
129 | ],
130 | "metadata": {
131 | "hide_input": false,
132 | "kernelspec": {
133 | "display_name": "Python 3",
134 | "language": "python",
135 | "name": "python3"
136 | },
137 | "language_info": {
138 | "codemirror_mode": {
139 | "name": "ipython",
140 | "version": 3
141 | },
142 | "file_extension": ".py",
143 | "mimetype": "text/x-python",
144 | "name": "python",
145 | "nbconvert_exporter": "python",
146 | "pygments_lexer": "ipython3",
147 | "version": "3.8.5"
148 | },
149 | "toc": {
150 | "base_numbering": 1,
151 | "nav_menu": {},
152 | "number_sections": true,
153 | "sideBar": true,
154 | "skip_h1_title": true,
155 | "title_cell": "Table of Contents",
156 | "title_sidebar": "Table of Contents",
157 | "toc_cell": false,
158 | "toc_position": {},
159 | "toc_section_display": true,
160 | "toc_window_display": true
161 | },
162 | "varInspector": {
163 | "cols": {
164 | "lenName": 16,
165 | "lenType": 16,
166 | "lenVar": 40
167 | },
168 | "kernels_config": {
169 | "python": {
170 | "delete_cmd_postfix": "",
171 | "delete_cmd_prefix": "del ",
172 | "library": "var_list.py",
173 | "varRefreshCmd": "print(var_dic_list())"
174 | },
175 | "r": {
176 | "delete_cmd_postfix": ") ",
177 | "delete_cmd_prefix": "rm(",
178 | "library": "var_list.r",
179 | "varRefreshCmd": "cat(var_dic_list()) "
180 | }
181 | },
182 | "types_to_exclude": [
183 | "module",
184 | "function",
185 | "builtin_function_or_method",
186 | "instance",
187 | "_Feature"
188 | ],
189 | "window_display": false
190 | }
191 | },
192 | "nbformat": 4,
193 | "nbformat_minor": 4
194 | }
195 |
--------------------------------------------------------------------------------
/notebooks/19_search_places_and_datasets.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import ee\n",
28 | "import geemap"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": null,
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "geemap.show_youtube('lwtgzrHrXj8')"
38 | ]
39 | },
40 | {
41 | "cell_type": "markdown",
42 | "metadata": {},
43 | "source": [
44 | "## Update the geemap package\n",
45 | "\n",
46 | "If you run into errors with this notebook, please uncomment the line below to update the [geemap](https://github.com/giswqs/geemap#installation) package to the latest version from GitHub. \n",
47 | "Restart the Kernel (Menu -> Kernel -> Restart) to take effect."
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": null,
53 | "metadata": {},
54 | "outputs": [],
55 | "source": [
56 | "# geemap.update_package()"
57 | ]
58 | },
59 | {
60 | "cell_type": "markdown",
61 | "metadata": {},
62 | "source": [
63 | "## Create an interactive map"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "Map = geemap.Map()\n",
73 | "Map"
74 | ]
75 | },
76 | {
77 | "cell_type": "markdown",
78 | "metadata": {},
79 | "source": [
80 | "## Convert marker to ee.Geometry"
81 | ]
82 | },
83 | {
84 | "cell_type": "code",
85 | "execution_count": null,
86 | "metadata": {},
87 | "outputs": [],
88 | "source": [
89 | "Map.search_locations"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {},
96 | "outputs": [],
97 | "source": [
98 | "Map.search_loc_geom"
99 | ]
100 | },
101 | {
102 | "cell_type": "code",
103 | "execution_count": null,
104 | "metadata": {},
105 | "outputs": [],
106 | "source": [
107 | "location = Map.search_loc_geom\n",
108 | "# print(location.getInfo())"
109 | ]
110 | }
111 | ],
112 | "metadata": {
113 | "hide_input": false,
114 | "kernelspec": {
115 | "display_name": "Python 3",
116 | "language": "python",
117 | "name": "python3"
118 | },
119 | "language_info": {
120 | "codemirror_mode": {
121 | "name": "ipython",
122 | "version": 3
123 | },
124 | "file_extension": ".py",
125 | "mimetype": "text/x-python",
126 | "name": "python",
127 | "nbconvert_exporter": "python",
128 | "pygments_lexer": "ipython3",
129 | "version": "3.8.5"
130 | },
131 | "toc": {
132 | "base_numbering": 1,
133 | "nav_menu": {},
134 | "number_sections": true,
135 | "sideBar": true,
136 | "skip_h1_title": true,
137 | "title_cell": "Table of Contents",
138 | "title_sidebar": "Table of Contents",
139 | "toc_cell": false,
140 | "toc_position": {},
141 | "toc_section_display": true,
142 | "toc_window_display": true
143 | },
144 | "varInspector": {
145 | "cols": {
146 | "lenName": 16,
147 | "lenType": 16,
148 | "lenVar": 40
149 | },
150 | "kernels_config": {
151 | "python": {
152 | "delete_cmd_postfix": "",
153 | "delete_cmd_prefix": "del ",
154 | "library": "var_list.py",
155 | "varRefreshCmd": "print(var_dic_list())"
156 | },
157 | "r": {
158 | "delete_cmd_postfix": ") ",
159 | "delete_cmd_prefix": "rm(",
160 | "library": "var_list.r",
161 | "varRefreshCmd": "cat(var_dic_list()) "
162 | }
163 | },
164 | "types_to_exclude": [
165 | "module",
166 | "function",
167 | "builtin_function_or_method",
168 | "instance",
169 | "_Feature"
170 | ],
171 | "window_display": false
172 | }
173 | },
174 | "nbformat": 4,
175 | "nbformat_minor": 4
176 | }
177 |
--------------------------------------------------------------------------------
/notebooks/22_import_scripts.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import ee\n",
28 | "import geemap"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": null,
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "Map = geemap.Map()\n",
38 | "Map"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "geemap.ee_search()"
48 | ]
49 | }
50 | ],
51 | "metadata": {
52 | "hide_input": false,
53 | "kernelspec": {
54 | "display_name": "Python 3",
55 | "language": "python",
56 | "name": "python3"
57 | },
58 | "language_info": {
59 | "codemirror_mode": {
60 | "name": "ipython",
61 | "version": 3
62 | },
63 | "file_extension": ".py",
64 | "mimetype": "text/x-python",
65 | "name": "python",
66 | "nbconvert_exporter": "python",
67 | "pygments_lexer": "ipython3",
68 | "version": "3.8.5"
69 | },
70 | "toc": {
71 | "base_numbering": 1,
72 | "nav_menu": {},
73 | "number_sections": true,
74 | "sideBar": true,
75 | "skip_h1_title": true,
76 | "title_cell": "Table of Contents",
77 | "title_sidebar": "Table of Contents",
78 | "toc_cell": false,
79 | "toc_position": {},
80 | "toc_section_display": true,
81 | "toc_window_display": false
82 | },
83 | "varInspector": {
84 | "cols": {
85 | "lenName": 16,
86 | "lenType": 16,
87 | "lenVar": 40
88 | },
89 | "kernels_config": {
90 | "python": {
91 | "delete_cmd_postfix": "",
92 | "delete_cmd_prefix": "del ",
93 | "library": "var_list.py",
94 | "varRefreshCmd": "print(var_dic_list())"
95 | },
96 | "r": {
97 | "delete_cmd_postfix": ") ",
98 | "delete_cmd_prefix": "rm(",
99 | "library": "var_list.r",
100 | "varRefreshCmd": "cat(var_dic_list()) "
101 | }
102 | },
103 | "types_to_exclude": [
104 | "module",
105 | "function",
106 | "builtin_function_or_method",
107 | "instance",
108 | "_Feature"
109 | ],
110 | "window_display": false
111 | }
112 | },
113 | "nbformat": 4,
114 | "nbformat_minor": 4
115 | }
116 |
--------------------------------------------------------------------------------
/notebooks/23_import_assets.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import os\n",
28 | "import ee\n",
29 | "import geemap"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": null,
35 | "metadata": {},
36 | "outputs": [],
37 | "source": [
38 | "Map = geemap.Map()\n",
39 | "Map"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')\n",
49 | "if not os.path.exists(out_dir):\n",
50 | " os.makedirs(out_dir)"
51 | ]
52 | },
53 | {
54 | "cell_type": "code",
55 | "execution_count": null,
56 | "metadata": {},
57 | "outputs": [],
58 | "source": [
59 | "out_csv = os.path.join(out_dir, 'ee_api.csv')\n",
60 | "geemap.ee_api_to_csv(out_csv)"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "geemap.ee_search()"
70 | ]
71 | }
72 | ],
73 | "metadata": {
74 | "hide_input": false,
75 | "kernelspec": {
76 | "display_name": "Python 3",
77 | "language": "python",
78 | "name": "python3"
79 | },
80 | "language_info": {
81 | "codemirror_mode": {
82 | "name": "ipython",
83 | "version": 3
84 | },
85 | "file_extension": ".py",
86 | "mimetype": "text/x-python",
87 | "name": "python",
88 | "nbconvert_exporter": "python",
89 | "pygments_lexer": "ipython3",
90 | "version": "3.8.5"
91 | },
92 | "toc": {
93 | "base_numbering": 1,
94 | "nav_menu": {},
95 | "number_sections": true,
96 | "sideBar": true,
97 | "skip_h1_title": true,
98 | "title_cell": "Table of Contents",
99 | "title_sidebar": "Table of Contents",
100 | "toc_cell": false,
101 | "toc_position": {},
102 | "toc_section_display": true,
103 | "toc_window_display": true
104 | },
105 | "varInspector": {
106 | "cols": {
107 | "lenName": 16,
108 | "lenType": 16,
109 | "lenVar": 40
110 | },
111 | "kernels_config": {
112 | "python": {
113 | "delete_cmd_postfix": "",
114 | "delete_cmd_prefix": "del ",
115 | "library": "var_list.py",
116 | "varRefreshCmd": "print(var_dic_list())"
117 | },
118 | "r": {
119 | "delete_cmd_postfix": ") ",
120 | "delete_cmd_prefix": "rm(",
121 | "library": "var_list.r",
122 | "varRefreshCmd": "cat(var_dic_list()) "
123 | }
124 | },
125 | "types_to_exclude": [
126 | "module",
127 | "function",
128 | "builtin_function_or_method",
129 | "instance",
130 | "_Feature"
131 | ],
132 | "window_display": false
133 | }
134 | },
135 | "nbformat": 4,
136 | "nbformat_minor": 4
137 | }
138 |
--------------------------------------------------------------------------------
/notebooks/24_publish_maps.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "To follow this tutorial, you will need to [sign up](https://datapane.com/accounts/signup/) for an account with , then install and authenticate the `datapane` Python package. More information can be found [here](https://docs.datapane.com/tutorials/tut-getting-started). \n",
26 | "\n",
27 | "- `pip install datapane`\n",
28 | "- `datapane login`\n",
29 | "- `datapane ping`"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": null,
35 | "metadata": {},
36 | "outputs": [],
37 | "source": [
38 | "import ee \n",
39 | "import geemap.eefolium as geemap"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "# Create a map centered at (lat, lon).\n",
49 | "Map = geemap.Map(center=[40, -100], zoom=4)\n",
50 | "\n",
51 | "# Use an elevation dataset and terrain functions to create\n",
52 | "# a custom visualization of topography.\n",
53 | "\n",
54 | "# Load a global elevation image.\n",
55 | "elev = ee.Image('USGS/GMTED2010')\n",
56 | "\n",
57 | "# Zoom to an area of interest.\n",
58 | "Map.setCenter(-121.069, 50.709, 6)\n",
59 | "\n",
60 | "# Add the elevation to the map.\n",
61 | "Map.addLayer(elev, {}, 'elev')\n",
62 | "\n",
63 | "# Use the terrain algorithms to compute a hillshade with 8-bit values.\n",
64 | "shade = ee.Terrain.hillshade(elev)\n",
65 | "Map.addLayer(shade, {}, 'hillshade', False)\n",
66 | "\n",
67 | "# Create a \"sea\" variable to be used for cartographic purposes\n",
68 | "sea = elev.lte(0)\n",
69 | "Map.addLayer(sea.mask(sea), {'palette':'000022'}, 'sea', False)\n",
70 | "\n",
71 | "# Create a custom elevation palette from hex strings.\n",
72 | "elevationPalette = ['006600', '002200', 'fff700', 'ab7634', 'c4d0ff', 'ffffff']\n",
73 | "# Use these visualization parameters, customized by location.\n",
74 | "visParams = {'min': 1, 'max': 3000, 'palette': elevationPalette}\n",
75 | "\n",
76 | "# Create a mosaic of the sea and the elevation data\n",
77 | "visualized = ee.ImageCollection([\n",
78 | " # Mask the elevation to get only land\n",
79 | " elev.mask(sea.Not()).visualize(**visParams),\n",
80 | " # Use the sea mask directly to display sea.\n",
81 | " sea.mask(sea).visualize(**{'palette':'000022'})\n",
82 | "]).mosaic()\n",
83 | "\n",
84 | "# Note that the visualization image doesn't require visualization parameters.\n",
85 | "Map.addLayer(visualized, {}, 'elev palette', False)\n",
86 | "\n",
87 | "# Convert the visualized elevation to HSV, first converting to [0, 1] data.\n",
88 | "hsv = visualized.divide(255).rgbToHsv()\n",
89 | "# Select only the hue and saturation bands.\n",
90 | "hs = hsv.select(0, 1)\n",
91 | "# Convert the hillshade to [0, 1] data, as expected by the HSV algorithm.\n",
92 | "v = shade.divide(255)\n",
93 | "# Create a visualization image by converting back to RGB from HSV.\n",
94 | "# Note the cast to byte in order to export the image correctly.\n",
95 | "rgb = hs.addBands(v).hsvToRgb().multiply(255).byte()\n",
96 | "Map.addLayer(rgb, {}, 'styled')\n",
97 | "\n",
98 | "states = ee.FeatureCollection('TIGER/2018/States')\n",
99 | "Map.addLayer(ee.Image().paint(states, 0, 2), {}, \"US States\")"
100 | ]
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": null,
105 | "metadata": {},
106 | "outputs": [],
107 | "source": [
108 | "# Add layer control to the map.\n",
109 | "Map.setControlVisibility()\n",
110 | "# Display the map.\n",
111 | "Map"
112 | ]
113 | },
114 | {
115 | "cell_type": "code",
116 | "execution_count": null,
117 | "metadata": {},
118 | "outputs": [],
119 | "source": [
120 | "Map.publish(name='gee_folium_map', headline='Terrain Visualization', visibility='PUBLIC', overwrite=True)"
121 | ]
122 | }
123 | ],
124 | "metadata": {
125 | "hide_input": false,
126 | "kernelspec": {
127 | "display_name": "Python 3",
128 | "language": "python",
129 | "name": "python3"
130 | },
131 | "language_info": {
132 | "codemirror_mode": {
133 | "name": "ipython",
134 | "version": 3
135 | },
136 | "file_extension": ".py",
137 | "mimetype": "text/x-python",
138 | "name": "python",
139 | "nbconvert_exporter": "python",
140 | "pygments_lexer": "ipython3",
141 | "version": "3.8.5"
142 | },
143 | "toc": {
144 | "base_numbering": 1,
145 | "nav_menu": {},
146 | "number_sections": true,
147 | "sideBar": true,
148 | "skip_h1_title": true,
149 | "title_cell": "Table of Contents",
150 | "title_sidebar": "Table of Contents",
151 | "toc_cell": false,
152 | "toc_position": {
153 | "height": "calc(100% - 180px)",
154 | "left": "10px",
155 | "top": "150px",
156 | "width": "318px"
157 | },
158 | "toc_section_display": true,
159 | "toc_window_display": true
160 | },
161 | "varInspector": {
162 | "cols": {
163 | "lenName": 16,
164 | "lenType": 16,
165 | "lenVar": 40
166 | },
167 | "kernels_config": {
168 | "python": {
169 | "delete_cmd_postfix": "",
170 | "delete_cmd_prefix": "del ",
171 | "library": "var_list.py",
172 | "varRefreshCmd": "print(var_dic_list())"
173 | },
174 | "r": {
175 | "delete_cmd_postfix": ") ",
176 | "delete_cmd_prefix": "rm(",
177 | "library": "var_list.r",
178 | "varRefreshCmd": "cat(var_dic_list()) "
179 | }
180 | },
181 | "types_to_exclude": [
182 | "module",
183 | "function",
184 | "builtin_function_or_method",
185 | "instance",
186 | "_Feature"
187 | ],
188 | "window_display": false
189 | }
190 | },
191 | "nbformat": 4,
192 | "nbformat_minor": 4
193 | }
194 |
--------------------------------------------------------------------------------
/notebooks/25_load_rasters.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "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",
26 | "\n",
27 | "- `conda create -n gee python`\n",
28 | "- `conda activate gee`\n",
29 | "- `conda install mamba -c conda-forge`\n",
30 | "- `mamba install geemap xarray_leaflet -c conda-forge`"
31 | ]
32 | },
33 | {
34 | "cell_type": "markdown",
35 | "metadata": {},
36 | "source": [
37 | "Import libraries"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": null,
43 | "metadata": {},
44 | "outputs": [],
45 | "source": [
46 | "import os\n",
47 | "import geemap"
48 | ]
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {},
53 | "source": [
54 | "Specify input raster datasets"
55 | ]
56 | },
57 | {
58 | "cell_type": "code",
59 | "execution_count": null,
60 | "metadata": {},
61 | "outputs": [],
62 | "source": [
63 | "out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')\n",
64 | "\n",
65 | "if not os.path.exists(out_dir):\n",
66 | " os.makedirs(out_dir)\n",
67 | "\n",
68 | "landsat = os.path.join(out_dir, 'landsat.tif')\n",
69 | "dem = os.path.join(out_dir, 'dem.tif')"
70 | ]
71 | },
72 | {
73 | "cell_type": "markdown",
74 | "metadata": {},
75 | "source": [
76 | "Download samples raster datasets\n",
77 | "\n",
78 | "More datasets can be downloaded from https://viewer.nationalmap.gov/basic/"
79 | ]
80 | },
81 | {
82 | "cell_type": "code",
83 | "execution_count": null,
84 | "metadata": {},
85 | "outputs": [],
86 | "source": [
87 | "if not os.path.exists(landsat):\n",
88 | " landsat_url = 'https://drive.google.com/file/d/1EV38RjNxdwEozjc9m0FcO3LFgAoAX1Uw/view?usp=sharing'\n",
89 | " geemap.download_from_gdrive(landsat_url, 'landsat.tif', out_dir, unzip=False)"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {},
96 | "outputs": [],
97 | "source": [
98 | "if not os.path.exists(dem):\n",
99 | " dem_url = 'https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing'\n",
100 | " geemap.download_from_gdrive(dem_url, 'dem.tif', out_dir, unzip=False)"
101 | ]
102 | },
103 | {
104 | "cell_type": "markdown",
105 | "metadata": {},
106 | "source": [
107 | "Create an interactive map"
108 | ]
109 | },
110 | {
111 | "cell_type": "code",
112 | "execution_count": null,
113 | "metadata": {},
114 | "outputs": [],
115 | "source": [
116 | "Map = geemap.Map()"
117 | ]
118 | },
119 | {
120 | "cell_type": "markdown",
121 | "metadata": {},
122 | "source": [
123 | "Add local raster datasets to the map\n",
124 | "\n",
125 | "More colormap can be found at https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html"
126 | ]
127 | },
128 | {
129 | "cell_type": "code",
130 | "execution_count": null,
131 | "metadata": {},
132 | "outputs": [],
133 | "source": [
134 | "Map.add_raster(dem, colormap='terrain', layer_name='DEM')"
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": null,
140 | "metadata": {},
141 | "outputs": [],
142 | "source": [
143 | "Map.add_raster(landsat, bands=[5, 4, 3], layer_name='Landsat')"
144 | ]
145 | },
146 | {
147 | "cell_type": "markdown",
148 | "metadata": {},
149 | "source": [
150 | "Display the map"
151 | ]
152 | },
153 | {
154 | "cell_type": "code",
155 | "execution_count": null,
156 | "metadata": {},
157 | "outputs": [],
158 | "source": [
159 | "Map"
160 | ]
161 | }
162 | ],
163 | "metadata": {
164 | "hide_input": false,
165 | "kernelspec": {
166 | "display_name": "Python 3",
167 | "language": "python",
168 | "name": "python3"
169 | },
170 | "language_info": {
171 | "codemirror_mode": {
172 | "name": "ipython",
173 | "version": 3
174 | },
175 | "file_extension": ".py",
176 | "mimetype": "text/x-python",
177 | "name": "python",
178 | "nbconvert_exporter": "python",
179 | "pygments_lexer": "ipython3",
180 | "version": "3.8.5"
181 | },
182 | "toc": {
183 | "base_numbering": 1,
184 | "nav_menu": {},
185 | "number_sections": true,
186 | "sideBar": true,
187 | "skip_h1_title": true,
188 | "title_cell": "Table of Contents",
189 | "title_sidebar": "Table of Contents",
190 | "toc_cell": false,
191 | "toc_position": {},
192 | "toc_section_display": true,
193 | "toc_window_display": true
194 | },
195 | "varInspector": {
196 | "cols": {
197 | "lenName": 16,
198 | "lenType": 16,
199 | "lenVar": 40
200 | },
201 | "kernels_config": {
202 | "python": {
203 | "delete_cmd_postfix": "",
204 | "delete_cmd_prefix": "del ",
205 | "library": "var_list.py",
206 | "varRefreshCmd": "print(var_dic_list())"
207 | },
208 | "r": {
209 | "delete_cmd_postfix": ") ",
210 | "delete_cmd_prefix": "rm(",
211 | "library": "var_list.r",
212 | "varRefreshCmd": "cat(var_dic_list()) "
213 | }
214 | },
215 | "types_to_exclude": [
216 | "module",
217 | "function",
218 | "builtin_function_or_method",
219 | "instance",
220 | "_Feature"
221 | ],
222 | "window_display": false
223 | }
224 | },
225 | "nbformat": 4,
226 | "nbformat_minor": 4
227 | }
228 |
--------------------------------------------------------------------------------
/notebooks/26_heroku.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import ee\n",
28 | "import geemap"
29 | ]
30 | },
31 | {
32 | "cell_type": "markdown",
33 | "metadata": {},
34 | "source": [
35 | "## Earth Engine App"
36 | ]
37 | },
38 | {
39 | "cell_type": "code",
40 | "execution_count": null,
41 | "metadata": {},
42 | "outputs": [],
43 | "source": [
44 | "Map = geemap.Map(center=(40, -100), zoom=4)"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": null,
50 | "metadata": {},
51 | "outputs": [],
52 | "source": [
53 | "# Add Earth Engine dataset\n",
54 | "dem = ee.Image('USGS/SRTMGL1_003')\n",
55 | "landcover = ee.Image(\"ESA/GLOBCOVER_L4_200901_200912_V2_3\").select('landcover')\n",
56 | "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003')\n",
57 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
58 | "\n",
59 | "# Set visualization parameters.\n",
60 | "vis_params = {\n",
61 | " 'min': 0,\n",
62 | " 'max': 4000,\n",
63 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
64 | "\n",
65 | "# Add Earth Eninge layers to Map\n",
66 | "Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7')\n",
67 | "Map.addLayer(landcover, {}, 'Land cover')\n",
68 | "Map.addLayer(dem, vis_params, 'SRTM DEM', True, 1)\n",
69 | "Map.addLayer(states, {}, \"US States\")\n",
70 | "\n",
71 | "Map"
72 | ]
73 | },
74 | {
75 | "cell_type": "code",
76 | "execution_count": null,
77 | "metadata": {},
78 | "outputs": [],
79 | "source": [
80 | "print('Change layer opacity:')\n",
81 | "dem_layer = Map.layers[-2]\n",
82 | "dem_layer.interact(opacity=(0, 1, 0.1))"
83 | ]
84 | }
85 | ],
86 | "metadata": {
87 | "hide_input": false,
88 | "kernelspec": {
89 | "display_name": "Python 3",
90 | "language": "python",
91 | "name": "python3"
92 | },
93 | "language_info": {
94 | "codemirror_mode": {
95 | "name": "ipython",
96 | "version": 3
97 | },
98 | "file_extension": ".py",
99 | "mimetype": "text/x-python",
100 | "name": "python",
101 | "nbconvert_exporter": "python",
102 | "pygments_lexer": "ipython3",
103 | "version": "3.8.5"
104 | },
105 | "toc": {
106 | "base_numbering": 1,
107 | "nav_menu": {},
108 | "number_sections": true,
109 | "sideBar": true,
110 | "skip_h1_title": true,
111 | "title_cell": "Table of Contents",
112 | "title_sidebar": "Table of Contents",
113 | "toc_cell": false,
114 | "toc_position": {},
115 | "toc_section_display": true,
116 | "toc_window_display": true
117 | },
118 | "varInspector": {
119 | "cols": {
120 | "lenName": 16,
121 | "lenType": 16,
122 | "lenVar": 40
123 | },
124 | "kernels_config": {
125 | "python": {
126 | "delete_cmd_postfix": "",
127 | "delete_cmd_prefix": "del ",
128 | "library": "var_list.py",
129 | "varRefreshCmd": "print(var_dic_list())"
130 | },
131 | "r": {
132 | "delete_cmd_postfix": ") ",
133 | "delete_cmd_prefix": "rm(",
134 | "library": "var_list.r",
135 | "varRefreshCmd": "cat(var_dic_list()) "
136 | }
137 | },
138 | "types_to_exclude": [
139 | "module",
140 | "function",
141 | "builtin_function_or_method",
142 | "instance",
143 | "_Feature"
144 | ],
145 | "window_display": false
146 | }
147 | },
148 | "nbformat": 4,
149 | "nbformat_minor": 4
150 | }
151 |
--------------------------------------------------------------------------------
/notebooks/35_geemap_colab.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "3YfuzRi6yXzE"
8 | },
9 | "source": [
10 | "
\n",
11 | "\n",
12 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": null,
18 | "metadata": {
19 | "colab": {},
20 | "colab_type": "code",
21 | "id": "d0wqNr5WXzLD"
22 | },
23 | "outputs": [],
24 | "source": [
25 | "# !pip install geemap"
26 | ]
27 | },
28 | {
29 | "cell_type": "markdown",
30 | "metadata": {
31 | "colab_type": "text",
32 | "id": "E1Rtqogbv11h"
33 | },
34 | "source": [
35 | "## Import geemap library\n",
36 | "\n",
37 | "The [geemap](https://github.com/giswqs/geemap) Python package has two plotting backends: [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) and [folium](https://github.com/python-visualization/folium). A key difference between folium and ipyleaflet is that ipyleaflet is built upon ipywidgets and allows bidirectional communication between the front-end and the backend enabling the use of the map to capture user input, while folium is meant for displaying static data only ([source](https://blog.jupyter.org/interactive-gis-in-jupyter-with-ipyleaflet-52f9657fa7a)). Note that Google Colab currently does not support ipyleaflet ([source](https://github.com/googlecolab/colabtools/issues/60#issuecomment-596225619)). Therefore, if you are using geemap with Google Colab, geemap will automatically use the folium plotting backend."
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": null,
43 | "metadata": {
44 | "colab": {},
45 | "colab_type": "code",
46 | "id": "rA615jyCYE-z"
47 | },
48 | "outputs": [],
49 | "source": [
50 | "import ee\n",
51 | "import geemap"
52 | ]
53 | },
54 | {
55 | "cell_type": "markdown",
56 | "metadata": {
57 | "colab_type": "text",
58 | "id": "bdWLuuJIwwas"
59 | },
60 | "source": [
61 | "## Create an interactive map"
62 | ]
63 | },
64 | {
65 | "cell_type": "code",
66 | "execution_count": null,
67 | "metadata": {
68 | "colab": {},
69 | "colab_type": "code",
70 | "id": "L-CTJwEAvYB0"
71 | },
72 | "outputs": [],
73 | "source": [
74 | "Map = geemap.Map()"
75 | ]
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {
80 | "colab_type": "text",
81 | "id": "ECKnyMyvw6wa"
82 | },
83 | "source": [
84 | "## Add Earth Engine data"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": null,
90 | "metadata": {
91 | "colab": {},
92 | "colab_type": "code",
93 | "id": "1b8yWFIFvfaZ"
94 | },
95 | "outputs": [],
96 | "source": [
97 | "# Add Earth Engine dataset\n",
98 | "image = ee.Image('USGS/SRTMGL1_003')\n",
99 | "\n",
100 | "# Set visualization parameters.\n",
101 | "vis_params = {\n",
102 | " 'min': 0,\n",
103 | " 'max': 4000,\n",
104 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
105 | "\n",
106 | "# Print the elevation of Mount Everest.\n",
107 | "xy = ee.Geometry.Point([86.9250, 27.9881])\n",
108 | "elev = image.sample(xy, 30).first().get('elevation').getInfo()\n",
109 | "print('Mount Everest elevation (m):', elev)\n",
110 | "\n",
111 | "# Add Earth Engine layers to Map\n",
112 | "Map.addLayer(image, vis_params, 'DEM')\n",
113 | "Map.addLayer(xy, {'color': 'red'}, 'Mount Everest')\n",
114 | "\n",
115 | "# Center the map based on an Earth Engine object or coordinates (longitude, latitude)\n",
116 | "# Map.centerObject(xy, 4)\n",
117 | "Map.setCenter(86.9250, 27.9881, 4)"
118 | ]
119 | },
120 | {
121 | "cell_type": "markdown",
122 | "metadata": {
123 | "colab_type": "text",
124 | "id": "At6VGzwlxNGb"
125 | },
126 | "source": [
127 | "## Display the map"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "execution_count": null,
133 | "metadata": {
134 | "colab": {},
135 | "colab_type": "code",
136 | "id": "IlO11sRAYKCu"
137 | },
138 | "outputs": [],
139 | "source": [
140 | "Map.addLayerControl() \n",
141 | "Map"
142 | ]
143 | }
144 | ],
145 | "metadata": {
146 | "colab": {
147 | "authorship_tag": "ABX9TyMRdgU6/oIRBcgoHSqYrQ+N",
148 | "name": "geemap_colab.ipynb",
149 | "provenance": []
150 | },
151 | "hide_input": false,
152 | "kernelspec": {
153 | "display_name": "Python 3",
154 | "language": "python",
155 | "name": "python3"
156 | },
157 | "language_info": {
158 | "codemirror_mode": {
159 | "name": "ipython",
160 | "version": 3
161 | },
162 | "file_extension": ".py",
163 | "mimetype": "text/x-python",
164 | "name": "python",
165 | "nbconvert_exporter": "python",
166 | "pygments_lexer": "ipython3",
167 | "version": "3.8.5"
168 | },
169 | "toc": {
170 | "base_numbering": 1,
171 | "nav_menu": {},
172 | "number_sections": true,
173 | "sideBar": true,
174 | "skip_h1_title": true,
175 | "title_cell": "Table of Contents",
176 | "title_sidebar": "Table of Contents",
177 | "toc_cell": false,
178 | "toc_position": {},
179 | "toc_section_display": true,
180 | "toc_window_display": true
181 | },
182 | "varInspector": {
183 | "cols": {
184 | "lenName": 16,
185 | "lenType": 16,
186 | "lenVar": 40
187 | },
188 | "kernels_config": {
189 | "python": {
190 | "delete_cmd_postfix": "",
191 | "delete_cmd_prefix": "del ",
192 | "library": "var_list.py",
193 | "varRefreshCmd": "print(var_dic_list())"
194 | },
195 | "r": {
196 | "delete_cmd_postfix": ") ",
197 | "delete_cmd_prefix": "rm(",
198 | "library": "var_list.r",
199 | "varRefreshCmd": "cat(var_dic_list()) "
200 | }
201 | },
202 | "types_to_exclude": [
203 | "module",
204 | "function",
205 | "builtin_function_or_method",
206 | "instance",
207 | "_Feature"
208 | ],
209 | "window_display": false
210 | }
211 | },
212 | "nbformat": 4,
213 | "nbformat_minor": 4
214 | }
--------------------------------------------------------------------------------
/notebooks/43_extract_values_to_points.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import os\n",
28 | "import ee\n",
29 | "import geemap"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "Upgrade geemap to the latest version"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {},
43 | "outputs": [],
44 | "source": [
45 | "# geemap.update_package()"
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": null,
51 | "metadata": {},
52 | "outputs": [],
53 | "source": [
54 | "Map = geemap.Map()\n",
55 | "Map"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": null,
61 | "metadata": {},
62 | "outputs": [],
63 | "source": [
64 | "# Add Earth Engine dataset\n",
65 | "dem = ee.Image('USGS/SRTMGL1_003')\n",
66 | "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003')\n",
67 | "\n",
68 | "# Set visualization parameters.\n",
69 | "vis_params = {\n",
70 | " 'min': 0,\n",
71 | " 'max': 4000,\n",
72 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
73 | "\n",
74 | "# Add Earth Eninge layers to Map\n",
75 | "Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7')\n",
76 | "Map.addLayer(dem, vis_params, 'SRTM DEM', True, 1)"
77 | ]
78 | },
79 | {
80 | "cell_type": "markdown",
81 | "metadata": {},
82 | "source": [
83 | "Download sample data"
84 | ]
85 | },
86 | {
87 | "cell_type": "code",
88 | "execution_count": null,
89 | "metadata": {},
90 | "outputs": [],
91 | "source": [
92 | "work_dir = os.path.expanduser('~/Downloads')\n",
93 | "in_shp = os.path.join(work_dir, 'us_cities.shp')\n",
94 | "if not os.path.exists(in_shp):\n",
95 | " data_url = 'https://github.com/giswqs/data/raw/main/us/us_cities.zip'\n",
96 | " geemap.download_from_url(data_url, out_dir=work_dir )"
97 | ]
98 | },
99 | {
100 | "cell_type": "code",
101 | "execution_count": null,
102 | "metadata": {},
103 | "outputs": [],
104 | "source": [
105 | "in_fc = geemap.shp_to_ee(in_shp)\n",
106 | "Map.addLayer(in_fc, {}, 'Cities')"
107 | ]
108 | },
109 | {
110 | "cell_type": "markdown",
111 | "metadata": {},
112 | "source": [
113 | "Export pixel values as a shapefile"
114 | ]
115 | },
116 | {
117 | "cell_type": "code",
118 | "execution_count": null,
119 | "metadata": {},
120 | "outputs": [],
121 | "source": [
122 | "out_shp = os.path.join(work_dir, 'dem.shp')\n",
123 | "geemap.extract_values_to_points(in_fc, dem, out_shp)"
124 | ]
125 | },
126 | {
127 | "cell_type": "markdown",
128 | "metadata": {},
129 | "source": [
130 | "Export pixel values as a csv"
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": null,
136 | "metadata": {},
137 | "outputs": [],
138 | "source": [
139 | "out_csv = os.path.join(work_dir, 'landsat.csv')\n",
140 | "geemap.extract_values_to_points(in_fc, landsat7, out_csv)"
141 | ]
142 | }
143 | ],
144 | "metadata": {
145 | "hide_input": false,
146 | "kernelspec": {
147 | "display_name": "Python 3",
148 | "language": "python",
149 | "name": "python3"
150 | },
151 | "language_info": {
152 | "codemirror_mode": {
153 | "name": "ipython",
154 | "version": 3
155 | },
156 | "file_extension": ".py",
157 | "mimetype": "text/x-python",
158 | "name": "python",
159 | "nbconvert_exporter": "python",
160 | "pygments_lexer": "ipython3",
161 | "version": "3.8.5"
162 | },
163 | "toc": {
164 | "base_numbering": 1,
165 | "nav_menu": {},
166 | "number_sections": true,
167 | "sideBar": true,
168 | "skip_h1_title": false,
169 | "title_cell": "Table of Contents",
170 | "title_sidebar": "Contents",
171 | "toc_cell": false,
172 | "toc_position": {},
173 | "toc_section_display": true,
174 | "toc_window_display": false
175 | }
176 | },
177 | "nbformat": 4,
178 | "nbformat_minor": 4
179 | }
180 |
--------------------------------------------------------------------------------
/notebooks/45_cog_mosaic.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import geemap"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {},
34 | "outputs": [],
35 | "source": [
36 | "# geemap.update_package()"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {},
43 | "outputs": [],
44 | "source": [
45 | "Map = geemap.Map(ee_initialize=False, layer_ctrl=True, toolbar_ctrl=False)\n",
46 | "Map"
47 | ]
48 | },
49 | {
50 | "cell_type": "markdown",
51 | "metadata": {},
52 | "source": [
53 | "For this demo, we will use data from https://www.maxar.com/open-data/california-colorado-fires for mapping California and Colorado fires. A List of COGs can be found [here](https://github.com/giswqs/geemap/blob/master/examples/data/cog_files.txt). "
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "execution_count": null,
59 | "metadata": {},
60 | "outputs": [],
61 | "source": [
62 | "URL = 'https://raw.githubusercontent.com/giswqs/geemap/master/examples/data/cog_files.txt'"
63 | ]
64 | },
65 | {
66 | "cell_type": "code",
67 | "execution_count": null,
68 | "metadata": {},
69 | "outputs": [],
70 | "source": [
71 | "import urllib \n",
72 | "\n",
73 | "data = urllib.request.urlopen(URL) \n",
74 | "links = []\n",
75 | "for line in data: \n",
76 | " links.append(line.decode(\"utf-8\").strip())"
77 | ]
78 | },
79 | {
80 | "cell_type": "code",
81 | "execution_count": null,
82 | "metadata": {},
83 | "outputs": [],
84 | "source": [
85 | "links = links[1:] # remove the first line that does not contain .tif"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": null,
91 | "metadata": {
92 | "scrolled": false
93 | },
94 | "outputs": [],
95 | "source": [
96 | "# links"
97 | ]
98 | },
99 | {
100 | "cell_type": "code",
101 | "execution_count": null,
102 | "metadata": {},
103 | "outputs": [],
104 | "source": [
105 | "Map.add_COG_mosaic(links, name=\"CA Fire\", show_footprints=True, verbose=True)"
106 | ]
107 | },
108 | {
109 | "cell_type": "code",
110 | "execution_count": null,
111 | "metadata": {},
112 | "outputs": [],
113 | "source": [
114 | "Map.addLayerControl()\n",
115 | "Map"
116 | ]
117 | }
118 | ],
119 | "metadata": {
120 | "hide_input": false,
121 | "kernelspec": {
122 | "display_name": "Python 3",
123 | "language": "python",
124 | "name": "python3"
125 | },
126 | "language_info": {
127 | "codemirror_mode": {
128 | "name": "ipython",
129 | "version": 3
130 | },
131 | "file_extension": ".py",
132 | "mimetype": "text/x-python",
133 | "name": "python",
134 | "nbconvert_exporter": "python",
135 | "pygments_lexer": "ipython3",
136 | "version": "3.8.5"
137 | },
138 | "toc": {
139 | "base_numbering": 1,
140 | "nav_menu": {},
141 | "number_sections": true,
142 | "sideBar": true,
143 | "skip_h1_title": false,
144 | "title_cell": "Table of Contents",
145 | "title_sidebar": "Contents",
146 | "toc_cell": false,
147 | "toc_position": {},
148 | "toc_section_display": true,
149 | "toc_window_display": false
150 | }
151 | },
152 | "nbformat": 4,
153 | "nbformat_minor": 4
154 | }
155 |
--------------------------------------------------------------------------------
/notebooks/47_image_thumbnails.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "## How to download image thumbnails from an ImageCollection"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": null,
31 | "metadata": {},
32 | "outputs": [],
33 | "source": [
34 | "import os\n",
35 | "import ee\n",
36 | "import geemap"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {},
43 | "outputs": [],
44 | "source": [
45 | "Map = geemap.Map()"
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": null,
51 | "metadata": {},
52 | "outputs": [],
53 | "source": [
54 | "roi = ee.Geometry.Point([-122.44, 37.75])\n",
55 | "collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \\\n",
56 | " .filterBounds(roi) \\\n",
57 | " .sort(\"CLOUD_COVER\") \\\n",
58 | " .limit(10)\n",
59 | "\n",
60 | "image = collection.first()"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "vis_params = {\n",
70 | " 'bands': ['B6', 'B5', 'B4'],\n",
71 | " 'min': 0,\n",
72 | " 'max': 6000,\n",
73 | " 'gamma': 1.4,\n",
74 | "};\n",
75 | "\n",
76 | "Map.addLayer(image, vis_params, \"LANDSAT 7\")\n",
77 | "Map.setCenter(-122.44, 37.75, 8)\n",
78 | "Map"
79 | ]
80 | },
81 | {
82 | "cell_type": "code",
83 | "execution_count": null,
84 | "metadata": {},
85 | "outputs": [],
86 | "source": [
87 | "out_img = os.path.expanduser(\"~/Downloads/landsat.png\")"
88 | ]
89 | },
90 | {
91 | "cell_type": "code",
92 | "execution_count": null,
93 | "metadata": {},
94 | "outputs": [],
95 | "source": [
96 | "geemap.get_image_thumbnail(image, out_img, vis_params, dimensions=500, format='png')"
97 | ]
98 | },
99 | {
100 | "cell_type": "code",
101 | "execution_count": null,
102 | "metadata": {},
103 | "outputs": [],
104 | "source": [
105 | "geemap.show_image(out_img)"
106 | ]
107 | },
108 | {
109 | "cell_type": "code",
110 | "execution_count": null,
111 | "metadata": {},
112 | "outputs": [],
113 | "source": [
114 | "out_dir = os.path.expanduser(\"~/Downloads\")"
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": null,
120 | "metadata": {},
121 | "outputs": [],
122 | "source": [
123 | "geemap.get_image_collection_thumbnails(collection, out_dir, vis_params, dimensions=500, format=\"jpg\")"
124 | ]
125 | }
126 | ],
127 | "metadata": {
128 | "anaconda-cloud": {},
129 | "hide_input": false,
130 | "kernelspec": {
131 | "display_name": "Python 3",
132 | "language": "python",
133 | "name": "python3"
134 | },
135 | "language_info": {
136 | "codemirror_mode": {
137 | "name": "ipython",
138 | "version": 3
139 | },
140 | "file_extension": ".py",
141 | "mimetype": "text/x-python",
142 | "name": "python",
143 | "nbconvert_exporter": "python",
144 | "pygments_lexer": "ipython3",
145 | "version": "3.8.5"
146 | },
147 | "toc": {
148 | "base_numbering": 1,
149 | "nav_menu": {},
150 | "number_sections": true,
151 | "sideBar": true,
152 | "skip_h1_title": false,
153 | "title_cell": "Table of Contents",
154 | "title_sidebar": "Contents",
155 | "toc_cell": false,
156 | "toc_position": {},
157 | "toc_section_display": true,
158 | "toc_window_display": false
159 | }
160 | },
161 | "nbformat": 4,
162 | "nbformat_minor": 4
163 | }
164 |
--------------------------------------------------------------------------------
/notebooks/53_layer_vis.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "# !pip install geemap"
24 | ]
25 | },
26 | {
27 | "cell_type": "markdown",
28 | "metadata": {},
29 | "source": [
30 | "# How to change layer visualization interactively with a GUI"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": null,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "import ee\n",
40 | "import geemap"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {},
47 | "outputs": [],
48 | "source": [
49 | "# geemap.update_package()"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": null,
55 | "metadata": {},
56 | "outputs": [],
57 | "source": [
58 | "Map = geemap.Map(center=(40, -100), zoom=4)\n",
59 | "\n",
60 | "# Add Earth Engine dataset\n",
61 | "dem = ee.Image('USGS/SRTMGL1_003')\n",
62 | "landcover = ee.Image(\"ESA/GLOBCOVER_L4_200901_200912_V2_3\").select('landcover')\n",
63 | "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003').select(['B1', 'B2', 'B3', 'B4', 'B5', 'B7'])\n",
64 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
65 | "\n",
66 | "# Set visualization parameters.\n",
67 | "vis_params = {\n",
68 | " 'min': 0,\n",
69 | " 'max': 4000,\n",
70 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
71 | "\n",
72 | "# Add Earth Eninge layers to Map\n",
73 | "Map.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)\n",
74 | "Map.addLayer(landcover, {}, 'Land cover')\n",
75 | "Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2}, 'Landsat 7')\n",
76 | "Map.addLayer(states, {}, \"US States\", False)\n",
77 | "\n",
78 | "Map"
79 | ]
80 | }
81 | ],
82 | "metadata": {
83 | "hide_input": false,
84 | "kernelspec": {
85 | "display_name": "Python 3",
86 | "language": "python",
87 | "name": "python3"
88 | },
89 | "language_info": {
90 | "codemirror_mode": {
91 | "name": "ipython",
92 | "version": 3
93 | },
94 | "file_extension": ".py",
95 | "mimetype": "text/x-python",
96 | "name": "python",
97 | "nbconvert_exporter": "python",
98 | "pygments_lexer": "ipython3",
99 | "version": "3.8.5"
100 | },
101 | "toc": {
102 | "base_numbering": 1,
103 | "nav_menu": {},
104 | "number_sections": true,
105 | "sideBar": true,
106 | "skip_h1_title": true,
107 | "title_cell": "Table of Contents",
108 | "title_sidebar": "Table of Contents",
109 | "toc_cell": false,
110 | "toc_position": {},
111 | "toc_section_display": true,
112 | "toc_window_display": true
113 | },
114 | "varInspector": {
115 | "cols": {
116 | "lenName": 16,
117 | "lenType": 16,
118 | "lenVar": 40
119 | },
120 | "kernels_config": {
121 | "python": {
122 | "delete_cmd_postfix": "",
123 | "delete_cmd_prefix": "del ",
124 | "library": "var_list.py",
125 | "varRefreshCmd": "print(var_dic_list())"
126 | },
127 | "r": {
128 | "delete_cmd_postfix": ") ",
129 | "delete_cmd_prefix": "rm(",
130 | "library": "var_list.r",
131 | "varRefreshCmd": "cat(var_dic_list()) "
132 | }
133 | },
134 | "types_to_exclude": [
135 | "module",
136 | "function",
137 | "builtin_function_or_method",
138 | "instance",
139 | "_Feature"
140 | ],
141 | "window_display": false
142 | }
143 | },
144 | "nbformat": 4,
145 | "nbformat_minor": 4
146 | }
147 |
--------------------------------------------------------------------------------
/notebooks/54_vector_vis.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "# !pip install geemap"
24 | ]
25 | },
26 | {
27 | "cell_type": "markdown",
28 | "metadata": {},
29 | "source": [
30 | "# How to visualize Earth Engine vector data interactively with a GUI"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": null,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "import ee\n",
40 | "import geemap"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {},
47 | "outputs": [],
48 | "source": [
49 | "# geemap.update_package()"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": null,
55 | "metadata": {
56 | "scrolled": false
57 | },
58 | "outputs": [],
59 | "source": [
60 | "Map = geemap.Map(center=(40, -100), zoom=4)\n",
61 | "\n",
62 | "# Add Earth Engine dataset\n",
63 | "dem = ee.Image('USGS/SRTMGL1_003')\n",
64 | "landcover = ee.Image(\"ESA/GLOBCOVER_L4_200901_200912_V2_3\").select('landcover')\n",
65 | "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003').select(['B1', 'B2', 'B3', 'B4', 'B5', 'B7'])\n",
66 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
67 | "cities = ee.FeatureCollection('users/giswqs/public/us-cities')\n",
68 | "\n",
69 | "# Set visualization parameters.\n",
70 | "vis_params = {\n",
71 | " 'min': 0,\n",
72 | " 'max': 4000,\n",
73 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
74 | "\n",
75 | "# Add Earth Eninge layers to Map\n",
76 | "Map.addLayer(dem, vis_params, 'SRTM DEM', True)\n",
77 | "Map.addLayer(landcover, {}, 'Land cover', False)\n",
78 | "Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200}, 'Landsat 7', False)\n",
79 | "Map.addLayer(states, {}, \"US States\", True)\n",
80 | "Map.addLayer(cities, {}, 'Cities', False)\n",
81 | "\n",
82 | "Map"
83 | ]
84 | },
85 | {
86 | "cell_type": "code",
87 | "execution_count": null,
88 | "metadata": {},
89 | "outputs": [],
90 | "source": [
91 | "Map = geemap.Map()\n",
92 | "\n",
93 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
94 | "\n",
95 | "Map.addLayer(states, {}, \"US States\")\n",
96 | "Map"
97 | ]
98 | },
99 | {
100 | "cell_type": "code",
101 | "execution_count": null,
102 | "metadata": {},
103 | "outputs": [],
104 | "source": [
105 | "vis_params = {\n",
106 | " 'color': '000000', \n",
107 | " 'colorOpacity': 1,\n",
108 | " 'pointSize': 3,\n",
109 | " 'pointShape': 'circle',\n",
110 | " 'width': 2,\n",
111 | " 'lineType': 'solid', \n",
112 | " 'fillColorOpacity': 0.66 \n",
113 | "}\n",
114 | "\n",
115 | "palette = ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']\n",
116 | "\n",
117 | "Map.add_styled_vector(states, column=\"NAME\", palette=palette, layer_name=\"Styled vector\", **vis_params)"
118 | ]
119 | }
120 | ],
121 | "metadata": {
122 | "hide_input": false,
123 | "kernelspec": {
124 | "display_name": "Python 3",
125 | "language": "python",
126 | "name": "python3"
127 | },
128 | "language_info": {
129 | "codemirror_mode": {
130 | "name": "ipython",
131 | "version": 3
132 | },
133 | "file_extension": ".py",
134 | "mimetype": "text/x-python",
135 | "name": "python",
136 | "nbconvert_exporter": "python",
137 | "pygments_lexer": "ipython3",
138 | "version": "3.8.5"
139 | },
140 | "toc": {
141 | "base_numbering": 1,
142 | "nav_menu": {},
143 | "number_sections": true,
144 | "sideBar": true,
145 | "skip_h1_title": true,
146 | "title_cell": "Table of Contents",
147 | "title_sidebar": "Table of Contents",
148 | "toc_cell": false,
149 | "toc_position": {
150 | "height": "calc(100% - 180px)",
151 | "left": "10px",
152 | "top": "150px",
153 | "width": "165px"
154 | },
155 | "toc_section_display": true,
156 | "toc_window_display": true
157 | },
158 | "varInspector": {
159 | "cols": {
160 | "lenName": 16,
161 | "lenType": 16,
162 | "lenVar": 40
163 | },
164 | "kernels_config": {
165 | "python": {
166 | "delete_cmd_postfix": "",
167 | "delete_cmd_prefix": "del ",
168 | "library": "var_list.py",
169 | "varRefreshCmd": "print(var_dic_list())"
170 | },
171 | "r": {
172 | "delete_cmd_postfix": ") ",
173 | "delete_cmd_prefix": "rm(",
174 | "library": "var_list.r",
175 | "varRefreshCmd": "cat(var_dic_list()) "
176 | }
177 | },
178 | "types_to_exclude": [
179 | "module",
180 | "function",
181 | "builtin_function_or_method",
182 | "instance",
183 | "_Feature"
184 | ],
185 | "window_display": false
186 | }
187 | },
188 | "nbformat": 4,
189 | "nbformat_minor": 4
190 | }
191 |
--------------------------------------------------------------------------------
/notebooks/55_raster_vis.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "# !pip install geemap"
24 | ]
25 | },
26 | {
27 | "cell_type": "markdown",
28 | "metadata": {},
29 | "source": [
30 | "# How to visualize Earth Engine raster data interactively with a GUI"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": null,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "import ee\n",
40 | "import geemap"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {},
47 | "outputs": [],
48 | "source": [
49 | "# geemap.update_package()"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": null,
55 | "metadata": {
56 | "scrolled": false
57 | },
58 | "outputs": [],
59 | "source": [
60 | "Map = geemap.Map(center=(40, -100), zoom=4)\n",
61 | "\n",
62 | "# Add Earth Engine dataset\n",
63 | "dem = ee.Image('USGS/SRTMGL1_003')\n",
64 | "# landcover = ee.Image(\"ESA/GLOBCOVER_L4_200901_200912_V2_3\").select('landcover')\n",
65 | "landsat7 = ee.Image('LE7_TOA_5YEAR/1999_2003').select(['B1', 'B2', 'B3', 'B4', 'B5', 'B7'])\n",
66 | "states = ee.FeatureCollection(\"TIGER/2018/States\")\n",
67 | "\n",
68 | "# Set visualization parameters.\n",
69 | "vis_params = {\n",
70 | " 'min': 0,\n",
71 | " 'max': 4000,\n",
72 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
73 | "\n",
74 | "# Add Earth Eninge layers to Map\n",
75 | "Map.addLayer(dem, vis_params, 'SRTM DEM', True, 1)\n",
76 | "# Map.addLayer(landcover, {}, 'Land cover')\n",
77 | "Map.addLayer(landsat7, {'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2}, 'Landsat 7')\n",
78 | "Map.addLayer(states, {}, \"US States\", False)\n",
79 | "\n",
80 | "Map"
81 | ]
82 | }
83 | ],
84 | "metadata": {
85 | "hide_input": false,
86 | "kernelspec": {
87 | "display_name": "Python 3",
88 | "language": "python",
89 | "name": "python3"
90 | },
91 | "language_info": {
92 | "codemirror_mode": {
93 | "name": "ipython",
94 | "version": 3
95 | },
96 | "file_extension": ".py",
97 | "mimetype": "text/x-python",
98 | "name": "python",
99 | "nbconvert_exporter": "python",
100 | "pygments_lexer": "ipython3",
101 | "version": "3.8.5"
102 | },
103 | "toc": {
104 | "base_numbering": 1,
105 | "nav_menu": {},
106 | "number_sections": true,
107 | "sideBar": true,
108 | "skip_h1_title": true,
109 | "title_cell": "Table of Contents",
110 | "title_sidebar": "Table of Contents",
111 | "toc_cell": false,
112 | "toc_position": {},
113 | "toc_section_display": true,
114 | "toc_window_display": false
115 | },
116 | "varInspector": {
117 | "cols": {
118 | "lenName": 16,
119 | "lenType": 16,
120 | "lenVar": 40
121 | },
122 | "kernels_config": {
123 | "python": {
124 | "delete_cmd_postfix": "",
125 | "delete_cmd_prefix": "del ",
126 | "library": "var_list.py",
127 | "varRefreshCmd": "print(var_dic_list())"
128 | },
129 | "r": {
130 | "delete_cmd_postfix": ") ",
131 | "delete_cmd_prefix": "rm(",
132 | "library": "var_list.r",
133 | "varRefreshCmd": "cat(var_dic_list()) "
134 | }
135 | },
136 | "types_to_exclude": [
137 | "module",
138 | "function",
139 | "builtin_function_or_method",
140 | "instance",
141 | "_Feature"
142 | ],
143 | "window_display": false
144 | }
145 | },
146 | "nbformat": 4,
147 | "nbformat_minor": 4
148 | }
149 |
--------------------------------------------------------------------------------
/notebooks/56_local_data.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {},
15 | "source": [
16 | "# How to add local vector and raster data to the map with a few clicks"
17 | ]
18 | },
19 | {
20 | "cell_type": "code",
21 | "execution_count": null,
22 | "metadata": {},
23 | "outputs": [],
24 | "source": [
25 | "# !pip install geemap"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": null,
31 | "metadata": {},
32 | "outputs": [],
33 | "source": [
34 | "import os\n",
35 | "import geemap"
36 | ]
37 | },
38 | {
39 | "cell_type": "code",
40 | "execution_count": null,
41 | "metadata": {},
42 | "outputs": [],
43 | "source": [
44 | "# geemap.update_package()"
45 | ]
46 | },
47 | {
48 | "cell_type": "markdown",
49 | "metadata": {},
50 | "source": [
51 | "## Create an interactive map"
52 | ]
53 | },
54 | {
55 | "cell_type": "code",
56 | "execution_count": null,
57 | "metadata": {},
58 | "outputs": [],
59 | "source": [
60 | "Map = geemap.Map()\n",
61 | "Map"
62 | ]
63 | },
64 | {
65 | "cell_type": "markdown",
66 | "metadata": {},
67 | "source": [
68 | "## Download sample daatasets\n",
69 | "\n",
70 | "Note that geemap only supports vector data using WGS84 (EPSG:4326)."
71 | ]
72 | },
73 | {
74 | "cell_type": "code",
75 | "execution_count": null,
76 | "metadata": {},
77 | "outputs": [],
78 | "source": [
79 | "out_dir = os.getcwd()"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": null,
85 | "metadata": {},
86 | "outputs": [],
87 | "source": [
88 | "countries_url = \"https://github.com/giswqs/data/raw/main/world/countries.zip\"\n",
89 | "us_states_url = \"https://raw.githubusercontent.com/giswqs/data/main/us/us_states.geojson\"\n",
90 | "dem_url = 'https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing'\n",
91 | "landsat_url = 'https://drive.google.com/file/d/1EV38RjNxdwEozjc9m0FcO3LFgAoAX1Uw/view?usp=sharing'"
92 | ]
93 | },
94 | {
95 | "cell_type": "code",
96 | "execution_count": null,
97 | "metadata": {},
98 | "outputs": [],
99 | "source": [
100 | "geemap.download_from_url(countries_url)"
101 | ]
102 | },
103 | {
104 | "cell_type": "code",
105 | "execution_count": null,
106 | "metadata": {},
107 | "outputs": [],
108 | "source": [
109 | "geemap.download_from_url(us_states_url)"
110 | ]
111 | },
112 | {
113 | "cell_type": "code",
114 | "execution_count": null,
115 | "metadata": {},
116 | "outputs": [],
117 | "source": [
118 | "geemap.download_from_gdrive(dem_url, 'dem.tif', unzip=False)"
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": null,
124 | "metadata": {},
125 | "outputs": [],
126 | "source": [
127 | "geemap.download_from_gdrive(landsat_url, 'landsat.tif', unzip=False)"
128 | ]
129 | },
130 | {
131 | "cell_type": "markdown",
132 | "metadata": {},
133 | "source": [
134 | "## Add data to the map using the toolbar"
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": null,
140 | "metadata": {},
141 | "outputs": [],
142 | "source": [
143 | "Map"
144 | ]
145 | }
146 | ],
147 | "metadata": {
148 | "hide_input": false,
149 | "kernelspec": {
150 | "display_name": "Python 3",
151 | "language": "python",
152 | "name": "python3"
153 | },
154 | "language_info": {
155 | "codemirror_mode": {
156 | "name": "ipython",
157 | "version": 3
158 | },
159 | "file_extension": ".py",
160 | "mimetype": "text/x-python",
161 | "name": "python",
162 | "nbconvert_exporter": "python",
163 | "pygments_lexer": "ipython3",
164 | "version": "3.8.5"
165 | },
166 | "toc": {
167 | "base_numbering": 1,
168 | "nav_menu": {},
169 | "number_sections": true,
170 | "sideBar": true,
171 | "skip_h1_title": true,
172 | "title_cell": "Table of Contents",
173 | "title_sidebar": "Table of Contents",
174 | "toc_cell": false,
175 | "toc_position": {},
176 | "toc_section_display": true,
177 | "toc_window_display": true
178 | },
179 | "varInspector": {
180 | "cols": {
181 | "lenName": 16,
182 | "lenType": 16,
183 | "lenVar": 40
184 | },
185 | "kernels_config": {
186 | "python": {
187 | "delete_cmd_postfix": "",
188 | "delete_cmd_prefix": "del ",
189 | "library": "var_list.py",
190 | "varRefreshCmd": "print(var_dic_list())"
191 | },
192 | "r": {
193 | "delete_cmd_postfix": ") ",
194 | "delete_cmd_prefix": "rm(",
195 | "library": "var_list.r",
196 | "varRefreshCmd": "cat(var_dic_list()) "
197 | }
198 | },
199 | "types_to_exclude": [
200 | "module",
201 | "function",
202 | "builtin_function_or_method",
203 | "instance",
204 | "_Feature"
205 | ],
206 | "window_display": false
207 | }
208 | },
209 | "nbformat": 4,
210 | "nbformat_minor": 4
211 | }
212 |
--------------------------------------------------------------------------------
/notebooks/58_shp_kml.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "# How to add a shapefile, GeoJSON, and KML to the map\n",
26 | "\n",
27 | "## For ipyleaflet"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {},
34 | "outputs": [],
35 | "source": [
36 | "import geemap"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {},
43 | "outputs": [],
44 | "source": [
45 | "# geemap.update_package()"
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": null,
51 | "metadata": {},
52 | "outputs": [],
53 | "source": [
54 | "Map = geemap.Map()\n",
55 | "Map"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": null,
61 | "metadata": {},
62 | "outputs": [],
63 | "source": [
64 | "in_shp = '../data/countries.shp'\n",
65 | "Map.add_shapefile(in_shp, layer_name=\"Countries\")"
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": null,
71 | "metadata": {},
72 | "outputs": [],
73 | "source": [
74 | "style = {\n",
75 | " \"stroke\": True,\n",
76 | " \"color\": \"#0000ff\",\n",
77 | " \"weight\": 2,\n",
78 | " \"opacity\": 1,\n",
79 | " \"fill\": True,\n",
80 | " \"fillColor\": \"#0000ff\",\n",
81 | " \"fillOpacity\": 0.4,\n",
82 | "}"
83 | ]
84 | },
85 | {
86 | "cell_type": "code",
87 | "execution_count": null,
88 | "metadata": {},
89 | "outputs": [],
90 | "source": [
91 | "Map.add_shapefile(in_shp, style=style, layer_name=\"Countries Styled\")"
92 | ]
93 | },
94 | {
95 | "cell_type": "code",
96 | "execution_count": null,
97 | "metadata": {},
98 | "outputs": [],
99 | "source": [
100 | "in_geojson = '../data/us-states.json'\n",
101 | "Map.add_geojson(in_geojson, style, layer_name=\"US States\")"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": null,
107 | "metadata": {},
108 | "outputs": [],
109 | "source": [
110 | "in_kml = '../data/us-states.kml'\n",
111 | "Map.add_kml(in_kml,layer_name=\"US States KML\")"
112 | ]
113 | },
114 | {
115 | "cell_type": "markdown",
116 | "metadata": {},
117 | "source": [
118 | "## For folium"
119 | ]
120 | },
121 | {
122 | "cell_type": "code",
123 | "execution_count": null,
124 | "metadata": {},
125 | "outputs": [],
126 | "source": [
127 | "import geemap.eefolium as geemap"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "execution_count": null,
133 | "metadata": {},
134 | "outputs": [],
135 | "source": [
136 | "Map = geemap.Map()"
137 | ]
138 | },
139 | {
140 | "cell_type": "code",
141 | "execution_count": null,
142 | "metadata": {},
143 | "outputs": [],
144 | "source": [
145 | "in_shp = '../data/countries.shp'\n",
146 | "in_geojson = '../data/us-states.json'\n",
147 | "in_kml = '../data/us-states.kml'"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": null,
153 | "metadata": {},
154 | "outputs": [],
155 | "source": [
156 | "Map.add_shapefile(in_shp, name=\"Shapefile\")\n",
157 | "Map.add_geojson(in_geojson, name=\"GeoJSON\")\n",
158 | "Map.add_kml(in_kml, name=\"KML\")"
159 | ]
160 | },
161 | {
162 | "cell_type": "code",
163 | "execution_count": null,
164 | "metadata": {},
165 | "outputs": [],
166 | "source": [
167 | "Map.addLayerControl()\n",
168 | "Map"
169 | ]
170 | }
171 | ],
172 | "metadata": {
173 | "hide_input": false,
174 | "kernelspec": {
175 | "display_name": "Python 3",
176 | "language": "python",
177 | "name": "python3"
178 | },
179 | "language_info": {
180 | "codemirror_mode": {
181 | "name": "ipython",
182 | "version": 3
183 | },
184 | "file_extension": ".py",
185 | "mimetype": "text/x-python",
186 | "name": "python",
187 | "nbconvert_exporter": "python",
188 | "pygments_lexer": "ipython3",
189 | "version": "3.8.5"
190 | },
191 | "toc": {
192 | "base_numbering": 1,
193 | "nav_menu": {},
194 | "number_sections": true,
195 | "sideBar": true,
196 | "skip_h1_title": true,
197 | "title_cell": "Table of Contents",
198 | "title_sidebar": "Table of Contents",
199 | "toc_cell": false,
200 | "toc_position": {},
201 | "toc_section_display": true,
202 | "toc_window_display": true
203 | },
204 | "varInspector": {
205 | "cols": {
206 | "lenName": 16,
207 | "lenType": 16,
208 | "lenVar": 40
209 | },
210 | "kernels_config": {
211 | "python": {
212 | "delete_cmd_postfix": "",
213 | "delete_cmd_prefix": "del ",
214 | "library": "var_list.py",
215 | "varRefreshCmd": "print(var_dic_list())"
216 | },
217 | "r": {
218 | "delete_cmd_postfix": ") ",
219 | "delete_cmd_prefix": "rm(",
220 | "library": "var_list.r",
221 | "varRefreshCmd": "cat(var_dic_list()) "
222 | }
223 | },
224 | "types_to_exclude": [
225 | "module",
226 | "function",
227 | "builtin_function_or_method",
228 | "instance",
229 | "_Feature"
230 | ],
231 | "window_display": false
232 | }
233 | },
234 | "nbformat": 4,
235 | "nbformat_minor": 4
236 | }
237 |
--------------------------------------------------------------------------------
/notebooks/59_whitebox.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import subprocess\n",
28 | "\n",
29 | "try:\n",
30 | " import whiteboxgui\n",
31 | "except ImportError:\n",
32 | " print('Installing whiteboxgui ...')\n",
33 | " subprocess.check_call([\"python\", '-m', 'pip', 'install', 'whiteboxgui'])"
34 | ]
35 | },
36 | {
37 | "cell_type": "code",
38 | "execution_count": null,
39 | "metadata": {},
40 | "outputs": [],
41 | "source": [
42 | "import geemap\n",
43 | "import whiteboxgui"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": null,
49 | "metadata": {},
50 | "outputs": [],
51 | "source": [
52 | "Map = geemap.Map()\n",
53 | "Map"
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "execution_count": null,
59 | "metadata": {
60 | "scrolled": false
61 | },
62 | "outputs": [],
63 | "source": [
64 | "whiteboxgui.show()"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": null,
70 | "metadata": {
71 | "scrolled": false
72 | },
73 | "outputs": [],
74 | "source": [
75 | "whiteboxgui.show(tree=True)"
76 | ]
77 | }
78 | ],
79 | "metadata": {
80 | "hide_input": false,
81 | "kernelspec": {
82 | "display_name": "Python 3",
83 | "language": "python",
84 | "name": "python3"
85 | },
86 | "language_info": {
87 | "codemirror_mode": {
88 | "name": "ipython",
89 | "version": 3
90 | },
91 | "file_extension": ".py",
92 | "mimetype": "text/x-python",
93 | "name": "python",
94 | "nbconvert_exporter": "python",
95 | "pygments_lexer": "ipython3",
96 | "version": "3.8.5"
97 | },
98 | "toc": {
99 | "base_numbering": 1,
100 | "nav_menu": {},
101 | "number_sections": true,
102 | "sideBar": true,
103 | "skip_h1_title": false,
104 | "title_cell": "Table of Contents",
105 | "title_sidebar": "Contents",
106 | "toc_cell": false,
107 | "toc_position": {},
108 | "toc_section_display": true,
109 | "toc_window_display": false
110 | },
111 | "varInspector": {
112 | "cols": {
113 | "lenName": 16,
114 | "lenType": 16,
115 | "lenVar": 40
116 | },
117 | "kernels_config": {
118 | "python": {
119 | "delete_cmd_postfix": "",
120 | "delete_cmd_prefix": "del ",
121 | "library": "var_list.py",
122 | "varRefreshCmd": "print(var_dic_list())"
123 | },
124 | "r": {
125 | "delete_cmd_postfix": ") ",
126 | "delete_cmd_prefix": "rm(",
127 | "library": "var_list.r",
128 | "varRefreshCmd": "cat(var_dic_list()) "
129 | }
130 | },
131 | "types_to_exclude": [
132 | "module",
133 | "function",
134 | "builtin_function_or_method",
135 | "instance",
136 | "_Feature"
137 | ],
138 | "window_display": false
139 | }
140 | },
141 | "nbformat": 4,
142 | "nbformat_minor": 4
143 | }
144 |
--------------------------------------------------------------------------------
/notebooks/cartoee_colab.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "id": "evv3PLpEAXA-"
7 | },
8 | "source": [
9 | "
"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {
16 | "id": "U8XgkNZjFaLk"
17 | },
18 | "outputs": [],
19 | "source": [
20 | "# only run the install once, after install then restart session and proceed\n",
21 | "\n",
22 | "# install the Proj and GEOS libraries\n",
23 | "!apt-get install libproj-dev proj-bin\n",
24 | "!apt-get install libgeos-dev\n",
25 | "\n",
26 | "# install cartopy and geemap with all of the dependencies prebuilt\n",
27 | "!pip install cartopy geemap"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {
34 | "id": "Y8k0PSDGHfYA"
35 | },
36 | "outputs": [],
37 | "source": [
38 | "# test some basic functionality\n",
39 | "import ee\n",
40 | "import geemap.eefolium as geemap\n",
41 | "from geemap import cartoee\n",
42 | "\n",
43 | "%pylab inline\n",
44 | "Map = geemap.Map()"
45 | ]
46 | },
47 | {
48 | "cell_type": "code",
49 | "execution_count": null,
50 | "metadata": {
51 | "id": "KLi3XWIJZhKa"
52 | },
53 | "outputs": [],
54 | "source": [
55 | "# get an earth engine image\n",
56 | "srtm = ee.Image(\"CGIAR/SRTM90_V4\")\n",
57 | "\n",
58 | "region = [-180,-60,180,85] # define bounding box to request data\n",
59 | "vis = {'min':0,'max':3000} # define visualization parameters for image\n",
60 | "\n",
61 | "# plot the result using cartoee\n",
62 | "ax = cartoee.get_map(srtm,region=[-180,-60,180,60],vis_params={'min':0,'max':3000})\n",
63 | "cartoee.add_gridlines(ax,interval=(60,30),linestyle=\":\")\n",
64 | "cartoee.add_colorbar(ax,vis_params={'min':0,'max':3000},loc=\"bottom\", label=\"Elevation\",orientation=\"horizontal\")\n",
65 | "\n",
66 | "# ax.coastlines() # adding coastlines are causing the errors!!!\n",
67 | "plt.show()"
68 | ]
69 | }
70 | ],
71 | "metadata": {
72 | "colab": {
73 | "collapsed_sections": [],
74 | "name": "cartoee_colab.ipynb",
75 | "provenance": [
76 | {
77 | "file_id": "13Ug6S_aQaIUEWCVU01bGZ55voy2ewRs_",
78 | "timestamp": 1605193579903
79 | },
80 | {
81 | "file_id": "1pvDOKC7QLLeOGGLBlFgZwcp6FNde1DhI",
82 | "timestamp": 1604009510469
83 | }
84 | ]
85 | },
86 | "hide_input": false,
87 | "kernelspec": {
88 | "display_name": "Python 3",
89 | "language": "python",
90 | "name": "python3"
91 | },
92 | "language_info": {
93 | "codemirror_mode": {
94 | "name": "ipython",
95 | "version": 3
96 | },
97 | "file_extension": ".py",
98 | "mimetype": "text/x-python",
99 | "name": "python",
100 | "nbconvert_exporter": "python",
101 | "pygments_lexer": "ipython3",
102 | "version": "3.8.5"
103 | },
104 | "toc": {
105 | "base_numbering": 1,
106 | "nav_menu": {},
107 | "number_sections": true,
108 | "sideBar": true,
109 | "skip_h1_title": false,
110 | "title_cell": "Table of Contents",
111 | "title_sidebar": "Contents",
112 | "toc_cell": false,
113 | "toc_position": {},
114 | "toc_section_display": true,
115 | "toc_window_display": false
116 | }
117 | },
118 | "nbformat": 4,
119 | "nbformat_minor": 1
120 | }
121 |
--------------------------------------------------------------------------------
/notebooks/cartoee_scalebar.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import ee\n",
10 | "import geemap\n",
11 | "from geemap import cartoee\n",
12 | "import cartopy.crs as ccrs\n",
13 | "import matplotlib.pyplot as plt"
14 | ]
15 | },
16 | {
17 | "cell_type": "code",
18 | "execution_count": null,
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "geemap.ee_initialize()\n",
23 | "\n",
24 | "point = ee.Geometry.Point(123.488, -8.284)\n",
25 | "\n",
26 | "volcano = ee.ImageCollection(\"COPERNICUS/S2_SR\") \\\n",
27 | " .filterBounds(point) \\\n",
28 | " .filterDate(\"2020-11-28\", \"2020-12-04\") \\\n",
29 | " .first()\n",
30 | "\n",
31 | "plt.figure(figsize=(16, 12))\n",
32 | "\n",
33 | "region = [123.3,-8.5,123.8,-8.18]\n",
34 | "vis = {'min': 0, 'max': 6000, 'bands': ['B4', 'B3', 'B2']}\n",
35 | "\n",
36 | "ax = cartoee.get_map(volcano, region=region, vis_params=vis)\n",
37 | "\n",
38 | "ax.set_title(\n",
39 | " label = 'Lewato volcano 2020-11-29',\n",
40 | " fontsize = 15\n",
41 | ")\n",
42 | "\n",
43 | "cartoee.add_gridlines(ax, interval=(0.1,0.1), linestyle=\":\")\n",
44 | "cartoee.add_scale_bar(ax, 5, xy=(0.9, 0.02), linewidth=3, color=\"white\", unit=\"km\")\n",
45 | "cartoee.add_north_arrow(ax, 'N', xy=(0.9, 0.2), arrow_length=0.1, text_color=\"white\", arrow_color=\"white\")\n",
46 | "\n",
47 | "plt.show()"
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": null,
53 | "metadata": {},
54 | "outputs": [],
55 | "source": []
56 | }
57 | ],
58 | "metadata": {
59 | "hide_input": false,
60 | "kernelspec": {
61 | "display_name": "Python 3",
62 | "language": "python",
63 | "name": "python3"
64 | },
65 | "language_info": {
66 | "codemirror_mode": {
67 | "name": "ipython",
68 | "version": 3
69 | },
70 | "file_extension": ".py",
71 | "mimetype": "text/x-python",
72 | "name": "python",
73 | "nbconvert_exporter": "python",
74 | "pygments_lexer": "ipython3",
75 | "version": "3.8.5"
76 | },
77 | "toc": {
78 | "base_numbering": 1,
79 | "nav_menu": {},
80 | "number_sections": true,
81 | "sideBar": true,
82 | "skip_h1_title": false,
83 | "title_cell": "Table of Contents",
84 | "title_sidebar": "Contents",
85 | "toc_cell": false,
86 | "toc_position": {},
87 | "toc_section_display": true,
88 | "toc_window_display": false
89 | }
90 | },
91 | "nbformat": 4,
92 | "nbformat_minor": 4
93 | }
94 |
--------------------------------------------------------------------------------
/notebooks/geemap_colab.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "colab_type": "text",
7 | "id": "3YfuzRi6yXzE"
8 | },
9 | "source": [
10 | ""
15 | ]
16 | },
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "colab_type": "text",
21 | "id": "caAZzvnSuwDi"
22 | },
23 | "source": [
24 | "## Install geemap"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": 6,
30 | "metadata": {
31 | "colab": {},
32 | "colab_type": "code",
33 | "id": "d0wqNr5WXzLD"
34 | },
35 | "outputs": [],
36 | "source": [
37 | "# !pip install geemap"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": 7,
43 | "metadata": {
44 | "colab": {},
45 | "colab_type": "code",
46 | "id": "rA615jyCYE-z"
47 | },
48 | "outputs": [],
49 | "source": [
50 | "import ee\n",
51 | "import geemap"
52 | ]
53 | },
54 | {
55 | "cell_type": "markdown",
56 | "metadata": {
57 | "colab_type": "text",
58 | "id": "bdWLuuJIwwas"
59 | },
60 | "source": [
61 | "## Create an interactive map"
62 | ]
63 | },
64 | {
65 | "cell_type": "code",
66 | "execution_count": 8,
67 | "metadata": {
68 | "colab": {},
69 | "colab_type": "code",
70 | "id": "L-CTJwEAvYB0"
71 | },
72 | "outputs": [],
73 | "source": [
74 | "Map = geemap.Map()\n",
75 | "# Map"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "metadata": {
81 | "colab_type": "text",
82 | "id": "ECKnyMyvw6wa"
83 | },
84 | "source": [
85 | "## Add Earth Engine data"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": 9,
91 | "metadata": {
92 | "colab": {},
93 | "colab_type": "code",
94 | "id": "1b8yWFIFvfaZ"
95 | },
96 | "outputs": [
97 | {
98 | "name": "stdout",
99 | "output_type": "stream",
100 | "text": [
101 | "Mount Everest elevation (m): 8729\n"
102 | ]
103 | }
104 | ],
105 | "source": [
106 | "# Add Earth Engine dataset\n",
107 | "image = ee.Image('USGS/SRTMGL1_003')\n",
108 | "\n",
109 | "# Set visualization parameters.\n",
110 | "vis_params = {\n",
111 | " 'min': 0,\n",
112 | " 'max': 4000,\n",
113 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
114 | "\n",
115 | "# Print the elevation of Mount Everest.\n",
116 | "xy = ee.Geometry.Point([86.9250, 27.9881])\n",
117 | "elev = image.sample(xy, 30).first().get('elevation').getInfo()\n",
118 | "print('Mount Everest elevation (m):', elev)\n",
119 | "\n",
120 | "# Add Earth Engine layers to Map\n",
121 | "Map.addLayer(image, vis_params, 'DEM')\n",
122 | "Map.addLayer(xy, {'color': 'red'}, 'Mount Everest')\n",
123 | "\n",
124 | "# Center the map based on an Earth Engine object or coordinates (longitude, latitude)\n",
125 | "# Map.centerObject(xy, 4)\n",
126 | "Map.setCenter(86.9250, 27.9881, 4)"
127 | ]
128 | },
129 | {
130 | "cell_type": "markdown",
131 | "metadata": {
132 | "colab_type": "text",
133 | "id": "At6VGzwlxNGb"
134 | },
135 | "source": [
136 | "## Display the map"
137 | ]
138 | },
139 | {
140 | "cell_type": "code",
141 | "execution_count": 10,
142 | "metadata": {
143 | "colab": {},
144 | "colab_type": "code",
145 | "id": "IlO11sRAYKCu"
146 | },
147 | "outputs": [
148 | {
149 | "data": {
150 | "application/vnd.jupyter.widget-view+json": {
151 | "model_id": "96d752e00aa04af68221f68e6f792ac3",
152 | "version_major": 2,
153 | "version_minor": 0
154 | },
155 | "text/plain": [
156 | "Map(center=[27.9881, 86.925], controls=(WidgetControl(options=['position'], widget=HBox(children=(ToggleButton…"
157 | ]
158 | },
159 | "metadata": {},
160 | "output_type": "display_data"
161 | }
162 | ],
163 | "source": [
164 | "Map.addLayerControl() \n",
165 | "Map"
166 | ]
167 | }
168 | ],
169 | "metadata": {
170 | "colab": {
171 | "authorship_tag": "ABX9TyMRdgU6/oIRBcgoHSqYrQ+N",
172 | "name": "geemap_colab.ipynb",
173 | "provenance": []
174 | },
175 | "kernelspec": {
176 | "display_name": "Python 3",
177 | "language": "python",
178 | "name": "python3"
179 | },
180 | "language_info": {
181 | "codemirror_mode": {
182 | "name": "ipython",
183 | "version": 3
184 | },
185 | "file_extension": ".py",
186 | "mimetype": "text/x-python",
187 | "name": "python",
188 | "nbconvert_exporter": "python",
189 | "pygments_lexer": "ipython3",
190 | "version": "3.8.5"
191 | }
192 | },
193 | "nbformat": 4,
194 | "nbformat_minor": 4
195 | }
196 |
--------------------------------------------------------------------------------
/notebooks/geopandas.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import os\n",
28 | "import geemap\n",
29 | "import pandas as pd\n",
30 | "import geopandas as gpd"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": null,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "# geemap.update_package()"
40 | ]
41 | },
42 | {
43 | "cell_type": "markdown",
44 | "metadata": {},
45 | "source": [
46 | "## Create an interactive map"
47 | ]
48 | },
49 | {
50 | "cell_type": "code",
51 | "execution_count": null,
52 | "metadata": {},
53 | "outputs": [],
54 | "source": [
55 | "Map = geemap.Map()\n",
56 | "Map"
57 | ]
58 | },
59 | {
60 | "cell_type": "markdown",
61 | "metadata": {},
62 | "source": [
63 | "## Convert ee.FeatureCollection to Pandas DataFrame"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "countries_shp = '../data/countries.shp'\n",
73 | "countries = geemap.shp_to_ee(countries_shp)\n",
74 | "Map.addLayer(countries, {}, 'Countries')"
75 | ]
76 | },
77 | {
78 | "cell_type": "code",
79 | "execution_count": null,
80 | "metadata": {},
81 | "outputs": [],
82 | "source": [
83 | "df = geemap.ee_to_pandas(countries, selectors=['id', 'name'])\n",
84 | "df.head()"
85 | ]
86 | },
87 | {
88 | "cell_type": "markdown",
89 | "metadata": {},
90 | "source": [
91 | "## Convert ee.FeatureCollection to GeoPandas GeoDataFrame"
92 | ]
93 | },
94 | {
95 | "cell_type": "code",
96 | "execution_count": null,
97 | "metadata": {},
98 | "outputs": [],
99 | "source": [
100 | "gdf = geemap.ee_to_geopandas(countries, selectors=['id', 'name'])\n",
101 | "gdf.head()"
102 | ]
103 | },
104 | {
105 | "cell_type": "markdown",
106 | "metadata": {},
107 | "source": [
108 | "## Convert Pandas DataFrame to ee.FeatureCollection"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": null,
114 | "metadata": {},
115 | "outputs": [],
116 | "source": [
117 | "in_csv = 'https://raw.githubusercontent.com/giswqs/data/main/world/world_cities.csv'"
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "execution_count": null,
123 | "metadata": {},
124 | "outputs": [],
125 | "source": [
126 | "df = pd.read_csv(in_csv)\n",
127 | "df.head()"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "execution_count": null,
133 | "metadata": {},
134 | "outputs": [],
135 | "source": [
136 | "fc = geemap.pandas_to_ee(df, latitude=\"latitude\", longitude=\"longitude\")"
137 | ]
138 | },
139 | {
140 | "cell_type": "code",
141 | "execution_count": null,
142 | "metadata": {},
143 | "outputs": [],
144 | "source": [
145 | "Map.addLayer(fc, {}, \"pandas to ee\")\n",
146 | "Map"
147 | ]
148 | },
149 | {
150 | "cell_type": "markdown",
151 | "metadata": {},
152 | "source": [
153 | "## Convert GeoPandas GeoDataFrame to ee.FeatureCollection"
154 | ]
155 | },
156 | {
157 | "cell_type": "code",
158 | "execution_count": null,
159 | "metadata": {},
160 | "outputs": [],
161 | "source": [
162 | "gdf = gpd.read_file(\"https://raw.githubusercontent.com/giswqs/data/main/us/us_states.geojson\")\n",
163 | "gdf.head()"
164 | ]
165 | },
166 | {
167 | "cell_type": "code",
168 | "execution_count": null,
169 | "metadata": {},
170 | "outputs": [],
171 | "source": [
172 | "fc = geemap.geopandas_to_ee(gdf)"
173 | ]
174 | },
175 | {
176 | "cell_type": "code",
177 | "execution_count": null,
178 | "metadata": {},
179 | "outputs": [],
180 | "source": [
181 | "Map.addLayer(fc, {}, \"geopandas to ee\")\n",
182 | "Map"
183 | ]
184 | }
185 | ],
186 | "metadata": {
187 | "hide_input": false,
188 | "kernelspec": {
189 | "display_name": "Python 3",
190 | "language": "python",
191 | "name": "python3"
192 | },
193 | "language_info": {
194 | "codemirror_mode": {
195 | "name": "ipython",
196 | "version": 3
197 | },
198 | "file_extension": ".py",
199 | "mimetype": "text/x-python",
200 | "name": "python",
201 | "nbconvert_exporter": "python",
202 | "pygments_lexer": "ipython3",
203 | "version": "3.8.5"
204 | },
205 | "toc": {
206 | "base_numbering": 1,
207 | "nav_menu": {},
208 | "number_sections": true,
209 | "sideBar": true,
210 | "skip_h1_title": true,
211 | "title_cell": "Table of Contents",
212 | "title_sidebar": "Table of Contents",
213 | "toc_cell": false,
214 | "toc_position": {},
215 | "toc_section_display": true,
216 | "toc_window_display": true
217 | },
218 | "varInspector": {
219 | "cols": {
220 | "lenName": 16,
221 | "lenType": 16,
222 | "lenVar": 40
223 | },
224 | "kernels_config": {
225 | "python": {
226 | "delete_cmd_postfix": "",
227 | "delete_cmd_prefix": "del ",
228 | "library": "var_list.py",
229 | "varRefreshCmd": "print(var_dic_list())"
230 | },
231 | "r": {
232 | "delete_cmd_postfix": ") ",
233 | "delete_cmd_prefix": "rm(",
234 | "library": "var_list.r",
235 | "varRefreshCmd": "cat(var_dic_list()) "
236 | }
237 | },
238 | "types_to_exclude": [
239 | "module",
240 | "function",
241 | "builtin_function_or_method",
242 | "instance",
243 | "_Feature"
244 | ],
245 | "window_display": false
246 | }
247 | },
248 | "nbformat": 4,
249 | "nbformat_minor": 4
250 | }
251 |
--------------------------------------------------------------------------------
/notebooks/image_overlay.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import ee\n",
28 | "import geemap\n",
29 | "from ipyleaflet import ImageOverlay"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": null,
35 | "metadata": {},
36 | "outputs": [],
37 | "source": [
38 | "Map = geemap.Map()\n",
39 | "Map"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "collection = ee.ImageCollection(\"USGS/NLCD\")\n",
49 | "print(collection.aggregate_array('system:id').getInfo())"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": null,
55 | "metadata": {},
56 | "outputs": [],
57 | "source": [
58 | "dataset = ee.Image('USGS/NLCD/NLCD2016')\n",
59 | "landcover = ee.Image(dataset.select('landcover'))\n",
60 | "Map.addLayer(landcover, {}, 'NLCD land cover')"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "url = 'https://www.mrlc.gov/sites/default/files/NLCD_Colour_Classification_Update.jpg'\n",
70 | "bounds = [(28, -128), (35, -123)]\n",
71 | "io = ImageOverlay(url=url, bounds=bounds, name='NLCD legend')\n",
72 | "Map.add_layer(io)"
73 | ]
74 | }
75 | ],
76 | "metadata": {
77 | "kernelspec": {
78 | "display_name": "Python 3",
79 | "language": "python",
80 | "name": "python3"
81 | },
82 | "language_info": {
83 | "codemirror_mode": {
84 | "name": "ipython",
85 | "version": 3
86 | },
87 | "file_extension": ".py",
88 | "mimetype": "text/x-python",
89 | "name": "python",
90 | "nbconvert_exporter": "python",
91 | "pygments_lexer": "ipython3",
92 | "version": "3.8.5"
93 | }
94 | },
95 | "nbformat": 4,
96 | "nbformat_minor": 4
97 | }
98 |
--------------------------------------------------------------------------------
/notebooks/kml_kmz.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import geemap"
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": 2,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "Map = geemap.Map()"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 3,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "in_kmz = '../data/us-states.kmz'\n",
28 | "fc = geemap.kmz_to_ee(in_kmz)"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": 4,
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "# in_kml = '../data/us-states.kml'\n",
38 | "# fc = geemap.kml_to_ee(in_kml)"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": 5,
44 | "metadata": {},
45 | "outputs": [
46 | {
47 | "data": {
48 | "application/vnd.jupyter.widget-view+json": {
49 | "model_id": "57fca73b0f8c45f183f650d20fe9bf96",
50 | "version_major": 2,
51 | "version_minor": 0
52 | },
53 | "text/plain": [
54 | "Map(center=[40, -100], controls=(WidgetControl(options=['position', 'transparent_bg'], widget=HBox(children=(T…"
55 | ]
56 | },
57 | "metadata": {},
58 | "output_type": "display_data"
59 | }
60 | ],
61 | "source": [
62 | "Map.addLayer(fc, {}, \"KMZ\")\n",
63 | "Map"
64 | ]
65 | }
66 | ],
67 | "metadata": {
68 | "hide_input": false,
69 | "kernelspec": {
70 | "display_name": "Python 3",
71 | "language": "python",
72 | "name": "python3"
73 | },
74 | "language_info": {
75 | "codemirror_mode": {
76 | "name": "ipython",
77 | "version": 3
78 | },
79 | "file_extension": ".py",
80 | "mimetype": "text/x-python",
81 | "name": "python",
82 | "nbconvert_exporter": "python",
83 | "pygments_lexer": "ipython3",
84 | "version": "3.8.5"
85 | },
86 | "toc": {
87 | "base_numbering": 1,
88 | "nav_menu": {},
89 | "number_sections": true,
90 | "sideBar": true,
91 | "skip_h1_title": false,
92 | "title_cell": "Table of Contents",
93 | "title_sidebar": "Contents",
94 | "toc_cell": false,
95 | "toc_position": {},
96 | "toc_section_display": true,
97 | "toc_window_display": false
98 | }
99 | },
100 | "nbformat": 4,
101 | "nbformat_minor": 4
102 | }
103 |
--------------------------------------------------------------------------------
/notebooks/mouse_click_coordinates.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import ee\n",
28 | "import geemap\n",
29 | "import ipywidgets as widgets\n",
30 | "from ipyleaflet import WidgetControl"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": null,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "Map = geemap.Map()\n",
40 | "Map"
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": null,
46 | "metadata": {},
47 | "outputs": [],
48 | "source": [
49 | "# Add an output widget to the map\n",
50 | "output_widget = widgets.Output(layout={'border': '1px solid black'})\n",
51 | "output_control = WidgetControl(widget=output_widget, position='bottomright')\n",
52 | "Map.add_control(output_control)"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": null,
58 | "metadata": {},
59 | "outputs": [],
60 | "source": [
61 | "# Capture user interaction with the map\n",
62 | "def handle_interaction(**kwargs):\n",
63 | " latlon = kwargs.get('coordinates')\n",
64 | " if kwargs.get('type') == 'click':\n",
65 | " Map.default_style = {'cursor': 'wait'}\n",
66 | " # xy = ee.Geometry.Point(latlon[::-1])\n",
67 | " \n",
68 | " with output_widget:\n",
69 | " output_widget.clear_output()\n",
70 | " print(latlon) \n",
71 | " Map.default_style = {'cursor': 'pointer'}\n",
72 | "Map.on_interaction(handle_interaction)"
73 | ]
74 | }
75 | ],
76 | "metadata": {
77 | "hide_input": false,
78 | "kernelspec": {
79 | "display_name": "Python 3",
80 | "language": "python",
81 | "name": "python3"
82 | },
83 | "language_info": {
84 | "codemirror_mode": {
85 | "name": "ipython",
86 | "version": 3
87 | },
88 | "file_extension": ".py",
89 | "mimetype": "text/x-python",
90 | "name": "python",
91 | "nbconvert_exporter": "python",
92 | "pygments_lexer": "ipython3",
93 | "version": "3.8.5"
94 | },
95 | "toc": {
96 | "base_numbering": 1,
97 | "nav_menu": {},
98 | "number_sections": true,
99 | "sideBar": true,
100 | "skip_h1_title": false,
101 | "title_cell": "Table of Contents",
102 | "title_sidebar": "Contents",
103 | "toc_cell": false,
104 | "toc_position": {},
105 | "toc_section_display": true,
106 | "toc_window_display": false
107 | }
108 | },
109 | "nbformat": 4,
110 | "nbformat_minor": 4
111 | }
112 |
--------------------------------------------------------------------------------
/notebooks/netcdf.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import geemap\n",
28 | "import os\n",
29 | "import xarray as xr\n",
30 | "from ipyleaflet import Map, Velocity, TileLayer, basemaps"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": null,
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "Map = geemap.Map(center=[44.33, -130.60], zoom=3, interpolation='nearest')\n",
40 | "Map.add_layer(basemaps.CartoDB.DarkMatter)\n",
41 | "Map"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": null,
47 | "metadata": {},
48 | "outputs": [],
49 | "source": [
50 | "file_path = os.path.abspath('../data/wind-global.nc')\n",
51 | "if not os.path.exists(file_path):\n",
52 | " url = 'https://github.com/giswqs/geemap/raw/master/examples/data/wind-global.nc'\n",
53 | " import requests\n",
54 | " r = requests.get(url)\n",
55 | " wind_data = r.content\n",
56 | " with open(file_path, 'wb') as f:\n",
57 | " f.write(wind_data)"
58 | ]
59 | },
60 | {
61 | "cell_type": "code",
62 | "execution_count": null,
63 | "metadata": {},
64 | "outputs": [],
65 | "source": [
66 | "ds = xr.open_dataset(file_path)\n",
67 | "ds"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": null,
73 | "metadata": {},
74 | "outputs": [],
75 | "source": [
76 | "display_options = {\n",
77 | " 'velocityType': 'Global Wind',\n",
78 | " 'displayPosition': 'bottomleft',\n",
79 | " 'displayEmptyString': 'No wind data'\n",
80 | "}\n",
81 | "wind = Velocity(\n",
82 | " data=ds, \n",
83 | " name = 'Velocity',\n",
84 | " zonal_speed='u_wind', meridional_speed='v_wind', \n",
85 | " latitude_dimension='lat', longitude_dimension='lon', \n",
86 | " velocity_scale=0.01, max_velocity=20, \n",
87 | " display_options=display_options\n",
88 | ")\n",
89 | "Map.add_layer(wind)"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {},
96 | "outputs": [],
97 | "source": []
98 | }
99 | ],
100 | "metadata": {
101 | "kernelspec": {
102 | "display_name": "Python 3",
103 | "language": "python",
104 | "name": "python3"
105 | },
106 | "language_info": {
107 | "codemirror_mode": {
108 | "name": "ipython",
109 | "version": 3
110 | },
111 | "file_extension": ".py",
112 | "mimetype": "text/x-python",
113 | "name": "python",
114 | "nbconvert_exporter": "python",
115 | "pygments_lexer": "ipython3",
116 | "version": "3.8.5"
117 | }
118 | },
119 | "nbformat": 4,
120 | "nbformat_minor": 4
121 | }
122 |
--------------------------------------------------------------------------------
/notebooks/notebook_template.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "# Google Earth Engine Python Tutorials\n",
26 | "\n",
27 | "* GitHub: https://github.com/giswqs/geemap\n",
28 | "* Notebook examples: https://github.com/giswqs/geemap/blob/master/examples/README.md#tutorials\n",
29 | "* Video tutorials: https://www.youtube.com/playlist?list=PLAxJ4-o7ZoPccOFv1dCwvGI6TYnirRTg3\n",
30 | "\n",
31 | "\n",
32 | "**Tutorial 21 - How to export Earth Engine maps as HTML and images**"
33 | ]
34 | },
35 | {
36 | "cell_type": "markdown",
37 | "metadata": {},
38 | "source": [
39 | "## Import libraries"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "import ee\n",
49 | "import geemap"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "## Video tutorial on YouTube"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": null,
62 | "metadata": {},
63 | "outputs": [],
64 | "source": [
65 | "geemap.show_youtube('h0pz3S6Tvx0')"
66 | ]
67 | },
68 | {
69 | "cell_type": "markdown",
70 | "metadata": {},
71 | "source": [
72 | "## Update the geemap package\n",
73 | "\n",
74 | "If you run into errors with this notebook, please uncomment the line below to update the [geemap](https://github.com/giswqs/geemap#installation) package to the latest version from GitHub. \n",
75 | "Restart the Kernel (Menu -> Kernel -> Restart) to take effect."
76 | ]
77 | },
78 | {
79 | "cell_type": "code",
80 | "execution_count": null,
81 | "metadata": {},
82 | "outputs": [],
83 | "source": [
84 | "# geemap.update_package()"
85 | ]
86 | },
87 | {
88 | "cell_type": "markdown",
89 | "metadata": {},
90 | "source": [
91 | "## Create an interactive map"
92 | ]
93 | },
94 | {
95 | "cell_type": "code",
96 | "execution_count": null,
97 | "metadata": {},
98 | "outputs": [],
99 | "source": [
100 | "Map = geemap.Map()\n",
101 | "Map"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": null,
107 | "metadata": {},
108 | "outputs": [],
109 | "source": []
110 | }
111 | ],
112 | "metadata": {
113 | "kernelspec": {
114 | "display_name": "Python 3",
115 | "language": "python",
116 | "name": "python3"
117 | },
118 | "language_info": {
119 | "codemirror_mode": {
120 | "name": "ipython",
121 | "version": 3
122 | },
123 | "file_extension": ".py",
124 | "mimetype": "text/x-python",
125 | "name": "python",
126 | "nbconvert_exporter": "python",
127 | "pygments_lexer": "ipython3",
128 | "version": "3.8.5"
129 | }
130 | },
131 | "nbformat": 4,
132 | "nbformat_minor": 4
133 | }
134 |
--------------------------------------------------------------------------------
/notebooks/qgis_layer_style_file.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": 1,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 2,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import os\n",
28 | "import geemap"
29 | ]
30 | },
31 | {
32 | "cell_type": "markdown",
33 | "metadata": {},
34 | "source": [
35 | "## Create a QGIS Layer Style File for NLCD data\n",
36 | "\n"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": 3,
42 | "metadata": {},
43 | "outputs": [],
44 | "source": [
45 | "out_nlcd_qml = os.path.join(os.path.expanduser('~/Downloads'), 'nlcd_style.qml')"
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": 4,
51 | "metadata": {},
52 | "outputs": [],
53 | "source": [
54 | "geemap.create_nlcd_qml(out_nlcd_qml)"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {},
60 | "source": [
61 | "## Create a QGIS Layer Style File from an Earth Engine color table\n",
62 | "\n",
63 | "Separated by Tab"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": 5,
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "ee_class_table = \"\"\"\n",
73 | "\n",
74 | " Value\tColor\tDescription\n",
75 | " 0\t1c0dff\tWater\n",
76 | " 1\t05450a\tEvergreen needleleaf forest\n",
77 | " 2\t086a10\tEvergreen broadleaf forest\n",
78 | " 3\t54a708\tDeciduous needleleaf forest\n",
79 | " 4\t78d203\tDeciduous broadleaf forest\n",
80 | " 5\t009900\tMixed forest\n",
81 | " 6\tc6b044\tClosed shrublands\n",
82 | " 7\tdcd159\tOpen shrublands\n",
83 | " 8\tdade48\tWoody savannas\n",
84 | " 9\tfbff13\tSavannas\n",
85 | " 10\tb6ff05\tGrasslands\n",
86 | " 11\t27ff87\tPermanent wetlands\n",
87 | " 12\tc24f44\tCroplands\n",
88 | " 13\ta5a5a5\tUrban and built-up\n",
89 | " 14\tff6d4c\tCropland/natural vegetation mosaic\n",
90 | " 15\t69fff8\tSnow and ice\n",
91 | " 16\tf9ffa4\tBarren or sparsely vegetated\n",
92 | " 254\tffffff\tUnclassified\n",
93 | "\n",
94 | "\"\"\""
95 | ]
96 | },
97 | {
98 | "cell_type": "code",
99 | "execution_count": 6,
100 | "metadata": {},
101 | "outputs": [],
102 | "source": [
103 | "out_qml = os.path.join(os.path.expanduser('~/Downloads'), 'image_style.qml')"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": 7,
109 | "metadata": {},
110 | "outputs": [],
111 | "source": [
112 | "geemap.vis_to_qml(ee_class_table, out_qml)"
113 | ]
114 | }
115 | ],
116 | "metadata": {
117 | "hide_input": false,
118 | "kernelspec": {
119 | "display_name": "Python 3",
120 | "language": "python",
121 | "name": "python3"
122 | },
123 | "language_info": {
124 | "codemirror_mode": {
125 | "name": "ipython",
126 | "version": 3
127 | },
128 | "file_extension": ".py",
129 | "mimetype": "text/x-python",
130 | "name": "python",
131 | "nbconvert_exporter": "python",
132 | "pygments_lexer": "ipython3",
133 | "version": "3.8.5"
134 | },
135 | "toc": {
136 | "base_numbering": 1,
137 | "nav_menu": {},
138 | "number_sections": true,
139 | "sideBar": true,
140 | "skip_h1_title": false,
141 | "title_cell": "Table of Contents",
142 | "title_sidebar": "Contents",
143 | "toc_cell": false,
144 | "toc_position": {},
145 | "toc_section_display": true,
146 | "toc_window_display": false
147 | }
148 | },
149 | "nbformat": 4,
150 | "nbformat_minor": 4
151 | }
152 |
--------------------------------------------------------------------------------
/notebooks/select_features_old.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "# How to select features by location and attribute?"
26 | ]
27 | },
28 | {
29 | "cell_type": "markdown",
30 | "metadata": {
31 | "toc": true
32 | },
33 | "source": [
34 | "Table of Contents
\n",
35 | ""
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {},
41 | "source": [
42 | "## Create an interactive map"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "import ee\n",
52 | "import geemap"
53 | ]
54 | },
55 | {
56 | "cell_type": "markdown",
57 | "metadata": {},
58 | "source": [
59 | "## Add a FeatureCollection to the map"
60 | ]
61 | },
62 | {
63 | "cell_type": "markdown",
64 | "metadata": {},
65 | "source": [
66 | "Add a FeatureCollection from the Earth Engine Data Catalog"
67 | ]
68 | },
69 | {
70 | "cell_type": "code",
71 | "execution_count": null,
72 | "metadata": {},
73 | "outputs": [],
74 | "source": [
75 | "states = ee.FeatureCollection('TIGER/2018/States')\n",
76 | "Map.addLayer(states, {}, \"TIGER/2018/States\")"
77 | ]
78 | },
79 | {
80 | "cell_type": "markdown",
81 | "metadata": {},
82 | "source": [
83 | "Load a shapefile stored locally and convert it to ee.FeatureCollection"
84 | ]
85 | },
86 | {
87 | "cell_type": "code",
88 | "execution_count": null,
89 | "metadata": {},
90 | "outputs": [],
91 | "source": [
92 | "shp_path = '../data/us-states.shp'\n",
93 | "states_shp = geemap.shp_to_ee(shp_path)\n",
94 | "Map.addLayer(states_shp, {}, 'US States SHP')"
95 | ]
96 | },
97 | {
98 | "cell_type": "markdown",
99 | "metadata": {},
100 | "source": [
101 | "Display the vector outline only"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": null,
107 | "metadata": {},
108 | "outputs": [],
109 | "source": [
110 | "Map.addLayer(ee.Image().paint(states, 0, 2), {'palette': 'red'}, 'US States Image')"
111 | ]
112 | },
113 | {
114 | "cell_type": "markdown",
115 | "metadata": {},
116 | "source": [
117 | "## Select by attribute"
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "execution_count": null,
123 | "metadata": {},
124 | "outputs": [],
125 | "source": []
126 | },
127 | {
128 | "cell_type": "code",
129 | "execution_count": null,
130 | "metadata": {},
131 | "outputs": [],
132 | "source": [
133 | "Map = geemap.Map()\n",
134 | "Map"
135 | ]
136 | }
137 | ],
138 | "metadata": {
139 | "hide_input": false,
140 | "kernelspec": {
141 | "display_name": "Python 3",
142 | "language": "python",
143 | "name": "python3"
144 | },
145 | "language_info": {
146 | "codemirror_mode": {
147 | "name": "ipython",
148 | "version": 3
149 | },
150 | "file_extension": ".py",
151 | "mimetype": "text/x-python",
152 | "name": "python",
153 | "nbconvert_exporter": "python",
154 | "pygments_lexer": "ipython3",
155 | "version": "3.8.5"
156 | },
157 | "toc": {
158 | "base_numbering": 1,
159 | "nav_menu": {},
160 | "number_sections": true,
161 | "sideBar": true,
162 | "skip_h1_title": true,
163 | "title_cell": "Table of Contents",
164 | "title_sidebar": "Table of Contents",
165 | "toc_cell": true,
166 | "toc_position": {},
167 | "toc_section_display": true,
168 | "toc_window_display": true
169 | },
170 | "varInspector": {
171 | "cols": {
172 | "lenName": 16,
173 | "lenType": 16,
174 | "lenVar": 40
175 | },
176 | "kernels_config": {
177 | "python": {
178 | "delete_cmd_postfix": "",
179 | "delete_cmd_prefix": "del ",
180 | "library": "var_list.py",
181 | "varRefreshCmd": "print(var_dic_list())"
182 | },
183 | "r": {
184 | "delete_cmd_postfix": ") ",
185 | "delete_cmd_prefix": "rm(",
186 | "library": "var_list.r",
187 | "varRefreshCmd": "cat(var_dic_list()) "
188 | }
189 | },
190 | "types_to_exclude": [
191 | "module",
192 | "function",
193 | "builtin_function_or_method",
194 | "instance",
195 | "_Feature"
196 | ],
197 | "window_display": false
198 | }
199 | },
200 | "nbformat": 4,
201 | "nbformat_minor": 4
202 | }
203 |
--------------------------------------------------------------------------------
/notebooks/template.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import ee\n",
28 | "import geemap"
29 | ]
30 | },
31 | {
32 | "cell_type": "markdown",
33 | "metadata": {},
34 | "source": [
35 | "## Create an interactive map \n",
36 | "The default basemap is `Google Maps`. Additional basemaps can be added using the `Map.add_basemap()` function. "
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {},
43 | "outputs": [],
44 | "source": [
45 | "Map = geemap.Map(center=[40,-100], zoom=4)\n",
46 | "Map.add_basemap('HYBRID') # Add Google Satellite\n",
47 | "Map"
48 | ]
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {},
53 | "source": [
54 | "## Add Earth Engine Python script "
55 | ]
56 | },
57 | {
58 | "cell_type": "code",
59 | "execution_count": null,
60 | "metadata": {},
61 | "outputs": [],
62 | "source": [
63 | "# Add Earth Engine dataset\n",
64 | "image = ee.Image('USGS/SRTMGL1_003')\n",
65 | "\n",
66 | "# Set visualization parameters.\n",
67 | "vis_params = {\n",
68 | " 'min': 0,\n",
69 | " 'max': 4000,\n",
70 | " 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}\n",
71 | "\n",
72 | "# Print the elevation of Mount Everest.\n",
73 | "xy = ee.Geometry.Point([86.9250, 27.9881])\n",
74 | "elev = image.sample(xy, 30).first().get('elevation').getInfo()\n",
75 | "print('Mount Everest elevation (m):', elev)\n",
76 | "\n",
77 | "# Add Earth Engine layers to Map\n",
78 | "Map.addLayer(image, vis_params, 'DEM')\n",
79 | "Map.addLayer(xy, {'color': 'red'}, 'Mount Everest')\n",
80 | "\n",
81 | "# Center the map based on an Earth Engine object or coordinates (longitude, latitude)\n",
82 | "# Map.centerObject(xy, 4)\n",
83 | "Map.setCenter(86.9250, 27.9881, 4)"
84 | ]
85 | },
86 | {
87 | "cell_type": "markdown",
88 | "metadata": {},
89 | "source": [
90 | "## Display Earth Engine data layers "
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "execution_count": null,
96 | "metadata": {},
97 | "outputs": [],
98 | "source": [
99 | "Map.addLayerControl() # This line is not needed for ipyleaflet-based Map.\n",
100 | "Map"
101 | ]
102 | },
103 | {
104 | "cell_type": "code",
105 | "execution_count": null,
106 | "metadata": {},
107 | "outputs": [],
108 | "source": []
109 | }
110 | ],
111 | "metadata": {
112 | "anaconda-cloud": {},
113 | "kernelspec": {
114 | "display_name": "Python 3",
115 | "language": "python",
116 | "name": "python3"
117 | },
118 | "language_info": {
119 | "codemirror_mode": {
120 | "name": "ipython",
121 | "version": 3
122 | },
123 | "file_extension": ".py",
124 | "mimetype": "text/x-python",
125 | "name": "python",
126 | "nbconvert_exporter": "python",
127 | "pygments_lexer": "ipython3",
128 | "version": "3.8.5"
129 | }
130 | },
131 | "nbformat": 4,
132 | "nbformat_minor": 4
133 | }
134 |
--------------------------------------------------------------------------------
/notebooks/usda_naip_imagery.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 1,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "# Installs geemap package\n",
28 | "import subprocess\n",
29 | "\n",
30 | "try:\n",
31 | " import geemap\n",
32 | "except ImportError:\n",
33 | " print('geemap package not installed. Installing ...')\n",
34 | " subprocess.check_call([\"python\", '-m', 'pip', 'install', 'geemap'])"
35 | ]
36 | },
37 | {
38 | "cell_type": "code",
39 | "execution_count": null,
40 | "metadata": {},
41 | "outputs": [],
42 | "source": [
43 | "import ee"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": 2,
49 | "metadata": {},
50 | "outputs": [
51 | {
52 | "data": {
53 | "application/vnd.jupyter.widget-view+json": {
54 | "model_id": "d27b9ed18bd64922ba5c208e64654329",
55 | "version_major": 2,
56 | "version_minor": 0
57 | },
58 | "text/plain": [
59 | "Map(center=[47.01, -99.0], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_o…"
60 | ]
61 | },
62 | "metadata": {},
63 | "output_type": "display_data"
64 | }
65 | ],
66 | "source": [
67 | "import geemap\n",
68 | "from ipyleaflet import *\n",
69 | "from ipywidgets import *\n",
70 | "from geemap.utils import *\n",
71 | "\n",
72 | "Map = geemap.Map(center=(-100, 40), zoom=4)\n",
73 | "Map.default_style = {'cursor': 'pointer'}\n",
74 | "Map\n",
75 | "\n",
76 | "Map.setOptions('ROADMAP')\n",
77 | "# Load National Hydrography Dataset (NHD) \n",
78 | "HUC10 = ee.FeatureCollection('USGS/WBD/2017/HUC10'); # 18,487 HUC10 watersheds in the U.S.\n",
79 | "\n",
80 | "# Add HUC layer to the map\n",
81 | "Map.setCenter(-99.00, 47.01, 8);\n",
82 | "Map.addLayer(ee.Image().paint(HUC10, 0, 1), {}, 'HUC-10 Watershed') # HUC10 for the entire U.S.\n",
83 | "\n",
84 | "label = Label(\"Click on the map to select a watershed\")\n",
85 | "widget_control = WidgetControl(widget=label, position='bottomright')\n",
86 | "Map.add_control(widget_control)\n",
87 | "\n",
88 | "layer = None\n",
89 | "\n",
90 | "def handle_interaction(**kwargs):\n",
91 | " latlon = kwargs.get('coordinates')\n",
92 | " if kwargs.get('type') == 'click':\n",
93 | " Map.default_style = {'cursor': 'wait'}\n",
94 | " xy = ee.Geometry.Point(latlon[::-1])\n",
95 | " watershed = HUC10.filterBounds(xy)\n",
96 | " huc10_id = watershed.first().get('huc10').getInfo()\n",
97 | " Map.layers = Map.layers[:3]\n",
98 | " Map.addLayer(ee.Image().paint(watershed, 0, 2), {'palette': 'red'}, 'HUC ID: ' + huc10_id) \n",
99 | " \n",
100 | " NAIP_images = find_NAIP(watershed)\n",
101 | " first_image = ee.Image(NAIP_images.toList(5).get(0))\n",
102 | " Map.addLayer(first_image, {'bands': ['N', 'R', 'G']}, 'first image')\n",
103 | " count = NAIP_images.size().getInfo()\n",
104 | " for i in range(0, count):\n",
105 | " image = ee.Image(NAIP_images.toList(count).get(i))\n",
106 | " Map.addLayer(image, {'bands': ['N', 'R', 'G']}, str(i))\n",
107 | " \n",
108 | " Map.default_style = {'cursor': 'pointer'}\n",
109 | "\n",
110 | "Map.on_interaction(handle_interaction)\n",
111 | "\n",
112 | "Map"
113 | ]
114 | },
115 | {
116 | "cell_type": "code",
117 | "execution_count": null,
118 | "metadata": {},
119 | "outputs": [],
120 | "source": [
121 | "Map.layers"
122 | ]
123 | }
124 | ],
125 | "metadata": {
126 | "kernelspec": {
127 | "display_name": "Python 3",
128 | "language": "python",
129 | "name": "python3"
130 | },
131 | "language_info": {
132 | "codemirror_mode": {
133 | "name": "ipython",
134 | "version": 3
135 | },
136 | "file_extension": ".py",
137 | "mimetype": "text/x-python",
138 | "name": "python",
139 | "nbconvert_exporter": "python",
140 | "pygments_lexer": "ipython3",
141 | "version": "3.8.5"
142 | },
143 | "toc": {
144 | "base_numbering": 1,
145 | "nav_menu": {},
146 | "number_sections": true,
147 | "sideBar": true,
148 | "skip_h1_title": true,
149 | "title_cell": "Table of Contents",
150 | "title_sidebar": "Table of Contents",
151 | "toc_cell": false,
152 | "toc_position": {},
153 | "toc_section_display": true,
154 | "toc_window_display": true
155 | }
156 | },
157 | "nbformat": 4,
158 | "nbformat_minor": 4
159 | }
160 |
--------------------------------------------------------------------------------
/notebooks/velocity.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "You will need to install the following packages:\n",
8 | "- `ipyleaflet`\n",
9 | "- `requests`\n",
10 | "- `xarray`\n",
11 | "- `netcdf4`\n",
12 | "- `geemap`"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": null,
18 | "metadata": {},
19 | "outputs": [],
20 | "source": [
21 | "from ipyleaflet import TileLayer, basemaps\n",
22 | "from ipyleaflet.velocity import Velocity\n",
23 | "import xarray as xr\n",
24 | "import geemap"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": null,
30 | "metadata": {},
31 | "outputs": [],
32 | "source": [
33 | "center = [44.33956524809713, -130.60546875000003]\n",
34 | "zoom = 3\n",
35 | "m = geemap.Map(center=center, zoom=zoom, interpolation='nearest', basemap=basemaps.CartoDB.DarkMatter, add_google_map=False, ee_initialize=False)\n",
36 | "m"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {},
43 | "outputs": [],
44 | "source": [
45 | "import os\n",
46 | "\n",
47 | "if not os.path.exists('wind-global.nc'):\n",
48 | " url = 'https://github.com/benbovy/xvelmap/raw/master/notebooks/wind-global.nc'\n",
49 | " import requests\n",
50 | " r = requests.get(url)\n",
51 | " wind_data = r.content\n",
52 | " with open('wind-global.nc', 'wb') as f:\n",
53 | " f.write(wind_data)"
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "execution_count": null,
59 | "metadata": {},
60 | "outputs": [],
61 | "source": [
62 | "ds = xr.open_dataset('wind-global.nc')\n",
63 | "ds"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": null,
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "display_options = {\n",
73 | " 'velocityType': 'Global Wind',\n",
74 | " 'displayPosition': 'bottomleft',\n",
75 | " 'displayEmptyString': 'No wind data'\n",
76 | "}\n",
77 | "wind = Velocity(\n",
78 | " data=ds, \n",
79 | " zonal_speed='u_wind', meridional_speed='v_wind', \n",
80 | " latitude_dimension='lat', longitude_dimension='lon', \n",
81 | " velocity_scale=0.01, max_velocity=20, \n",
82 | " display_options=display_options\n",
83 | ")\n",
84 | "m.add_layer(wind)"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": null,
90 | "metadata": {},
91 | "outputs": [],
92 | "source": []
93 | }
94 | ],
95 | "metadata": {
96 | "_draft": {
97 | "nbviewer_url": "https://gist.github.com/6342666b7b629ed0a86b79eb919a0d0c"
98 | },
99 | "gist": {
100 | "data": {
101 | "description": "Velocity",
102 | "public": true
103 | },
104 | "id": "6342666b7b629ed0a86b79eb919a0d0c"
105 | },
106 | "hide_input": false,
107 | "kernelspec": {
108 | "display_name": "Python 3",
109 | "language": "python",
110 | "name": "python3"
111 | },
112 | "language_info": {
113 | "codemirror_mode": {
114 | "name": "ipython",
115 | "version": 3
116 | },
117 | "file_extension": ".py",
118 | "mimetype": "text/x-python",
119 | "name": "python",
120 | "nbconvert_exporter": "python",
121 | "pygments_lexer": "ipython3",
122 | "version": "3.8.5"
123 | },
124 | "toc": {
125 | "base_numbering": 1,
126 | "nav_menu": {},
127 | "number_sections": true,
128 | "sideBar": true,
129 | "skip_h1_title": false,
130 | "title_cell": "Table of Contents",
131 | "title_sidebar": "Contents",
132 | "toc_cell": false,
133 | "toc_position": {},
134 | "toc_section_display": true,
135 | "toc_window_display": false
136 | }
137 | },
138 | "nbformat": 4,
139 | "nbformat_minor": 2
140 | }
141 |
--------------------------------------------------------------------------------
/notebooks/video_overlay.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import geemap\n",
28 | "from ipyleaflet import VideoOverlay"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": null,
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "Map = geemap.Map(center=[25, -130], zoom=4)\n",
38 | "Map"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "bounds = [(13, -130), (32, -100)]\n",
48 | "io = VideoOverlay(url='https://www.mapbox.com/bites/00188/patricia_nasa.webm', bounds=bounds, name='Video')\n",
49 | "Map.add_layer(io)\n",
50 | "io.interact(opacity=(0.0,1.0,0.01))"
51 | ]
52 | }
53 | ],
54 | "metadata": {
55 | "kernelspec": {
56 | "display_name": "Python 3",
57 | "language": "python",
58 | "name": "python3"
59 | },
60 | "language_info": {
61 | "codemirror_mode": {
62 | "name": "ipython",
63 | "version": 3
64 | },
65 | "file_extension": ".py",
66 | "mimetype": "text/x-python",
67 | "name": "python",
68 | "nbconvert_exporter": "python",
69 | "pygments_lexer": "ipython3",
70 | "version": "3.8.5"
71 | }
72 | },
73 | "nbformat": 4,
74 | "nbformat_minor": 4
75 | }
76 |
--------------------------------------------------------------------------------
/notebooks/xy_to_points.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "\n",
9 | "Uncomment the following line to install [geemap](https://geemap.org) if needed."
10 | ]
11 | },
12 | {
13 | "cell_type": "code",
14 | "execution_count": null,
15 | "metadata": {},
16 | "outputs": [],
17 | "source": [
18 | "# !pip install geemap"
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": null,
24 | "metadata": {},
25 | "outputs": [],
26 | "source": [
27 | "import os\n",
28 | "import geemap"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": null,
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "## update geemap to the latest version\n",
38 | "# geemap.update_package()"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "Map = geemap.Map()"
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": null,
53 | "metadata": {},
54 | "outputs": [],
55 | "source": [
56 | "in_csv = 'https://raw.githubusercontent.com/giswqs/data/main/world/world_cities.csv'"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": null,
62 | "metadata": {},
63 | "outputs": [],
64 | "source": [
65 | "points = geemap.xy_to_points(in_csv, latitude='latitude', longitude='longitude')"
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": null,
71 | "metadata": {},
72 | "outputs": [],
73 | "source": [
74 | "Map.addLayer(points, {}, 'csv to ee')\n",
75 | "Map"
76 | ]
77 | },
78 | {
79 | "cell_type": "code",
80 | "execution_count": null,
81 | "metadata": {},
82 | "outputs": [],
83 | "source": [
84 | "in_csv = 'https://raw.githubusercontent.com/giswqs/data/main/world/world_cities.csv'\n",
85 | "out_shp = os.path.expanduser('~/Downloads/world_cities.shp')"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": null,
91 | "metadata": {},
92 | "outputs": [],
93 | "source": [
94 | "geemap.csv_to_shp(in_csv, out_shp)"
95 | ]
96 | },
97 | {
98 | "cell_type": "code",
99 | "execution_count": null,
100 | "metadata": {},
101 | "outputs": [],
102 | "source": [
103 | "fc = geemap.shp_to_ee(out_shp)"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "metadata": {},
110 | "outputs": [],
111 | "source": [
112 | "Map.addLayer(fc, {}, 'shp to ee', False)"
113 | ]
114 | }
115 | ],
116 | "metadata": {
117 | "hide_input": false,
118 | "kernelspec": {
119 | "display_name": "Python 3",
120 | "language": "python",
121 | "name": "python3"
122 | },
123 | "language_info": {
124 | "codemirror_mode": {
125 | "name": "ipython",
126 | "version": 3
127 | },
128 | "file_extension": ".py",
129 | "mimetype": "text/x-python",
130 | "name": "python",
131 | "nbconvert_exporter": "python",
132 | "pygments_lexer": "ipython3",
133 | "version": "3.8.5"
134 | },
135 | "toc": {
136 | "base_numbering": 1,
137 | "nav_menu": {},
138 | "number_sections": true,
139 | "sideBar": true,
140 | "skip_h1_title": true,
141 | "title_cell": "Table of Contents",
142 | "title_sidebar": "Table of Contents",
143 | "toc_cell": false,
144 | "toc_position": {},
145 | "toc_section_display": true,
146 | "toc_window_display": true
147 | },
148 | "varInspector": {
149 | "cols": {
150 | "lenName": 16,
151 | "lenType": 16,
152 | "lenVar": 40
153 | },
154 | "kernels_config": {
155 | "python": {
156 | "delete_cmd_postfix": "",
157 | "delete_cmd_prefix": "del ",
158 | "library": "var_list.py",
159 | "varRefreshCmd": "print(var_dic_list())"
160 | },
161 | "r": {
162 | "delete_cmd_postfix": ") ",
163 | "delete_cmd_prefix": "rm(",
164 | "library": "var_list.r",
165 | "varRefreshCmd": "cat(var_dic_list()) "
166 | }
167 | },
168 | "types_to_exclude": [
169 | "module",
170 | "function",
171 | "builtin_function_or_method",
172 | "instance",
173 | "_Feature"
174 | ],
175 | "window_display": false
176 | }
177 | },
178 | "nbformat": 4,
179 | "nbformat_minor": 4
180 | }
181 |
--------------------------------------------------------------------------------
/python/earthengine_js_to_ipynb.py:
--------------------------------------------------------------------------------
1 | import os
2 | from geemap.conversion import *
3 |
4 | # Create a temporary working directory
5 | work_dir = os.path.join(os.path.expanduser('~'), 'geemap')
6 | # Get Earth Engine JavaScript examples. There are five examples in the geemap package folder.
7 | # Change js_dir to your own folder containing your Earth Engine JavaScripts, such as js_dir = '/path/to/your/js/folder'
8 | js_dir = get_js_examples(out_dir=work_dir)
9 |
10 | # Convert all Earth Engine JavaScripts in a folder recursively to Python scripts.
11 | js_to_python_dir(in_dir=js_dir, out_dir=js_dir, use_qgis=True)
12 | print("Python scripts saved at: {}".format(js_dir))
13 |
14 | # Convert all Earth Engine Python scripts in a folder recursively to Jupyter notebooks.
15 | nb_template = get_nb_template() # Get the notebook template from the package folder.
16 | py_to_ipynb_dir(js_dir, nb_template)
17 |
18 | # Execute all Jupyter notebooks in a folder recursively and save the output cells.
19 | execute_notebook_dir(in_dir=js_dir)
--------------------------------------------------------------------------------
/python/earthengine_py_to_ipynb.py:
--------------------------------------------------------------------------------
1 | """The example shows you how to convert all Earth Engine Python scripts in a GitHub repo to Jupyter notebooks.
2 | """
3 |
4 | import os
5 | from geemap.conversion import *
6 |
7 | import subprocess
8 |
9 | try:
10 | from git import Repo
11 | except ImportError:
12 | print('gitpython package is not installed. Installing ...')
13 | subprocess.check_call(["python", '-m', 'pip', 'install', 'gitpython'])
14 | from git import Repo
15 |
16 |
17 | git_url = 'https://github.com/giswqs/qgis-earthengine-examples'
18 | out_repo_name = 'earthengine-py-notebooks'
19 |
20 | # Create a temporary working directory
21 | work_dir = os.path.join(os.path.expanduser('~'), 'geemap')
22 | if not os.path.exists(work_dir):
23 | os.makedirs(work_dir)
24 |
25 | out_dir = os.path.join(work_dir, out_repo_name)
26 |
27 | repo_name = git_url.split('/')[-1]
28 | repo_dir = os.path.join(work_dir, repo_name)
29 |
30 | if not os.path.exists(repo_dir):
31 | Repo.clone_from(git_url, repo_dir)
32 |
33 | # # Convert all Earth Engine Python scripts in a folder recursively to Jupyter notebooks.
34 | nb_template = get_nb_template() # Get the notebook template from the package folder.
35 | py_to_ipynb_dir(repo_dir, nb_template, out_dir, github_username='giswqs', github_repo=out_repo_name)
36 |
37 | # execute_notebook_dir(out_dir)
38 |
39 |
--------------------------------------------------------------------------------
/python/geemap_and_earthengine.py:
--------------------------------------------------------------------------------
1 | import ee
2 | import geemap
3 |
4 | try:
5 | ee.Initialize()
6 | except Exception as e:
7 | ee.Authenticate()
8 | ee.Initialize()
9 |
10 | # Create an interactive map
11 | Map = geemap.Map(center=(40, -100), zoom=4)
12 | Map
13 |
14 | # Add Earth Engine dataset
15 | image = ee.Image('USGS/SRTMGL1_003')
16 |
17 | # Set visualization parameters.
18 | vis_params = {
19 | 'min': 0,
20 | 'max': 4000,
21 | 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}
22 |
23 | # Print the elevation of Mount Everest.
24 | xy = ee.Geometry.Point([86.9250, 27.9881])
25 | elev = image.sample(xy, 30).first().get('elevation').getInfo()
26 | print('Mount Everest elevation (m):', elev)
27 |
28 | # Add Earth Engine layers to Map
29 | Map.addLayer(image, vis_params, 'STRM DEM', True, 0.5)
30 | Map.addLayer(xy, {'color': 'red'}, 'Mount Everest')
31 |
32 | # Set center of the map
33 | Map.centerObject(ee_object=xy, zoom=13)
34 | Map.setCenter(lon=-100, lat=40, zoom=4)
--------------------------------------------------------------------------------
/python/javascript_to_python.py:
--------------------------------------------------------------------------------
1 | import os
2 | from geemap.conversion import *
3 |
4 | # Create a temporary working directory
5 | work_dir = os.path.join(os.path.expanduser('~'), 'geemap')
6 | # Get Earth Engine JavaScript examples. There are five examples in the geemap package folder.
7 | # Change js_dir to your own folder containing your Earth Engine JavaScripts, such as js_dir = '/path/to/your/js/folder'
8 | js_dir = get_js_examples(out_dir=work_dir)
9 |
10 | # Convert all Earth Engine JavaScripts in a folder recursively to Python scripts.
11 | js_to_python_dir(in_dir=js_dir, out_dir=js_dir, use_qgis=True)
12 | print("Python scripts saved at: {}".format(js_dir))
13 |
14 | # Convert all Earth Engine Python scripts in a folder recursively to Jupyter notebooks.
15 | nb_template = get_nb_template() # Get the notebook template from the package folder.
16 | py_to_ipynb_dir(js_dir, nb_template)
17 |
18 | # Execute all Jupyter notebooks in a folder recursively and save the output cells.
19 | execute_notebook_dir(in_dir=js_dir)
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | voila
2 | googledrivedownloader
3 | xarray_leaflet>=0.1.13
4 | # geemap
5 | # git+git://github.com/voila-dashboards/voila.git
6 | git+git://github.com/giswqs/geemap.git
7 |
--------------------------------------------------------------------------------
/runtime.txt:
--------------------------------------------------------------------------------
1 | python-3.7.7
2 |
--------------------------------------------------------------------------------
/template/template.py:
--------------------------------------------------------------------------------
1 | # %%
2 | """
3 |
8 | """
9 |
10 | # %%
11 | """
12 | ## Install Earth Engine API and geemap
13 | Install the [Earth Engine Python API](https://developers.google.com/earth-engine/python_install) and [geemap](https://github.com/giswqs/geemap). The **geemap** Python package is built upon the [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) and [folium](https://github.com/python-visualization/folium) packages and implements several methods for interacting with Earth Engine data layers, such as `Map.addLayer()`, `Map.setCenter()`, and `Map.centerObject()`.
14 | The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its [dependencies](https://github.com/giswqs/geemap#dependencies), including earthengine-api, folium, and ipyleaflet.
15 |
16 | **Important note**: A key difference between folium and ipyleaflet is that ipyleaflet is built upon ipywidgets and allows bidirectional communication between the front-end and the backend enabling the use of the map to capture user input, while folium is meant for displaying static data only ([source](https://blog.jupyter.org/interactive-gis-in-jupyter-with-ipyleaflet-52f9657fa7a)). Note that [Google Colab](https://colab.research.google.com/) currently does not support ipyleaflet ([source](https://github.com/googlecolab/colabtools/issues/60#issuecomment-596225619)). Therefore, if you are using geemap with Google Colab, you should use [`import geemap.eefolium`](https://github.com/giswqs/geemap/blob/master/geemap/eefolium.py). If you are using geemap with [binder](https://mybinder.org/) or a local Jupyter notebook server, you can use [`import geemap`](https://github.com/giswqs/geemap/blob/master/geemap/geemap.py), which provides more functionalities for capturing user input (e.g., mouse-clicking and moving).
17 | """
18 |
19 | # %%
20 | # Installs geemap package
21 | import subprocess
22 |
23 | try:
24 | import geemap
25 | except ImportError:
26 | print('geemap package not installed. Installing ...')
27 | subprocess.check_call(["python", '-m', 'pip', 'install', 'geemap'])
28 |
29 | # Checks whether this notebook is running on Google Colab
30 | try:
31 | import google.colab
32 | import geemap.eefolium as emap
33 | except:
34 | import geemap as emap
35 |
36 | # Authenticates and initializes Earth Engine
37 | import ee
38 |
39 | try:
40 | ee.Initialize()
41 | except Exception as e:
42 | ee.Authenticate()
43 | ee.Initialize()
44 |
45 | # %%
46 | """
47 | ## Create an interactive map
48 | The default basemap is `Google Satellite`. [Additional basemaps](https://github.com/giswqs/geemap/blob/master/geemap/geemap.py#L13) can be added using the `Map.add_basemap()` function.
49 | """
50 |
51 | # %%
52 | Map = emap.Map(center=[40,-100], zoom=4)
53 | Map.add_basemap('ROADMAP') # Add Google Map
54 | Map
55 |
56 | # %%
57 | """
58 | ## Add Earth Engine Python script
59 | """
60 |
61 | # %%
62 | # Add Earth Engine dataset
63 | image = ee.Image('USGS/SRTMGL1_003')
64 |
65 | # Set visualization parameters.
66 | vis_params = {
67 | 'min': 0,
68 | 'max': 4000,
69 | 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']}
70 |
71 | # Print the elevation of Mount Everest.
72 | xy = ee.Geometry.Point([86.9250, 27.9881])
73 | elev = image.sample(xy, 30).first().get('elevation').getInfo()
74 | print('Mount Everest elevation (m):', elev)
75 |
76 | # Add Earth Engine layers to Map
77 | Map.addLayer(image, vis_params, 'DEM')
78 | Map.addLayer(xy, {'color': 'red'}, 'Mount Everest')
79 |
80 | # Center the map based on an Earth Engine object or coordinates (longitude, latitude)
81 | # Map.centerObject(xy, 4)
82 | Map.setCenter(86.9250, 27.9881, 4)
83 |
84 | # %%
85 | """
86 | ## Display Earth Engine data layers
87 | """
88 |
89 | # %%
90 | Map.addLayerControl() # This line is not needed for ipyleaflet-based Map.
91 | Map
--------------------------------------------------------------------------------