import geemap
import json
import os
import requests
from geemap import geojson_to_ee, ee_to_geojson
from ipyleaflet import GeoJSON, Marker, MarkerCluster
geemap.set_proxy(port=10809)
geemap.show_youtube('4HycJPrwpuo')
Map = geemap.Map(center = (38, 105))
Map
file_path = os.path.abspath('G:/learnpy/data//us-cities.json')
# 如果本地没有这个文件就从下面链接获取,然后写进本地路径
if not os.path.exists(file_path):
url = 'https://github.com/giswqs/geemap/raw/master/examples/data/us-cities.json'
r = requests.get(url)
with open(file_path, 'w') as f:
f.write(r.content.decode("utf-8"))
with open(file_path) as f:
json_data = json.load(f)
json_data
# {'features': [{'properties': {'POP_2010': 40888.0,
# 'ELEV_IN_FT': 1611.0,
# 'STATE': 'ND'},
# 'id': '53',
# 'geometry': {'type': 'Point',
# 'coordinates': [-101.29627319999997, 48.232509500000106]},
# 'type': 'Feature'},
# {'properties': {'POP_2010': 52838.0, 'ELEV_IN_FT': 830.0, 'STATE': 'ND'},
# 'id': '101',
# 'geometry': {'type': 'Point',
# 'coordinates': [-97.03285469999997, 47.92525680000006]},
# 'type': 'Feature'},
# {'properties': {'POP_2010': 15427.0, 'ELEV_IN_FT': 1407.0, 'STATE': 'ND'},
# 'id': '153',
# 'geometry': {'type': 'Point',
# 'coordinates': [-98.70843569999994, 46.91054380000003]},
# 'type': 'Feature'},
# {'properties': {'POP_2010': 105549.0, 'ELEV_IN_FT': 902.0, 'STATE': 'ND'},
# ......
marker_cluster = MarkerCluster(
markers = [Marker(location = feature['geometry']['coordinates'][::-1]) for feature in json_data['features']],
name = 'Markers')
Map.add_layer(marker_cluster)
大圈为markers,黑点为US Cities ee
ee_fc = geojson_to_ee(json_data)
Map.addLayer(ee_fc, {}, 'US Cities EE')