{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Styling Earth Engine vector data**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# geemap.update_package()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use the default style" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "\n", "Map.addLayer(states, {}, \"US States\")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use Image.paint()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "image = ee.Image().paint(states, 0, 3)\n", "\n", "Map.addLayer(image, {'palette': 'red'}, \"US States\")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use FeatureCollection.style()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "style = {'color': '0000ffff', 'width': 2, 'lineType': 'solid', 'fillColor': '00000080'}\n", "\n", "Map.addLayer(states.style(**style), {}, \"US States\")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use add_styled_vector()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "\n", "vis_params = {\n", " 'color': '000000',\n", " 'colorOpacity': 1,\n", " 'pointSize': 3,\n", " 'pointShape': 'circle',\n", " 'width': 2,\n", " 'lineType': 'solid',\n", " 'fillColorOpacity': 0.66,\n", "}\n", "\n", "palette = ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5']\n", "\n", "Map.add_styled_vector(\n", " states, column=\"NAME\", palette=palette, layer_name=\"Styled vector\", **vis_params\n", ")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import geemap.colormaps as cm" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "\n", "vis_params = {\n", " 'color': '000000',\n", " 'colorOpacity': 1,\n", " 'pointSize': 3,\n", " 'pointShape': 'circle',\n", " 'width': 2,\n", " 'lineType': 'solid',\n", " 'fillColorOpacity': 0.66,\n", "}\n", "\n", "palette = list(cm.palettes.gist_earth.n12)\n", "\n", "Map.add_styled_vector(\n", " states, column=\"NAME\", palette=palette, layer_name=\"Styled vector\", **vis_params\n", ")\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "states = ee.FeatureCollection(\"TIGER/2018/States\").filter(\n", " ee.Filter.inList('NAME', ['California', 'Nevada', 'Utah', 'Arizona'])\n", ")\n", "\n", "palette = {\n", " 'California': 'ff0000',\n", " 'Nevada': '00ff00',\n", " 'Utah': '0000ff',\n", " 'Arizona': 'ffff00',\n", "}\n", "\n", "vis_params = {\n", " 'color': '000000',\n", " 'colorOpacity': 1,\n", " 'width': 2,\n", " 'lineType': 'solid',\n", " 'fillColorOpacity': 0.66,\n", "}\n", "\n", "Map.add_styled_vector(\n", " states, column=\"NAME\", palette=palette, layer_name=\"Styled vector\", **vis_params\n", ")\n", "\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use interactive GUI" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "\n", "states = ee.FeatureCollection(\"TIGER/2018/States\")\n", "\n", "Map.addLayer(states, {}, \"US States\")\n", "Map" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }