{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "\"Open" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "# !pip install geemap" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "**Styling Earth Engine vector data**" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "# geemap.update_package()" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "## Use the default style" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "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", "id": "8", "metadata": {}, "source": [ "## Use Image.paint()" ] }, { "cell_type": "code", "execution_count": null, "id": "9", "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", "id": "10", "metadata": {}, "source": [ "## Use FeatureCollection.style()" ] }, { "cell_type": "code", "execution_count": null, "id": "11", "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", "id": "12", "metadata": {}, "source": [ "## Use add_styled_vector()" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "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, "id": "14", "metadata": {}, "outputs": [], "source": [ "import geemap.colormaps as cm" ] }, { "cell_type": "code", "execution_count": null, "id": "15", "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, "id": "16", "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", "id": "17", "metadata": {}, "source": [ "## Use interactive GUI" ] }, { "cell_type": "code", "execution_count": null, "id": "18", "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 }