I am displaying a map of a Feature Collection on a sample Python Flask website I've created (not in the Earth Engine code tool). Let's say for example it's a map of piano stores and their annual revenue. I want a color-coded map of a Google Earth Engine FeatureCollection based on one key (in this case revenue
) in the underlying GeoJSON but can't figure out how to do it. Here is what I've tried:
I assign the FeatureCollection:
piano_shops = ee.FeatureCollection('my/feature/collection')
I get the feature collection using getmapID and getTileUrl like this, but all features display as black:
url = ee.data.getTileUrl(piano_shops.getMapId(), 0, 0, 0)
I can change the color like this, but it changes the entire FeatureCollection to that one color:
url = ee.data.getTileUrl(piano_shops.getMapId({'color': 'red'}), 0, 0, 0)
I can filter the FeatureCollection like this:
piano_shops_filtered = piano_shops.filter(ee.Filter.gt('revenue', 100000))
url = ee.data.getTileUrl(piano_shops_filtered.getMapId({'color': 'red'}), 0, 0, 0)
But what I really want is two things:
- A color gradient from red to green of 0 revenue to 1,000,000 revenue. It seems like you can do this on an Image using
palette
andbands
but FeatureCollection doesn't have that. - Manually-specified color codes of, say, 'red': 0 to 250000, 'orange': 250000 to 500000, 'yellow': 500000 to 750000, 'green': >750000. It seems like for Images you can assign a list to 'palette' based on categories like this (https://developers.google.com/earth-engine/guides/image_visualization):
# Load 2012 MODIS land cover and select the IGBP classification.
cover = ee.Image('MODIS/051/MCD12Q1/2012_01_01').select('Land_Cover_Type_1')
# Define a palette for the 18 distinct land cover classes.
igbp_palette = [
'aec3d4', # water
'152106',
'225129',
'369b47',
'30eb5b',
'387242', # forest
'6a2325',
'c3aa69',
'b76031',
'd9903d',
'91af40', # shrub, grass
'111149', # wetlands
'cdb33b', # croplands
'cc0013', # urban
'33280d', # crop mosaic
'd7cdcc', # snow and ice
'f7e084', # barren
'6f6f6f' # tundra
]
# Define a map centered on the United States.
map_palette = folium.Map(location=[40.413, -99.229], zoom_start=5)
# Add the image layer to the map and display it. Specify the min and max labels
# and the color palette matching the labels.
map_palette.add_ee_layer(
cover, {'min': 0, 'max': 17, 'palette': igbp_palette}, 'IGBP classes')
display(map_palette)
In the Google Earth Engine code editor it seems like you can filter and add lots of layers but I'm not sure that solution will work for my little web map and I want this web map to be fast even if there happened to be a million piano stores (hypothetical) but it also assumes you're using folium, which I'm not. Anyone find a solution for this?