#!/usr/bin/env python # coding: utf-8 # In[1]: import geemap import ee import folium import geopandas as gpd # In[2]: ee.Authenticate() ee.Initialize() # In[46]: datadir = 'C:/Users/jtrum/world_bank/data/' aoi_path = datadir + 'aoiLuanda.geojson' aoi = geemap.geojson_to_ee(aoi_path) esa = ee.ImageCollection("ESA/WorldCover/v100").first() esa = esa.clip(aoi) esa_vis = {'bands': ['Map']} Map = geemap.Map() Map.add_basemap('CartoDB.DarkMatter') Map.addLayer(esa, esa_vis, "ESA Land Cover") Map.add_legend(title="ESA Land Cover", builtin_legend='ESA_WorldCover') Map.centerObject(aoi, 10) #add title Map.add_text(x=-8.8, y=11.8, text="Land Cover (Luanda, Angola)", fontsize=20, fontweight='bold', color='white') Map # In[17]: df = geemap.image_area_by_group(esa, scale=1000, denominator=1e6, decimal_places=4, verbose=True) import pandas as pd data = { 'cover': ['Trees', 'Shrublands', 'Grasslands', 'Croplands', 'Built-Up', 'Barren', 'Snow and Ice', 'Water Bodies', 'Herbaceous Wetlands', 'Mangroves', 'Moss and Lichen'], 'group': ['10', '20', '30', '40', '50', '60', '70', '80', '90', '95', '100'] } lc_df = pd.DataFrame(data) #join the two dataframes by 'group' lc = lc_df.join(df, on='group') lc['percentage'] = lc['percentage']*100 lc = lc.fillna(0) lc # In[23]: # In[22]: df # In[27]: # In[53]: #make a bar chart, ordered descending by percentage import matplotlib.pyplot as plt import seaborn as sns color_codes = ['#006400', '#FFBB22', '#FFFF4C', '#F096FF', '#FA0000', '#B4B4B4', '#F0F0F0', '#0064C8', '#0096A0', '#00CF75', '#FAE6A0'] land_cover_categories = ['Trees', 'Shrublands', 'Grasslands', 'Croplands', 'Built-Up', 'Barren', 'Snow and Ice', 'Water Bodies', 'Herbaceous Wetlands', 'Mangroves', 'Moss and Lichen'] sns.set_style("whitegrid") fig, ax = plt.subplots(figsize=(12, 8)) #order descending by percentage lc = lc.sort_values(by=['percentage'], ascending=False) #add percentage to be just right of the bar, rounded to 2 decimal places for index, row in lc.iterrows(): ax.text(row.percentage+0.5, row.cover, str(round(row.percentage, 2)), color='black', ha="left", va='center', fontsize=12) ax = sns.barplot(x="percentage", y="cover", data=lc, palette=color_codes) ax.set(xlabel="Percentage (%)", ylabel="") plt.show()