0
# Export and Download
1
2
Export images and collections to various formats including GeoTIFF, Google Drive, Cloud Storage, and in-memory arrays with configurable parameters. Geedim provides both Earth Engine export tasks and direct download capabilities.
3
4
## Capabilities
5
6
### Export Types
7
8
Enumeration of available export destinations.
9
10
```python { .api }
11
class ExportType(Enum):
12
"""Enumeration for export destinations."""
13
14
drive = 'drive'
15
"""Export to Google Drive."""
16
17
asset = 'asset'
18
"""Export to Earth Engine asset."""
19
20
cloud = 'cloud'
21
"""Export to Google Cloud Storage."""
22
```
23
24
### Resampling Methods
25
26
Enumeration of resampling methods for reprojection and scaling.
27
28
```python { .api }
29
class ResamplingMethod(Enum):
30
"""Enumeration for resampling methods."""
31
32
near = 'near'
33
"""Nearest neighbor resampling."""
34
35
bilinear = 'bilinear'
36
"""Bilinear interpolation."""
37
38
bicubic = 'bicubic'
39
"""Bicubic interpolation."""
40
41
average = 'average'
42
"""Average resampling."""
43
```
44
45
### File Format Drivers
46
47
Enumeration of supported output file formats.
48
49
```python { .api }
50
class Driver(Enum):
51
"""Enumeration for image file formats."""
52
53
gtiff = 'gtiff'
54
"""GeoTIFF format."""
55
56
cog = 'cog'
57
"""Cloud Optimized GeoTIFF."""
58
```
59
60
### Image Export
61
62
Export individual images with comprehensive parameter control.
63
64
```python { .api }
65
def export(
66
self,
67
filename: str,
68
type: ExportType = ExportType.drive,
69
folder: str = None,
70
wait: bool = True,
71
**export_kwargs
72
) -> ee.batch.Task:
73
"""
74
Export image to specified destination using a batch task.
75
76
Parameters:
77
- description (str): Task description and output filename
78
- folder (str, optional): Destination folder name
79
- region (dict | ee.Geometry, optional): Export region bounds
80
- scale (float, optional): Export pixel scale in meters
81
- crs (str, optional): Coordinate reference system (EPSG code)
82
- export_type (ExportType): Export destination
83
- driver (Driver): Output file format
84
- dtype (str): Output data type ('auto', 'uint8', 'uint16', 'float32', etc.)
85
- nodata (float, optional): NoData value
86
- **kwargs: Additional export parameters
87
88
Returns:
89
ee.batch.Task: Earth Engine export task
90
"""
91
```
92
93
### Collection Export
94
95
Export entire image collections with splitting options.
96
97
```python { .api }
98
def export(
99
self,
100
description: str,
101
folder: str = None,
102
region: dict | ee.Geometry = None,
103
scale: float = None,
104
split: str = 'images',
105
max_images: int = 5000,
106
export_type: ExportType = ExportType.drive,
107
**kwargs
108
) -> list[ee.batch.Task]:
109
"""
110
Export image collection with splitting options.
111
112
Parameters:
113
- description (str): Base description for export tasks
114
- folder (str, optional): Destination folder name
115
- region (dict | ee.Geometry, optional): Export region bounds
116
- scale (float, optional): Export pixel scale in meters
117
- split (str): Split method ('images' or 'bands')
118
- max_images (int): Maximum number of images to export
119
- export_type (ExportType): Export destination
120
- **kwargs: Additional export parameters
121
122
Returns:
123
list[ee.batch.Task]: List of export tasks
124
"""
125
```
126
127
### Image Download
128
129
Download images directly to memory or local files.
130
131
```python { .api }
132
def download(
133
self,
134
filename: str = None,
135
region: dict | ee.Geometry = None,
136
scale: float = None,
137
crs: str = None,
138
dtype: str = 'auto',
139
resampling: ResamplingMethod = ResamplingMethod.near,
140
num_threads: int = None,
141
**kwargs
142
):
143
"""
144
Download image to memory or file.
145
146
Parameters:
147
- filename (str, optional): Output filename. If None, returns array/dataset
148
- region (dict | ee.Geometry, optional): Download region bounds
149
- scale (float, optional): Download pixel scale in meters
150
- crs (str, optional): Coordinate reference system
151
- dtype (str): Output data type
152
- resampling (ResamplingMethod): Resampling method
153
- num_threads (int, optional): Number of download threads
154
- **kwargs: Additional download parameters
155
156
Returns:
157
numpy.ndarray | xarray.Dataset | None: Downloaded data or None if saved to file
158
"""
159
```
160
161
### Collection Download
162
163
Download entire collections with parallel processing.
164
165
```python { .api }
166
def download(
167
self,
168
folder: str = None,
169
region: dict | ee.Geometry = None,
170
scale: float = None,
171
max_images: int = None,
172
concurrent: int = 4,
173
**kwargs
174
) -> list:
175
"""
176
Download collection with parallel processing.
177
178
Parameters:
179
- folder (str, optional): Output folder path
180
- region (dict | ee.Geometry, optional): Download region bounds
181
- scale (float, optional): Download pixel scale in meters
182
- max_images (int, optional): Maximum images to download
183
- concurrent (int): Number of concurrent downloads
184
- **kwargs: Additional download parameters
185
186
Returns:
187
list: List of downloaded arrays/datasets or filenames
188
"""
189
```
190
191
## Usage Examples
192
193
### Basic Image Export
194
195
```python
196
import ee
197
import geedim
198
199
geedim.Initialize()
200
201
# Load and process image
202
image = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_173083_20200601')
203
masked_image = image.gd.addMaskBands().maskClouds()
204
205
# Define region
206
region = ee.Geometry.Rectangle([-122.5, 37.7, -122.3, 37.8])
207
208
# Export to Google Drive
209
drive_task = masked_image.gd.export(
210
description='landsat_export',
211
folder='geedim_exports',
212
region=region,
213
scale=30,
214
crs='EPSG:4326',
215
export_type=geedim.ExportType.drive,
216
driver=geedim.Driver.cog
217
)
218
219
# Start export task
220
drive_task.start()
221
print(f"Export task ID: {drive_task.id}")
222
```
223
224
### Cloud Storage Export
225
226
```python
227
# Export to Google Cloud Storage
228
cloud_task = masked_image.gd.export(
229
description='landsat_cloud',
230
folder='gs://my-bucket/geedim-exports',
231
region=region,
232
scale=30,
233
export_type=geedim.ExportType.cloud,
234
dtype='uint16',
235
nodata=0
236
)
237
238
cloud_task.start()
239
```
240
241
### Earth Engine Asset Export
242
243
```python
244
# Export to Earth Engine Asset
245
asset_task = masked_image.gd.export(
246
description='landsat_asset',
247
folder='users/username/geedim_assets',
248
region=region,
249
scale=30,
250
export_type=geedim.ExportType.asset
251
)
252
253
asset_task.start()
254
```
255
256
### Direct Download
257
258
```python
259
# Download to NumPy array
260
array = masked_image.gd.download(
261
region=region,
262
scale=30,
263
dtype='float32',
264
resampling=geedim.ResamplingMethod.bilinear
265
)
266
267
print(f"Downloaded array shape: {array.shape}")
268
print(f"Data type: {array.dtype}")
269
270
# Download to file
271
masked_image.gd.download(
272
filename='landsat_download.tif',
273
region=region,
274
scale=30,
275
dtype='uint16'
276
)
277
```
278
279
### Xarray Integration
280
281
```python
282
# Download as Xarray Dataset (requires xarray dependency)
283
try:
284
dataset = masked_image.gd.download(
285
region=region,
286
scale=30,
287
dtype='float32',
288
format='xarray'
289
)
290
291
print(f"Dataset dimensions: {dataset.dims}")
292
print(f"Data variables: {list(dataset.data_vars)}")
293
print(f"Coordinates: {list(dataset.coords)}")
294
295
# Access bands
296
red_band = dataset['B4']
297
nir_band = dataset['B5']
298
299
# Calculate NDVI
300
ndvi = (nir_band - red_band) / (nir_band + red_band)
301
302
except ImportError:
303
print("Xarray not available, using NumPy array")
304
array = masked_image.gd.download(region=region, scale=30)
305
```
306
307
### Collection Export
308
309
```python
310
# Load collection
311
collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2') \
312
.filterDate('2020-06-01', '2020-09-30') \
313
.filterBounds(region) \
314
.limit(10)
315
316
# Export collection split by images
317
tasks = collection.gd.export(
318
description='landsat_collection',
319
folder='collection_export',
320
region=region,
321
scale=30,
322
split='images',
323
export_type=geedim.ExportType.drive
324
)
325
326
# Start all tasks
327
for i, task in enumerate(tasks):
328
task.start()
329
print(f"Started task {i+1}/{len(tasks)}: {task.id}")
330
331
# Export split by bands
332
band_tasks = collection.gd.export(
333
description='landsat_bands',
334
folder='band_export',
335
region=region,
336
scale=30,
337
split='bands',
338
max_images=5
339
)
340
```
341
342
### Batch Download
343
344
```python
345
# Download collection to folder
346
downloaded_files = collection.gd.download(
347
folder='collection_downloads',
348
region=region,
349
scale=60, # Lower resolution for faster download
350
max_images=5,
351
concurrent=2, # Parallel downloads
352
dtype='uint16'
353
)
354
355
print(f"Downloaded {len(downloaded_files)} files")
356
357
# Download to memory (be careful with memory usage)
358
arrays = collection.limit(3).gd.download(
359
region=region,
360
scale=120, # Much lower resolution
361
concurrent=3
362
)
363
364
for i, array in enumerate(arrays):
365
print(f"Array {i+1} shape: {array.shape}")
366
```
367
368
### Advanced Export Configuration
369
370
```python
371
# Custom export with all parameters
372
advanced_task = masked_image.gd.export(
373
description='advanced_export',
374
folder='advanced_exports',
375
region=region,
376
scale=30,
377
crs='EPSG:3857', # Web Mercator
378
export_type=geedim.ExportType.drive,
379
driver=geedim.Driver.cog,
380
dtype='float32',
381
nodata=-9999,
382
# Additional Earth Engine export parameters
383
maxPixels=1e9,
384
shardSize=256,
385
fileDimensions=4096
386
)
387
388
advanced_task.start()
389
390
# Monitor task progress
391
import time
392
393
while advanced_task.active():
394
print(f"Task status: {advanced_task.status()['state']}")
395
time.sleep(30)
396
397
print(f"Final status: {advanced_task.status()}")
398
```
399
400
### Tiled Downloads
401
402
```python
403
# Download large regions using tiling
404
from geedim.tile import Tiler
405
406
# Create tiler for large region
407
large_region = ee.Geometry.Rectangle([-123, 37, -121, 39])
408
409
tiler = Tiler(
410
region=large_region,
411
scale=30,
412
tile_size=512, # 512x512 pixel tiles
413
overlap=64 # 64 pixel overlap
414
)
415
416
# Download tiles in parallel
417
tile_arrays = []
418
for tile in tiler.tiles:
419
tile_array = masked_image.gd.download(
420
region=tile.region,
421
scale=tile.scale,
422
dtype='uint16'
423
)
424
tile_arrays.append(tile_array)
425
426
print(f"Downloaded {len(tile_arrays)} tiles")
427
```