{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"\n",
"\n",
"Uncomment the following line to install [geemap](https://geemap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"# !pip install geemap"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"import geemap\n",
"import json\n",
"import os\n",
"import requests\n",
"from geemap import geojson_to_ee, ee_to_geojson\n",
"from ipyleaflet import GeoJSON"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
"geemap.show_youtube(\"DbK_SRgrCHw\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map()\n",
"Map"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"metadata": {},
"outputs": [],
"source": [
"file_path = os.path.abspath(\"../data/us_states.json\")\n",
"\n",
"if not os.path.exists(file_path):\n",
" url = \"https://github.com/gee-community/geemap/raw/master/examples/data/us_states.json\"\n",
" r = requests.get(url)\n",
" with open(file_path, \"w\") as f:\n",
" f.write(r.content.decode(\"utf-8\"))\n",
"\n",
"with open(file_path) as f:\n",
" json_data = json.load(f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"json_layer = GeoJSON(\n",
" data=json_data,\n",
" name=\"US States JSON\",\n",
" hover_style={\"fillColor\": \"red\", \"fillOpacity\": 0.5},\n",
")\n",
"Map.add_layer(json_layer)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7",
"metadata": {},
"outputs": [],
"source": [
"ee_data = geojson_to_ee(json_data)\n",
"Map.addLayer(ee_data, {}, \"US States EE\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [],
"source": [
"json_data_2 = ee_to_geojson(ee_data)\n",
"json_layer_2 = GeoJSON(\n",
" data=json_data_2,\n",
" name=\"US States EE JSON\",\n",
" hover_style={\"fillColor\": \"red\", \"fillOpacity\": 0.5},\n",
")\n",
"Map.add_layer(json_layer_2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"metadata": {},
"outputs": [],
"source": [
"file_path = os.path.abspath(\"../data/countries.geojson\")\n",
"\n",
"if not os.path.exists(file_path):\n",
" url = \"https://github.com/gee-community/geemap/raw/master/examples/data/countries.geojson\"\n",
" r = requests.get(url)\n",
" with open(file_path, \"w\") as f:\n",
" f.write(r.content.decode(\"utf-8\"))\n",
"\n",
"with open(file_path) as f:\n",
" json_data = json.load(f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10",
"metadata": {},
"outputs": [],
"source": [
"json_layer = GeoJSON(\n",
" data=json_data,\n",
" name=\"Countries\",\n",
" hover_style={\"fillColor\": \"red\", \"fillOpacity\": 0.5},\n",
")\n",
"Map.add_layer(json_layer)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11",
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import Text, HTML\n",
"from ipyleaflet import WidgetControl, GeoJSON\n",
"\n",
"html1 = HTML(\n",
" \"\"\"\n",
"