06 marker cluster
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import geemap
import json
import os
import requests
from geemap import geojson_to_ee, ee_to_geojson
from ipyleaflet import GeoJSON, Marker, MarkerCluster
import geemap
import json
import os
import requests
from geemap import geojson_to_ee, ee_to_geojson
from ipyleaflet import GeoJSON, Marker, MarkerCluster
In [3]:
Copied!
geemap.show_youtube('4HycJPrwpuo')
geemap.show_youtube('4HycJPrwpuo')
In [4]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [5]:
Copied!
file_path = os.path.abspath('../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)
file_path = os.path.abspath('../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)
In [6]:
Copied!
maker_cluster = MarkerCluster(
markers=[
Marker(location=feature['geometry']['coordinates'][::-1])
for feature in json_data['features']
],
name='Markers',
)
maker_cluster = MarkerCluster(
markers=[
Marker(location=feature['geometry']['coordinates'][::-1])
for feature in json_data['features']
],
name='Markers',
)
In [7]:
Copied!
Map.add_layer(maker_cluster)
Map.add_layer(maker_cluster)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [7], in <cell line: 1>() ----> 1 Map.add_layer(maker_cluster) File ~/.local/lib/python3.9/site-packages/geemap/foliumap.py:195, in Map.add_layer(self, ee_object, vis_params, name, shown, opacity, **kwargs) 187 if ( 188 not isinstance(ee_object, ee.Image) 189 and not isinstance(ee_object, ee.ImageCollection) (...) 192 and not isinstance(ee_object, ee.Geometry) 193 ): 194 err_str = "\n\nThe image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection." --> 195 raise AttributeError(err_str) 197 if ( 198 isinstance(ee_object, ee.geometry.Geometry) 199 or isinstance(ee_object, ee.feature.Feature) 200 or isinstance(ee_object, ee.featurecollection.FeatureCollection) 201 ): 202 features = ee.FeatureCollection(ee_object) AttributeError: The image argument in 'addLayer' function must be an instance of one of ee.Image, ee.Geometry, ee.Feature or ee.FeatureCollection.
In [8]:
Copied!
ee_fc = geojson_to_ee(json_data)
Map.addLayer(ee_fc, {}, "US Cities EE")
ee_fc = geojson_to_ee(json_data)
Map.addLayer(ee_fc, {}, "US Cities EE")
Last update:
2022-03-14