{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\n", "\n", "**Styling Earth Engine vector data based on attributes**\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install -U geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Styling polygons**\n", "\n", "The US [National Wetland Inventory](https://samapriya.github.io/awesome-gee-community-datasets/projects/nwi/)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[28.00142, -81.7424], zoom=13)\n", "Map.add_basemap('HYBRID')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc = ee.FeatureCollection(\"projects/sat-io/open-datasets/NWI/wetlands/FL_Wetlands\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "types = [\n", " \"Freshwater Forested/Shrub Wetland\",\n", " \"Freshwater Emergent Wetland\",\n", " \"Freshwater Pond\",\n", " \"Estuarine and Marine Wetland\",\n", " \"Riverine\",\n", " \"Lake\",\n", " \"Estuarine and Marine Deepwater\",\n", " \"Other\",\n", "]\n", "\n", "colors = [\n", " \"#008837\",\n", " \"#7FC31C\",\n", " \"#688CC0\",\n", " \"#66C2A5\",\n", " \"#0190BF\",\n", " \"#13007C\",\n", " \"#007C88\",\n", " \"#B28653\",\n", "]\n", "\n", "fillColor = [c + \"A8\" for c in colors]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "styled_fc = geemap.ee_vector_style(\n", " fc, column='WETLAND_TY', labels=types, fillColor=fillColor, color='00000000'\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(styled_fc, {}, 'NWI')\n", "Map.add_legend(title='Wetland Type', labels=types, colors=colors)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/NxmUekc.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Styling points**\n", "\n", "The [Global Power Plant Database ](https://developers.google.com/earth-engine/datasets/catalog/WRI_GPPD_power_plants)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fuels = [\n", " 'Coal',\n", " 'Oil',\n", " 'Gas',\n", " 'Hydro',\n", " 'Nuclear',\n", " 'Solar',\n", " 'Waste',\n", " 'Wind',\n", " 'Geothermal',\n", " 'Biomass',\n", "]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc = ee.FeatureCollection(\"WRI/GPPD/power_plants\").filter(\n", " ee.Filter.inList('fuel1', fuels)\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colors = [\n", " '000000',\n", " '593704',\n", " 'BC80BD',\n", " '0565A6',\n", " 'E31A1C',\n", " 'FF7F00',\n", " '6A3D9A',\n", " '5CA2D1',\n", " 'FDBF6F',\n", " '229A00',\n", "]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "styled_fc = geemap.ee_vector_style(fc, column=\"fuel1\", labels=fuels, color=colors)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.addLayer(styled_fc, {}, 'Power Plants')\n", "Map.add_legend(title=\"Power Plant Fuel Type\", labels=fuels, colors=colors)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/K0jHLYW.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Styling polylines**\n", "\n", "The [TIGER: US Census Roads](https://developers.google.com/earth-engine/datasets/catalog/TIGER_2016_Roads). See the [route type codes](https://www.census.gov/library/reference/code-lists/route-type-codes.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc = ee.FeatureCollection('TIGER/2016/Roads')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "types = ['I', 'U', 'S', 'M', 'C', 'O']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "labels = ['Interstate', 'U.S.', 'State recognized', 'Common Name', 'County', 'Other']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colors = ['E31A1C', 'FF7F00', '6A3D9A', '000000', 'FDBF6F', '229A00']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "width = [8, 5, 4, 2, 1, 1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "styled_fc = geemap.ee_vector_style(\n", " fc, column='rttyp', labels=types, color=colors, width=width\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map(center=[40.7792, -73.9613], zoom=12)\n", "Map.addLayer(styled_fc, {}, 'Census Roads')\n", "Map.add_legend(title='Route Type', labels=labels, colors=colors)\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.imgur.com/02f03XU.png)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }