I'm using the python GEE api and ipyleaflet in a Jupyter Notebook and I'd like to retrieve an asset (FeatureCollection) and display it as an overlay on my map.

The retrieving work just fine

asset_descripsion = 'Glad_' + country_selection + '_boundaries'
folder = ee.data.getAssetRoots()[0]['id'] + '/'

asset = ee.FeaturCollection(folder+asset_descripsion)

I also have a ipyleaflet map

m = Map(center=center, zoom=zoom)
dark_matter_layer = basemap_to_tiles(basemaps.CartoDB.DarkMatter)

but I don't know how to add a layer based on a ee.FeatureCollection


I presumed there would be an easy way to convert FeatureCollection to GeoJSON and load up as a layer in ipyleaflet but it is not straightforward. As far as I can see there is no direct way of doing this. However, as a workaround, you can get a download url to your FeatureCollection (JSON is in the options but it did not work for me but CSV did) and then read the features from there as JSON to add as a layer to ipyleaflet. Something similar to in the line of:

import csv
from urllib.request import urlopen
import codecs
import json

url = asset.getDownloadURL("csv")
response = urlopen(url)
cr = csv.DictReader(codecs.iterdecode(response, 'utf-8'))

for row in cr:
    geojson = ipyleaflet.GeoJSON(json.loads(row['.geo']))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.