{ "cells": [ { "cell_type": "code", "execution_count": null, "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, "metadata": {}, "outputs": [], "source": [ "geemap.show_youtube('DbK_SRgrCHw')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "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/giswqs/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, "metadata": {}, "outputs": [], "source": [ "json_layer = GeoJSON(data=json_data, name='US States JSON', hover_style={'fillColor': 'red' , 'fillOpacity': 0.5})\n", "Map.add_layer(json_layer)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ee_data = geojson_to_ee(json_data)\n", "Map.addLayer(ee_data, {}, \"US States EE\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "json_data_2 = ee_to_geojson(ee_data)\n", "json_layer_2 = GeoJSON(data=json_data_2, name='US States EE JSON', hover_style={'fillColor': 'red' , 'fillOpacity': 0.5})\n", "Map.add_layer(json_layer_2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "file_path = os.path.abspath('../data/countries.json')\n", "\n", "if not os.path.exists(file_path):\n", " url = 'https://github.com/giswqs/geemap/raw/master/examples/data/countries.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, "metadata": {}, "outputs": [], "source": [ "json_layer = GeoJSON(data=json_data, name='Counties', hover_style={'fillColor': 'red' , 'fillOpacity': 0.5})\n", "Map.add_layer(json_layer)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import Text, HTML\n", "from ipyleaflet import WidgetControl, GeoJSON \n", "\n", "html1 = HTML('''\n", "