{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\n", "\n", "**Plotting Earth Engine vector data with cartoee**\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) and [cartopy](https://scitools.org.uk/cartopy/docs/latest/installing.html#installing) if needed. Keep in mind that cartopy can be challenging to install. If you are unable to install cartopy on your computer, you can try Google Colab with this the [notebook example](https://colab.research.google.com/github/giswqs/geemap/blob/master/examples/notebooks/69_cartoee_vector.ipynb). \n", "\n", "See below the commands to install cartopy and geemap using conda/mamba:\n", "\n", "```\n", "conda create -n carto python=3.8\n", "conda activate carto\n", "conda install cartopy scipy -c conda-forge\n", "conda install geemap -c conda-forge\n", "jupyter notebook\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install cartopy scipy\n", "# !pip install geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap\n", "from geemap import cartoee\n", "from geemap.datasets import DATA\n", "import geemap.colormaps as cmap\n", "import cartopy.crs as ccrs\n", "\n", "%pylab inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot a simple vector" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "features = ee.FeatureCollection(DATA.users_giswqs_public_countries)\n", "\n", "style = {'color': '000000ff', 'width': 1, 'lineType': 'solid', 'fillColor': '0000ff40'}\n", "\n", "Map.addLayer(features.style(**style), {}, \"Polygons\")\n", "Map.setCenter(-14.77, 34.70, 2)\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# specify region to focus on\n", "bbox = [-180, -88, 180, 88]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "fig = plt.figure(figsize=(15,10))\n", "\n", "# plot the result with cartoee using a PlateCarre projection (default)\n", "ax = cartoee.get_map(features, region=bbox, style=style)\n", "ax.set_title(label = 'Countries', fontsize = 15)\n", "cartoee.add_gridlines(ax, interval=30)\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/RTFGotE.png)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(figsize=(15,10))\n", "\n", "projection = ccrs.EqualEarth(central_longitude=-180)\n", "ax = cartoee.get_map(features, region=bbox, proj=projection, style=style)\n", "ax.set_title(label = 'Countries', fontsize = 15)\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/GagRINK.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot a styled vector" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "features = ee.FeatureCollection(DATA.users_giswqs_public_countries)\n", "\n", "palette = cmap.palettes.gist_earth\n", "features_styled = geemap.vector_styling(features, column=\"name\", palette=palette)\n", "\n", "Map.add_styled_vector(features, column=\"name\", palette=palette, layer_name='Polygon')\n", "Map.setCenter(-14.77, 34.70, 2)\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "bbox = [-180, -88, 180, 88]\n", "fig = plt.figure(figsize=(15,10))\n", "\n", "ax = cartoee.get_map(features_styled, region=bbox)\n", "ax.set_title(label = 'Countries', fontsize = 15)\n", "cartoee.add_gridlines(ax, interval=30)\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/reecFZo.png)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(figsize=(15,10))\n", "\n", "projection = ccrs.EqualEarth(central_longitude=-180)\n", "ax = cartoee.get_map(features_styled, region=bbox, proj=projection)\n", "ax.set_title(label = 'Countries', fontsize = 15)\n", "\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/uW9p8vS.png)" ] } ], "metadata": { "hide_input": false, "kernel_info": { "name": "python3" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" }, "nteract": { "version": "0.12.3" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Table of Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }