0
# Earth Engine Integration
1
2
Specialized tools and utilities for working with Google Earth Engine, including tile layer creation, authentication, initialization, and comprehensive API integration features.
3
4
## Capabilities
5
6
### Earth Engine Initialization
7
8
Initialize and authenticate with Google Earth Engine service with various authentication methods and configuration options.
9
10
```python { .api }
11
def ee_initialize(
12
token_name: str = "EARTHENGINE_TOKEN",
13
auth_args: Dict = None,
14
**kwargs
15
) -> None:
16
"""
17
Initialize Earth Engine with authentication.
18
19
Args:
20
token_name: Environment variable name for token
21
auth_args: Authentication arguments
22
**kwargs: Additional initialization parameters
23
"""
24
25
def set_proxy(
26
port: int = 1080,
27
host: str = "127.0.0.1",
28
**kwargs
29
) -> None:
30
"""
31
Set proxy configuration for Earth Engine.
32
33
Args:
34
port: Proxy port number
35
host: Proxy host address
36
**kwargs: Additional proxy parameters
37
"""
38
```
39
40
### Tile Layer Creation
41
42
Create tile layers from Earth Engine objects for visualization in interactive maps.
43
44
```python { .api }
45
def ee_tile_layer(
46
ee_object,
47
vis_params: Dict = {},
48
name: str = "Layer",
49
shown: bool = True,
50
opacity: float = 1.0
51
) -> ipyleaflet.TileLayer:
52
"""
53
Create Earth Engine tile layer for ipyleaflet maps.
54
55
Args:
56
ee_object: Earth Engine object (Image, ImageCollection, FeatureCollection)
57
vis_params: Visualization parameters
58
name: Layer name
59
shown: Whether layer is visible
60
opacity: Layer opacity (0-1)
61
62
Returns:
63
ipyleaflet TileLayer object
64
"""
65
```
66
67
**Visualization Parameters:**
68
- `min`, `max`: Value range for stretching
69
- `bands`: Band selection for RGB visualization
70
- `palette`: Color palette for single-band images
71
- `gamma`: Gamma correction value
72
73
### Earth Engine Tile Layer Classes
74
75
Specialized tile layer classes for different mapping backends.
76
77
```python { .api }
78
class EELeafletTileLayer:
79
"""Earth Engine tile layer for ipyleaflet backend."""
80
81
def __init__(
82
self,
83
ee_object,
84
vis_params: Dict = {},
85
name: str = "Layer",
86
opacity: float = 1.0,
87
visible: bool = True,
88
**kwargs
89
) -> None:
90
"""
91
Initialize Earth Engine tile layer for ipyleaflet.
92
93
Args:
94
ee_object: Earth Engine object
95
vis_params: Visualization parameters
96
name: Layer name
97
opacity: Layer opacity
98
visible: Layer visibility
99
**kwargs: Additional parameters
100
"""
101
102
class EEFoliumTileLayer:
103
"""Earth Engine tile layer for folium backend."""
104
105
def __init__(
106
self,
107
ee_object,
108
vis_params: Dict = {},
109
name: str = "Layer",
110
opacity: float = 1.0,
111
visible: bool = True,
112
**kwargs
113
) -> None:
114
"""
115
Initialize Earth Engine tile layer for folium.
116
117
Args:
118
ee_object: Earth Engine object
119
vis_params: Visualization parameters
120
name: Layer name
121
opacity: Layer opacity
122
visible: Layer visibility
123
**kwargs: Additional parameters
124
"""
125
```
126
127
### Authentication and Credentials
128
129
Manage Earth Engine authentication and credential handling across different environments.
130
131
```python { .api }
132
def is_drive_mounted() -> bool:
133
"""
134
Check if Google Drive is mounted in Colab.
135
136
Returns:
137
True if Drive is mounted
138
"""
139
140
def credentials_in_drive() -> bool:
141
"""
142
Check for Earth Engine credentials in Google Drive.
143
144
Returns:
145
True if credentials found in Drive
146
"""
147
148
def credentials_in_colab() -> bool:
149
"""
150
Check for Earth Engine credentials in Colab.
151
152
Returns:
153
True if credentials found in Colab
154
"""
155
156
def copy_credentials_to_drive() -> None:
157
"""Copy Earth Engine credentials to Google Drive."""
158
159
def copy_credentials_to_colab() -> None:
160
"""Copy Earth Engine credentials from Drive to Colab."""
161
```
162
163
### Object Information and Utilities
164
165
Utilities for inspecting and working with Earth Engine objects.
166
167
```python { .api }
168
def get_info(ee_object, **kwargs) -> Dict:
169
"""
170
Get information about Earth Engine object.
171
172
Args:
173
ee_object: Earth Engine object
174
**kwargs: Additional parameters
175
176
Returns:
177
Information dictionary
178
"""
179
180
def geometry_type(ee_object) -> str:
181
"""
182
Get geometry type of Earth Engine object.
183
184
Args:
185
ee_object: Earth Engine geometry object
186
187
Returns:
188
Geometry type string
189
"""
190
191
def build_computed_object_tree(ee_object) -> Dict:
192
"""
193
Build computed object tree for visualization.
194
195
Args:
196
ee_object: Earth Engine object
197
198
Returns:
199
Tree structure dictionary
200
"""
201
```
202
203
### Environment Detection
204
205
Detect execution environment for proper Earth Engine integration.
206
207
```python { .api }
208
def in_colab_shell() -> bool:
209
"""
210
Test if code is being executed within Google Colab.
211
212
Returns:
213
True if running in Google Colab
214
"""
215
216
def get_env_var(name: str, default: str = None) -> str:
217
"""
218
Get environment variable value.
219
220
Args:
221
name: Environment variable name
222
default: Default value if not found
223
224
Returns:
225
Environment variable value
226
"""
227
```
228
229
### Time Series Inspector
230
231
Interactive time series analysis tools for Earth Engine image collections.
232
233
```python { .api }
234
def ts_inspector(
235
map_object=None,
236
left_ts: ee.ImageCollection = None,
237
right_ts: ee.ImageCollection = None,
238
left_names: List[str] = None,
239
right_names: List[str] = None,
240
**kwargs
241
) -> widgets.VBox:
242
"""
243
Create time series inspector widget.
244
245
Args:
246
map_object: Map object to attach inspector
247
left_ts: Left panel time series collection
248
right_ts: Right panel time series collection
249
left_names: Names for left panel bands
250
right_names: Names for right panel bands
251
**kwargs: Additional parameters
252
253
Returns:
254
Time series inspector widget
255
"""
256
```
257
258
### Data Catalog Integration
259
260
Tools for working with Earth Engine data catalog and asset discovery.
261
262
```python { .api }
263
class Catalog:
264
"""Earth Engine data catalog interface."""
265
266
def __init__(self) -> None:
267
"""Initialize catalog interface."""
268
269
def search(self, keywords: str = None, **kwargs) -> List[Dict]:
270
"""
271
Search Earth Engine data catalog.
272
273
Args:
274
keywords: Search keywords
275
**kwargs: Additional search parameters
276
277
Returns:
278
List of matching dataset information
279
"""
280
281
def get_metadata(asset_id: str) -> Dict:
282
"""
283
Get metadata for Earth Engine asset.
284
285
Args:
286
asset_id: Earth Engine asset ID
287
288
Returns:
289
Asset metadata dictionary
290
"""
291
```
292
293
## Usage Examples
294
295
### Basic Earth Engine Setup
296
297
```python
298
import geemap
299
import ee
300
301
# Initialize Earth Engine
302
geemap.ee_initialize()
303
304
# Alternative initialization with token
305
geemap.ee_initialize(token_name='MY_EE_TOKEN')
306
```
307
308
### Creating Tile Layers
309
310
```python
311
# Create image tile layer
312
image = ee.Image('USGS/SRTMGL1_003')
313
vis_params = {
314
'min': 0,
315
'max': 4000,
316
'palette': ['blue', 'green', 'red']
317
}
318
319
tile_layer = geemap.ee_tile_layer(image, vis_params, 'Elevation')
320
321
# Add to map
322
m = geemap.Map()
323
m.add_layer(tile_layer)
324
```
325
326
### Authentication in Different Environments
327
328
```python
329
# Check environment and handle credentials
330
if geemap.in_colab_shell():
331
if not geemap.credentials_in_colab():
332
if geemap.credentials_in_drive():
333
geemap.copy_credentials_to_colab()
334
else:
335
ee.Authenticate()
336
geemap.ee_initialize()
337
else:
338
geemap.ee_initialize()
339
else:
340
# Local Jupyter environment
341
geemap.ee_initialize()
342
```
343
344
### Time Series Analysis
345
346
```python
347
# Create time series inspector
348
collection = (ee.ImageCollection('MODIS/006/MOD13A2')
349
.filterDate('2020-01-01', '2020-12-31')
350
.select('NDVI'))
351
352
inspector = geemap.ts_inspector(
353
left_ts=collection,
354
left_names=['NDVI']
355
)
356
357
# Display inspector widget
358
inspector
359
```
360
361
### Object Information
362
363
```python
364
# Get Earth Engine object information
365
image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20140318')
366
info = geemap.get_info(image)
367
print(f"Bands: {info['bands']}")
368
print(f"Properties: {info['properties']}")
369
370
# Check geometry type
371
geometry = ee.Geometry.Point([-122, 37])
372
geom_type = geemap.geometry_type(geometry)
373
print(f"Geometry type: {geom_type}")
374
```
375
376
## Types
377
378
```python { .api }
379
# Visualization parameters type
380
VisParams = Dict[str, Union[int, float, List[str], List[int], List[float]]]
381
382
# Earth Engine object info type
383
ObjectInfo = Dict[str, Any]
384
385
# Authentication arguments type
386
AuthArgs = Dict[str, Union[str, bool, Dict]]
387
388
# Asset metadata type
389
AssetMetadata = Dict[str, Union[str, int, float, List, Dict]]
390
```