Setting Up a GCP Service Account
Setting Up a GCP Service Account
Before you can authenticate, you need a Google Cloud Platform service account with the Earth Engine API enabled. Here is the short version:
1
.2
.Create a project (or select an existing one).
3
.Enable the Earth Engine API in the API Library.
4
.Go to IAM & Admin > Service Accounts and create a new service account.
5
.Grant the service account the Earth Engine Resource Viewer role.
6
.Create a JSON key for the service account and download it.
The downloaded file will look something like this:
{
"type": "service_account",
"project_id": "my-gee-project",
"private_key_id": "abc123...",
"private_key": "-----BEGIN RSA PRIVATE KEY-----\n...",
"client_email": "gee-reader@my-gee-project.iam.gserviceaccount.com",
...
}
"type": "service_account",
"project_id": "my-gee-project",
"private_key_id": "abc123...",
"private_key": "-----BEGIN RSA PRIVATE KEY-----\n...",
"client_email": "gee-reader@my-gee-project.iam.gserviceaccount.com",
...
}
Store this file securely. It is the only credential you need.
Connecting to Earth Engine
Connecting to Earth Engine
conn=["/path/to/service-account-key.json"]
On success, returns a status Association and stores the full connection state in :
GEEConnect
$GEEConnection
conn(*<|"Project"->"my-gee-project","Status"->"Connected","Expiry"->DateObject[...]|>*)
The access token has a one-hour lifetime and is automatically refreshed by subsequent API calls. You only need to call once per session.
GEEConnect
Point Query -- Elevation at a Location
In[6]:=
result=,"USGS/SRTMGL1_003"
Out[6]=
PositionGeoPosition[{27.9881,86.9253}],Values{8718},Bands{elevation}
Scope (2)
Scope
(2)
Image Retrieval -- Geo-Tagged Satellite Image
In[7]:=
img=[GeoPosition[{36.57,-118.29}],(*SierraNevada,CA*)"USGS/SRTMGL1_003",GeoRange->Quantity[50,"Kilometers"],"VisParams"-><|"min"->500,"max"->4400,"palette"->{"#1a9850","#91cf60","#d9ef8b","#fee08b","#fc8d59","#d73027","#FFFFFF"}|>]
Out[7]=
_________________________________________________________________________________________________________________
Sentinel-2 True Color
In[8]:=
img=,(*Madrid,Spain*)"COPERNICUS/S2_SR_HARMONIZED",GeoRange->Quantity[20,"Kilometers"],"Bands"->{"B4","B3","B2"},"VisParams"-><|"min"->0,"max"->3000|>
Out[8]=
Create a cloud-free RGB median composite of Barcelona for summer 2024.
In[9]:=
bbox={2.05,41.30,2.30,41.50};composite=GEECollection["COPERNICUS/S2_SR_HARMONIZED"]//GEEFilterDate["2024-06-01","2024-09-01"]//GEEFilterBounds[bbox]//GEEFilterProperty["CLOUDY_PIXEL_PERCENTAGE","LessThan",10]//GEESelectBands[{"B4","B3","B2"}]//GEEMedian;img=[bbox,composite,"VisParams"-><|"min"->0,"max"->3000|>,"ImageSize"->{640,640}]
Out[11]=
Feature Query -- Protected Areas
Goal: Find protected areas near Yellowstone National Park:
GeoGraphics Integration:
GeoGraphics Integration: