Motivation
๐Google Earth Engine use less line of code to do Zonal statistic compare with GEEMAP and no limitation of the CRS of your raster data.
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go
import geopandas as gpd
import folium
import matplotlib.pyplot as pl
import pyproj
The code below is Java script
You need to import your data into google earth engine
Add raster data
var dataset=ee.ImageCollection(ntl)
var style= {
max:100,
palette:['black','white','orange','yellow']
}
Map.addLayer(dataset, style, 'Night time light')
Map
Add shp
var china= ee.FeatureCollection(shp)
var shp_style={color:'yellow'}
Map.addLayer(china,shp_style, 'China')
Map
Zonal statistic--Mean
var y2020 = ntl.reduceRegions({
reducer: ee.Reducer.mean(),
collection: China
});
print(y2020)
Export result into GeoJSON / CSV
print(y2020)
Export.table.toDrive({
collection: y2020,
description: 'zonal',
folder: 'file',
fileNamePrefix: 'Chinam',
fileFormat: 'GeoJSON'
})
Data Visualization
The code below is Python code
gdf=gpd.read_file('/work/Chinam.geojson')
gdf
gdf.describe( ).round(2)
gdf.plot()
gdf.explore(column='mean',cmap='cividis')
gdf.explore(
column='mean',
tooltip=['ADM1_ZH', 'mean'],
scheme='naturalbreaks',
cmap='coolwarm',
legend=True,
style_kwds =dict(color="gray", weight=0.5),
legend_kwds=dict(colorbar=False)
)