geobox 2.0.1__py3-none-any.whl → 2.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. geobox/__init__.py +61 -63
  2. geobox/aio/__init__.py +61 -63
  3. geobox/aio/api.py +489 -473
  4. geobox/aio/apikey.py +263 -263
  5. geobox/aio/attachment.py +341 -339
  6. geobox/aio/base.py +261 -262
  7. geobox/aio/basemap.py +196 -196
  8. geobox/aio/dashboard.py +340 -342
  9. geobox/aio/feature.py +23 -33
  10. geobox/aio/field.py +315 -321
  11. geobox/aio/file.py +72 -72
  12. geobox/aio/layout.py +340 -341
  13. geobox/aio/log.py +23 -23
  14. geobox/aio/map.py +1033 -1034
  15. geobox/aio/model3d.py +415 -415
  16. geobox/aio/mosaic.py +696 -696
  17. geobox/aio/plan.py +314 -314
  18. geobox/aio/query.py +693 -693
  19. geobox/aio/raster.py +907 -869
  20. geobox/aio/raster_analysis.py +740 -0
  21. geobox/aio/route.py +4 -4
  22. geobox/aio/scene.py +340 -342
  23. geobox/aio/settings.py +18 -18
  24. geobox/aio/task.py +404 -402
  25. geobox/aio/tile3d.py +337 -339
  26. geobox/aio/tileset.py +102 -103
  27. geobox/aio/usage.py +52 -51
  28. geobox/aio/user.py +506 -507
  29. geobox/aio/vector_tool.py +1968 -0
  30. geobox/aio/vectorlayer.py +315 -306
  31. geobox/aio/version.py +272 -273
  32. geobox/aio/view.py +1019 -983
  33. geobox/aio/workflow.py +340 -341
  34. geobox/api.py +18 -2
  35. geobox/apikey.py +262 -262
  36. geobox/attachment.py +336 -337
  37. geobox/base.py +384 -384
  38. geobox/basemap.py +194 -194
  39. geobox/dashboard.py +339 -341
  40. geobox/enums.py +432 -348
  41. geobox/feature.py +5 -5
  42. geobox/field.py +320 -320
  43. geobox/file.py +4 -4
  44. geobox/layout.py +339 -340
  45. geobox/log.py +4 -4
  46. geobox/map.py +1031 -1032
  47. geobox/model3d.py +410 -410
  48. geobox/mosaic.py +696 -696
  49. geobox/plan.py +313 -313
  50. geobox/query.py +691 -691
  51. geobox/raster.py +907 -863
  52. geobox/raster_analysis.py +737 -0
  53. geobox/scene.py +341 -342
  54. geobox/settings.py +194 -194
  55. geobox/task.py +399 -400
  56. geobox/tile3d.py +337 -338
  57. geobox/tileset.py +4 -4
  58. geobox/usage.py +3 -3
  59. geobox/user.py +503 -503
  60. geobox/vector_tool.py +1968 -0
  61. geobox/vectorlayer.py +5 -5
  62. geobox/version.py +272 -272
  63. geobox/view.py +981 -981
  64. geobox/workflow.py +338 -339
  65. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/METADATA +15 -1
  66. geobox-2.2.0.dist-info/RECORD +72 -0
  67. geobox-2.0.1.dist-info/RECORD +0 -68
  68. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/WHEEL +0 -0
  69. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/licenses/LICENSE +0 -0
  70. {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/top_level.txt +0 -0
geobox/mosaic.py CHANGED
@@ -1,696 +1,696 @@
1
- from urllib.parse import urljoin, urlencode
2
- from typing import Dict, List, Optional, Union, TYPE_CHECKING
3
-
4
- from .utils import clean_data
5
- from .raster import Raster
6
-
7
- if TYPE_CHECKING:
8
- from . import GeoboxClient
9
- from .user import User
10
- from .task import Task
11
- from .aio import AsyncGeoboxClient
12
- from .aio.mosaic import Mosaic as AsyncMosaic
13
-
14
-
15
- class Mosaic(Raster):
16
-
17
- BASE_ENDPOINT: str = 'mosaics/'
18
-
19
- def __init__(self,
20
- api: 'GeoboxClient',
21
- uuid: str,
22
- data: Optional[Dict] = {}):
23
- """
24
- Initialize a Mosaic instance.
25
-
26
- Args:
27
- api (GeoboxClient): The GeoboxClient instance for making requests.
28
- uuid (str): The unique identifier for the mosaic.
29
- data (Dict, optional): The data of the mosaic.
30
- """
31
- super().__init__(api, uuid, data)
32
-
33
-
34
- @classmethod
35
- def get_mosaics(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Mosaic'], int]:
36
- """
37
- Get a list of mosaics.
38
-
39
- Args:
40
- api (GeoboxClient): The GeoboxClient instance for making requests.
41
-
42
- Keyword Args:
43
- q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'".
44
- seacrh (str): search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
45
- search_fields (str): comma separated list of fields for searching.
46
- order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
47
- return_count (bool): if true, the number of mosaics will be returned.
48
- skip (int): number of mosaics to skip. minimum value is 0.
49
- limit (int): maximum number of mosaics to return. minimum value is 1.
50
- user_id (int): specific user. privileges required.
51
- shared (bool): Whether to return shared mosaics. default is False.
52
-
53
- Returns:
54
- List['Mosaic'] | int: A list of Mosaic instances or the number of mosaics.
55
-
56
- Example:
57
- >>> from geobox import GeoboxClient
58
- >>> from geobox.mosaic import Mosaic
59
- >>> client = GeoboxClient()
60
- >>> mosaics = Mosaic.get_mosaics(client, q="name LIKE '%GIS%'")
61
- or
62
- >>> mosaics = client.get_mosaics(q="name LIKE '%GIS%'")
63
- """
64
- params = {
65
- 'terrain': kwargs.get('terrain', None),
66
- 'f': 'json',
67
- 'q': kwargs.get('q', None),
68
- 'search': kwargs.get('search', None),
69
- 'search_fields': kwargs.get('search_fields', None),
70
- 'order_by': kwargs.get('order_by', None),
71
- 'return_count': kwargs.get('return_count', False),
72
- 'skip': kwargs.get('skip', 0),
73
- 'limit': kwargs.get('limit', 100),
74
- 'user_id': kwargs.get('user_id', None),
75
- 'shared': kwargs.get('shared', False)
76
- }
77
- return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Mosaic(api, item['uuid'], item))
78
-
79
-
80
- @classmethod
81
- def get_mosaics_by_ids(cls, api: 'GeoboxClient', ids: List[str], user_id: int = None) -> List['Mosaic']:
82
- """
83
- Get mosaics by their IDs.
84
-
85
- Args:
86
- api (GeoboxClient): The GeoboxClient instance for making requests.
87
- ids (List[str]): The IDs of the mosaics.
88
- user_id (int, optional): specific user. privileges required.
89
-
90
- Returns:
91
- List[Mosaic]: A list of Mosaic instances.
92
-
93
- Example:
94
- >>> from geobox import GeoboxClient
95
- >>> from geobox.mosaic import Mosaic
96
- >>> client = GeoboxClient()
97
- >>> mosaics = Mosaic.get_mosaics_by_ids(client, ids=['1, 2, 3'])
98
- or
99
- >>> mosaics = client.get_mosaics_by_ids(ids=['1, 2, 3'])
100
- """
101
- params = {
102
- 'ids': ids,
103
- 'user_id': user_id
104
- }
105
- endpoint = urljoin(cls.BASE_ENDPOINT, 'get-mosaics/')
106
- return super()._get_list_by_ids(api, endpoint, params, factory_func=lambda api, item: Mosaic(api, item['uuid'], item))
107
-
108
-
109
- @classmethod
110
- def create_mosaic(cls,
111
- api: 'GeoboxClient',
112
- name:str,
113
- display_name: str = None,
114
- description: str = None,
115
- pixel_selection: str = None,
116
- min_zoom: int = None,
117
- user_id: int = None) -> 'Mosaic':
118
- """
119
- Create New Raster Mosaic
120
-
121
- Args:
122
- api (GeoboxClient): The GeoboxClient instance for making requests.
123
- name (str): The name of the mosaic.
124
- display_name (str, optional): The display name of the mosaic.
125
- description (str, optional): The description of the mosaic.
126
- pixel_selection (str, optional): The pixel selection of the mosaic.
127
- min_zoom (int, optional): The minimum zoom of the mosaic.
128
- user_id (int, optional): specific user. privileges required.
129
-
130
- Returns:
131
- Mosaic: The created mosaic.
132
-
133
- Example:
134
- >>> from geobox import GeoboxClient
135
- >>> from geobox.mosaic import Mosaic
136
- >>> client = GeoboxClient()
137
- >>> mosaic = Mosaic.create_mosaic(client, name='mosaic_name')
138
- or
139
- >>> mosaic = client.create_mosaic(name='mosaic_name')
140
- """
141
- data = {
142
- 'name': name,
143
- 'display_name': display_name,
144
- 'description': description,
145
- 'pixel_selection': pixel_selection,
146
- 'min_zoom': min_zoom,
147
- 'user_id': user_id
148
- }
149
- return super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Mosaic(api, item['uuid'], item))
150
-
151
-
152
- @classmethod
153
- def get_mosaic(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Mosaic':
154
- """
155
- Get a mosaic by uuid.
156
-
157
- Args:
158
- api (GeoboxClient): The GeoboxClient instance for making requests.
159
- uuid (str): The UUID of the mosaic.
160
- user_id (int, optional): specific user. privileges required.
161
-
162
- Returns:
163
- Mosaic: The mosaic object.
164
-
165
- Example:
166
- >>> from geobox import GeoboxClient
167
- >>> from geobox.mosaic import Mosaic
168
- >>> client = GeoboxClient()
169
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
170
- or
171
- >>> mosaic = client.get_mosaic(uuid="12345678-1234-5678-1234-567812345678")
172
- """
173
- params = {
174
- 'f': 'json',
175
- 'user_id': user_id
176
- }
177
- return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Mosaic(api, item['uuid'], item))
178
-
179
-
180
- @classmethod
181
- def get_mosaic_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Mosaic', None]:
182
- """
183
- Get a mosaic by name
184
-
185
- Args:
186
- api (GeoboxClient): The GeoboxClient instance for making requests.
187
- name (str): the name of the mosaic to get
188
- user_id (int, optional): specific user. privileges required.
189
-
190
- Returns:
191
- Mosaic | None: returns the mosaic if a mosaic matches the given name, else None
192
-
193
- Example:
194
- >>> from geobox import GeoboxClient
195
- >>> from geobox.mosaic import Mosaic
196
- >>> client = GeoboxClient()
197
- >>> mosaic = Mosaic.get_mosaic_by_name(client, name='test')
198
- or
199
- >>> mosaic = client.get_mosaic_by_name(name='test')
200
- """
201
- mosaics = cls.get_mosaics(api, q=f"name = '{name}'", user_id=user_id)
202
- if mosaics and mosaics[0].name == name:
203
- return mosaics[0]
204
- else:
205
- return None
206
-
207
-
208
- def update(self, **kwargs) -> Dict:
209
- """
210
- Update a mosaic.
211
-
212
- Keyword Args:
213
- name (str): The name of the mosaic.
214
- display_name (str): The display name of the mosaic.
215
- description (str): The description of the mosaic.
216
- pixel_selection (str): The pixel selection of the mosaic.
217
- min_zoom (int): The minimum zoom of the mosaic.
218
-
219
- Returns:
220
- Dict: the updated data
221
-
222
- Example:
223
- >>> from geobox import GeoboxClient
224
- >>> from geobox.mosaic import Mosaic
225
- >>> client = GeoboxClient()
226
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
227
- >>> mosaic.update(name='new_name', display_name='new_display_name', description='new_description', pixel_selection='new_pixel_selection', min_zoom=10)
228
- """
229
- data = {
230
- 'name': kwargs.get('name'),
231
- 'display_name': kwargs.get('display_name'),
232
- 'description': kwargs.get('description'),
233
- 'pixel_selection': kwargs.get('pixel_selection'),
234
- 'min_zoom': kwargs.get('min_zoom')
235
- }
236
- return super()._update(self.endpoint, data)
237
-
238
-
239
- def delete(self) -> None:
240
- """
241
- Delete the mosaic.
242
-
243
- Returns:
244
- None
245
-
246
- Example:
247
- >>> from geobox import GeoboxClient
248
- >>> from geobox.mosaic import Mosaic
249
- >>> client = GeoboxClient()
250
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
251
- >>> mosaic.delete()
252
- """
253
- super().delete()
254
-
255
-
256
- @property
257
- def thumbnail(self) -> str:
258
- """
259
- Get the thumbnail of the mosaic.
260
-
261
- Returns:
262
- str: The thumbnail url of the mosaic.
263
-
264
- Example:
265
- >>> from geobox import GeoboxClient
266
- >>> from geobox.mosaic import Mosaic
267
- >>> client = GeoboxClient()
268
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
269
- >>> mosaic.thumbnail
270
- """
271
- return super().thumbnail
272
-
273
-
274
- def get_point(self, lat: float, lng: float) -> List[float]:
275
- """
276
- Get the points of the mosaic.
277
-
278
- Args:
279
- lat (float): The latitude of the point.
280
- lng (float): The longitude of the point.
281
-
282
- Returns:
283
- List[float]: The points of the mosaic.
284
-
285
- Example:
286
- >>> from geobox import GeoboxClient
287
- >>> from geobox.mosaic import Mosaic
288
- >>> client = GeoboxClient()
289
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
290
- >>> mosaic.get_point(lat=60, lng=50)
291
- """
292
- return super().get_point(lat, lng)
293
-
294
-
295
- def get_render_png_url(self, x: int = '{x}', y: int = '{y}', z: int = '{z}', **kwargs) -> str:
296
- """
297
- Get the tile render URL of the mosaic.
298
-
299
- Args:
300
- x (int, optional): The x coordinate of the tile.
301
- y (int, optional): The y coordinate of the tile.
302
- z (int, optional): The zoom level of the tile.
303
-
304
- Keyword Args:
305
- indexes (str, optional): list of comma separated band indexes to be rendered. e.g. 1, 2, 3
306
- nodata (int, optional)
307
- expression (str, optional): band math expression. e.g. b1*b2+b3
308
- rescale (List, optional): comma (',') separated Min,Max range. Can set multiple time for multiple bands.
309
- color_formula (str, optional): Color formula. e.g. gamma R 0.5
310
- colormap_name (str, optional)
311
- colormap (str, optional): JSON encoded custom Colormap. e.g. {"0": "#ff0000", "1": "#00ff00"} or [[[0, 100], "#ff0000"], [[100, 200], "#00ff00"]]
312
-
313
- Returns:
314
- str: The tile render URL of the mosaic.
315
-
316
- Example:
317
- >>> from geobox import GeoboxClient
318
- >>> from geobox.mosaic import Mosaic
319
- >>> client = GeoboxClient()
320
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
321
- >>> mosaic.get_tile_render_url(x=1, y=1, z=1)
322
- """
323
- return super().get_render_png_url(x, y, z, **kwargs)
324
-
325
-
326
- def get_tile_png_url(self, x: int = '{x}', y: int = '{y}', z: int = '{z}') -> str:
327
- """
328
- Get the tile PNG URL of the mosaic.
329
-
330
- Args:
331
- x (int, optional): The x coordinate of the tile.
332
- y (int, optional): The y coordinate of the tile.
333
- z (int, optional): The zoom level of the tile.
334
-
335
- Returns:
336
- str: The tile PNG URL of the mosaic.
337
-
338
- Example:
339
- >>> from geobox import GeoboxClient
340
- >>> from geobox.mosaic import Mosaic
341
- >>> client = GeoboxClient()
342
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
343
- >>> mosaic.get_tile_png_url(x=1, y=1, z=1)
344
- """
345
- return super().get_tile_png_url(x, y, z)
346
-
347
-
348
- def get_tile_json(self) -> str:
349
- """
350
- Get the tile JSON of the raster.
351
-
352
- Returns:
353
- str: The tile JSON of the raster.
354
-
355
- Example:
356
- >>> from geobox import GeoboxClient
357
- >>> from geobox.mosaic import Mosaic
358
- >>> client = GeoboxClient()
359
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
360
- >>> mosaic.get_tile_json()
361
- """
362
- return super().get_tile_json()
363
-
364
-
365
- def wmts(self, scale: int = None) -> str:
366
- """
367
- Get the WMTS URL
368
-
369
- Args:
370
- scale (int, optional): The scale of the raster. values are: 1, 2
371
-
372
- Returns:
373
- str: The WMTS URL of the mosaic.
374
-
375
- Example:
376
- >>> from geobox import GeoboxClient
377
- >>> from geobox.mosaic import Mosaic
378
- >>> client = GeoboxClient()
379
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
380
- >>> mosaic.wmts(scale=1)
381
- """
382
- return super().wmts(scale)
383
-
384
- @property
385
- def settings(self) -> Dict:
386
- """
387
- Get the settings of the mosaic.
388
-
389
- Returns:
390
- Dict: The settings of the mosaic.
391
-
392
- Example:
393
- >>> from geobox import GeoboxClient
394
- >>> from geobox.mosaic import Mosaic
395
- >>> client = GeoboxClient()
396
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
397
- >>> mosaic.settings
398
- """
399
- return super().settings
400
-
401
-
402
- def update_settings(self, settings: Dict) -> Dict:
403
- """
404
- Update the settings
405
-
406
- settings (Dict): settings dictionary
407
-
408
- Returns:
409
- Dict: updated settings
410
-
411
- Example:
412
- >>> from geobox import GeoboxClient
413
- >>> client = GeoboxClient()
414
- >>> mosaic1 = client.get_mosaic(uuid="12345678-1234-5678-1234-567812345678")
415
- >>> mosaic2 = client.get_mosaic(uuid="12345678-1234-5678-1234-567812345678")
416
- >>> mosaic1.update_settings(mosaic2.settings)
417
- """
418
- return super().update_settings(settings)
419
-
420
-
421
- def set_settings(self, **kwargs) -> None:
422
- """
423
- Set the settings of the mosaic.
424
-
425
- Keyword Args:
426
- nodata (int): The nodata value of the raster.
427
- indexes (list[int]): The indexes of the raster.
428
- rescale (list[int]): The rescale of the raster.
429
- colormap_name (str): The colormap name of the raster.
430
- color_formula (str): The color formula of the raster.
431
- expression (str): The expression of the raster.
432
- exaggeraion (int): The exaggeraion of the raster.
433
- min_zoom (int): The min zoom of the raster.
434
- max_zoom (int): The max zoom of the raster.
435
- use_cache (bool): Whether to use cache of the raster.
436
- cache_until_zoom (int): The cache until zoom of the raster.
437
-
438
- Returns:
439
- None
440
-
441
- Example:
442
- >>> from geobox import GeoboxClient
443
- >>> from geobox.mosaic import Mosaic
444
- >>> client = GeoboxClient()
445
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
446
- >>> mosaic.set_settings(nodata=0,
447
- ... indexes=[1],
448
- ... rescale=[[0, 10000]],
449
- ... colormap_name='gist_rainbow',
450
- ... color_formula='Gamma R 0.5',
451
- ... expression='b1 * 2',
452
- ... exaggeraion=10,
453
- ... min_zoom=0,
454
- ... max_zoom=22,
455
- ... use_cache=True,
456
- ... cache_until_zoom=17)
457
- """
458
- return super().set_settings(**kwargs)
459
-
460
-
461
- def get_rasters(self, user_id: int = None) -> List[Raster]:
462
- """
463
- Get the rasters of the mosaic
464
-
465
- Args:
466
- user_id (int, optional): specific user. privileges required.
467
-
468
- Returns:
469
- List[Raster]: The rasters of the mosaic.
470
-
471
- Example:
472
- >>> from geobox import GeoboxClient
473
- >>> from geobox.mosaic import Mosaic
474
- >>> client = GeoboxClient()
475
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
476
- >>> rasters = mosaic.get_rasters()
477
- """
478
- params = clean_data({
479
- 'user_id': user_id
480
- })
481
- query_string = urlencode(params)
482
- endpoint = urljoin(self.BASE_ENDPOINT, f'{self.uuid}/rasters?{query_string}')
483
- response = self.api.get(endpoint)
484
- return [Raster(self.api, raster_data['uuid'], raster_data) for raster_data in response]
485
-
486
-
487
- def add_rasters(self, rasters: List['Raster']) -> None:
488
- """
489
- Add a raster to the mosaic.
490
-
491
- Args:
492
- rasters (List[Raster]): list of raster objects to add
493
-
494
- Returns:
495
- None
496
-
497
- Example:
498
- >>> from geobox import GeoboxClient
499
- >>> from geobox.mosaic import Mosaic
500
- >>> client = GeoboxClient()
501
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
502
- >>> rasters = client.get_rasters()
503
- >>> mosaic.add_raster(rasters=rasters)
504
- """
505
- data = clean_data({
506
- 'raster_ids': [raster.id for raster in rasters]
507
- })
508
- endpoint = urljoin(self.BASE_ENDPOINT, f'{self.uuid}/rasters/')
509
- self.api.post(endpoint, data, is_json=False)
510
-
511
-
512
- def remove_rasters(self, rasters: List['Raster']) -> None:
513
- """
514
- Remove a raster from the mosaic.
515
-
516
- Args:
517
- rasters (List[Raster]): list of raster objects to remove
518
-
519
- Returns:
520
- None
521
-
522
- Example:
523
- >>> from geobox import GeoboxClient
524
- >>> from geobox.mosaic import Mosaic
525
- >>> client = GeoboxClient()
526
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
527
- >>> rasters = client.get_raster()
528
- >>> mosaic.remove_rasters(rasters=rasters)
529
- """
530
- param = clean_data({
531
- 'raster_ids': [raster.id for raster in rasters]
532
- })
533
- query_string = urlencode(param)
534
- endpoint = urljoin(self.BASE_ENDPOINT, f'{self.uuid}/rasters/?{query_string}')
535
- self.api.delete(endpoint, is_json=False)
536
-
537
-
538
- def share(self, users: List['User']) -> None:
539
- """
540
- Shares the mosaic with specified users.
541
-
542
- Args:
543
- users (List[User]): The list of user objects to share the mosaic with.
544
-
545
- Returns:
546
- None
547
-
548
- Example:
549
- >>> from geobox import GeoboxClient
550
- >>> from geobox.mosaic import Mosaic
551
- >>> client = GeoboxClient()
552
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
553
- >>> users = client.search_users(search='John')
554
- >>> mosaic.share(users=users)
555
- """
556
- super()._share(self.endpoint, users)
557
-
558
-
559
- def unshare(self, users: List['User']) -> None:
560
- """
561
- Unshares the mosaic with specified users.
562
-
563
- Args:
564
- users (List[User]): The list of user objects to unshare the mosaic with.
565
-
566
- Returns:
567
- None
568
-
569
- Example:
570
- >>> from geobox import GeoboxClient
571
- >>> from geobox.mosaic import Mosaic
572
- >>> client = GeoboxClient()
573
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
574
- >>> users = client.search_users(search='John')
575
- >>> mosaic.unshare(users=users)
576
- """
577
- super()._unshare(self.endpoint, users)
578
-
579
-
580
- def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
581
- """
582
- Retrieves the list of users the file is shared with.
583
-
584
- Args:
585
- search (str, optional): The search query.
586
- skip (int, optional): The number of users to skip.
587
- limit (int, optional): The maximum number of users to retrieve.
588
-
589
- Returns:
590
- List[User]: The list of shared users.
591
-
592
- Example:
593
- >>> from geobox import GeoboxClient
594
- >>> from geobox.mosaic import Mosaic
595
- >>> client = GeoboxClient()
596
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
597
- >>> mosaic.get_shared_users(search='John', skip=0, limit=10)
598
- """
599
- params = {
600
- 'search': search,
601
- 'skip': skip,
602
- 'limit': limit
603
- }
604
- return super()._get_shared_users(self.endpoint, params)
605
-
606
-
607
- def seed_cache(self,
608
- from_zoom: int = None,
609
- to_zoom: int = None,
610
- extent: List[int] = None,
611
- workers: int = 1) -> List['Task']:
612
- """
613
- Seed the cache of the mosaic.
614
-
615
- Args:
616
- from_zoom (int, optional): The from zoom of the mosaic.
617
- to_zoom (int, optional): The to zoom of the mosaic.
618
- extent (list[int], optional): The extent of the mosaic.
619
- workers (int, optional): The number of workers to use. default is 1.
620
-
621
- Returns:
622
- List[Task]: The task of the seed cache.
623
-
624
- Example:
625
- >>> from geobox import GeoboxClient
626
- >>> from geobox.mosaic import Mosaic
627
- >>> client = GeoboxClient()
628
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
629
- >>> task = mosaic.seed_cache(from_zoom=0, to_zoom=22, extent=[0, 0, 100, 100], workers=1)
630
- """
631
- data = {
632
- 'from_zoom': from_zoom,
633
- 'to_zoom': to_zoom,
634
- 'extent': extent,
635
- 'workers': workers
636
- }
637
- return super()._seed_cache(endpoint=self.endpoint, data=data)
638
-
639
-
640
- def clear_cache(self) -> None:
641
- """
642
- Clear the cache of the mosaic.
643
-
644
- Returns:
645
- None
646
-
647
- Example:
648
- >>> from geobox import GeoboxClient
649
- >>> from geobox.mosaic import Mosaic
650
- >>> client = GeoboxClient()
651
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
652
- >>> mosaic.clear_cache()
653
- """
654
- return super().clear_cache()
655
-
656
-
657
- @property
658
- def cache_size(self) -> int:
659
- """
660
- Get the size of the cache of the mosaic.
661
-
662
- Returns:
663
- int: The size of the cache of the mosaic.
664
-
665
- Example:
666
- >>> from geobox import GeoboxClient
667
- >>> from geobox.mosaic import Mosaic
668
- >>> client = GeoboxClient()
669
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
670
- >>> mosaic.cache_size
671
- """
672
- return super().cache_size
673
-
674
-
675
- def to_async(self, async_client: 'AsyncGeoboxClient') -> 'AsyncMosaic':
676
- """
677
- Switch to async version of the mosaic instance to have access to the async methods
678
-
679
- Args:
680
- async_client (AsyncGeoboxClient): The async version of the GeoboxClient instance for making requests.
681
-
682
- Returns:
683
- geobox.aio.mosaic.Mosaic: the async instance of the mosaic.
684
-
685
- Example:
686
- >>> from geobox import Geoboxclient
687
- >>> from geobox.aio import AsyncGeoboxClient
688
- >>> from geobox.mosaic import Mosaic
689
- >>> client = GeoboxClient()
690
- >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
691
- >>> async with AsyncGeoboxClient() as async_client:
692
- >>> async_mosaic = mosaic.to_async(async_client)
693
- """
694
- from .aio.mosaic import Mosaic as AsyncMosaic
695
-
696
- return AsyncMosaic(api=async_client, uuid=self.uuid, data=self.data)
1
+ from urllib.parse import urljoin, urlencode
2
+ from typing import Dict, List, Optional, Union, TYPE_CHECKING
3
+
4
+ from .utils import clean_data
5
+ from .raster import Raster
6
+
7
+ if TYPE_CHECKING:
8
+ from . import GeoboxClient
9
+ from .user import User
10
+ from .task import Task
11
+ from .aio import AsyncGeoboxClient
12
+ from .aio.mosaic import AsyncMosaic
13
+
14
+
15
+ class Mosaic(Raster):
16
+
17
+ BASE_ENDPOINT: str = 'mosaics/'
18
+
19
+ def __init__(self,
20
+ api: 'GeoboxClient',
21
+ uuid: str,
22
+ data: Optional[Dict] = {}):
23
+ """
24
+ Initialize a Mosaic instance.
25
+
26
+ Args:
27
+ api (GeoboxClient): The GeoboxClient instance for making requests.
28
+ uuid (str): The unique identifier for the mosaic.
29
+ data (Dict, optional): The data of the mosaic.
30
+ """
31
+ super().__init__(api, uuid, data)
32
+
33
+
34
+ @classmethod
35
+ def get_mosaics(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Mosaic'], int]:
36
+ """
37
+ Get a list of mosaics.
38
+
39
+ Args:
40
+ api (GeoboxClient): The GeoboxClient instance for making requests.
41
+
42
+ Keyword Args:
43
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'".
44
+ seacrh (str): search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
45
+ search_fields (str): comma separated list of fields for searching.
46
+ order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
47
+ return_count (bool): if true, the number of mosaics will be returned.
48
+ skip (int): number of mosaics to skip. minimum value is 0.
49
+ limit (int): maximum number of mosaics to return. minimum value is 1.
50
+ user_id (int): specific user. privileges required.
51
+ shared (bool): Whether to return shared mosaics. default is False.
52
+
53
+ Returns:
54
+ List['Mosaic'] | int: A list of Mosaic instances or the number of mosaics.
55
+
56
+ Example:
57
+ >>> from geobox import GeoboxClient
58
+ >>> from geobox.mosaic import Mosaic
59
+ >>> client = GeoboxClient()
60
+ >>> mosaics = Mosaic.get_mosaics(client, q="name LIKE '%GIS%'")
61
+ or
62
+ >>> mosaics = client.get_mosaics(q="name LIKE '%GIS%'")
63
+ """
64
+ params = {
65
+ 'terrain': kwargs.get('terrain', None),
66
+ 'f': 'json',
67
+ 'q': kwargs.get('q', None),
68
+ 'search': kwargs.get('search', None),
69
+ 'search_fields': kwargs.get('search_fields', None),
70
+ 'order_by': kwargs.get('order_by', None),
71
+ 'return_count': kwargs.get('return_count', False),
72
+ 'skip': kwargs.get('skip', 0),
73
+ 'limit': kwargs.get('limit', 100),
74
+ 'user_id': kwargs.get('user_id', None),
75
+ 'shared': kwargs.get('shared', False)
76
+ }
77
+ return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Mosaic(api, item['uuid'], item))
78
+
79
+
80
+ @classmethod
81
+ def get_mosaics_by_ids(cls, api: 'GeoboxClient', ids: List[str], user_id: int = None) -> List['Mosaic']:
82
+ """
83
+ Get mosaics by their IDs.
84
+
85
+ Args:
86
+ api (GeoboxClient): The GeoboxClient instance for making requests.
87
+ ids (List[str]): The IDs of the mosaics.
88
+ user_id (int, optional): specific user. privileges required.
89
+
90
+ Returns:
91
+ List[Mosaic]: A list of Mosaic instances.
92
+
93
+ Example:
94
+ >>> from geobox import GeoboxClient
95
+ >>> from geobox.mosaic import Mosaic
96
+ >>> client = GeoboxClient()
97
+ >>> mosaics = Mosaic.get_mosaics_by_ids(client, ids=['1, 2, 3'])
98
+ or
99
+ >>> mosaics = client.get_mosaics_by_ids(ids=['1, 2, 3'])
100
+ """
101
+ params = {
102
+ 'ids': ids,
103
+ 'user_id': user_id
104
+ }
105
+ endpoint = urljoin(cls.BASE_ENDPOINT, 'get-mosaics/')
106
+ return super()._get_list_by_ids(api, endpoint, params, factory_func=lambda api, item: Mosaic(api, item['uuid'], item))
107
+
108
+
109
+ @classmethod
110
+ def create_mosaic(cls,
111
+ api: 'GeoboxClient',
112
+ name:str,
113
+ display_name: str = None,
114
+ description: str = None,
115
+ pixel_selection: str = None,
116
+ min_zoom: int = None,
117
+ user_id: int = None) -> 'Mosaic':
118
+ """
119
+ Create New Raster Mosaic
120
+
121
+ Args:
122
+ api (GeoboxClient): The GeoboxClient instance for making requests.
123
+ name (str): The name of the mosaic.
124
+ display_name (str, optional): The display name of the mosaic.
125
+ description (str, optional): The description of the mosaic.
126
+ pixel_selection (str, optional): The pixel selection of the mosaic.
127
+ min_zoom (int, optional): The minimum zoom of the mosaic.
128
+ user_id (int, optional): specific user. privileges required.
129
+
130
+ Returns:
131
+ Mosaic: The created mosaic.
132
+
133
+ Example:
134
+ >>> from geobox import GeoboxClient
135
+ >>> from geobox.mosaic import Mosaic
136
+ >>> client = GeoboxClient()
137
+ >>> mosaic = Mosaic.create_mosaic(client, name='mosaic_name')
138
+ or
139
+ >>> mosaic = client.create_mosaic(name='mosaic_name')
140
+ """
141
+ data = {
142
+ 'name': name,
143
+ 'display_name': display_name,
144
+ 'description': description,
145
+ 'pixel_selection': pixel_selection,
146
+ 'min_zoom': min_zoom,
147
+ 'user_id': user_id
148
+ }
149
+ return super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Mosaic(api, item['uuid'], item))
150
+
151
+
152
+ @classmethod
153
+ def get_mosaic(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Mosaic':
154
+ """
155
+ Get a mosaic by uuid.
156
+
157
+ Args:
158
+ api (GeoboxClient): The GeoboxClient instance for making requests.
159
+ uuid (str): The UUID of the mosaic.
160
+ user_id (int, optional): specific user. privileges required.
161
+
162
+ Returns:
163
+ Mosaic: The mosaic object.
164
+
165
+ Example:
166
+ >>> from geobox import GeoboxClient
167
+ >>> from geobox.mosaic import Mosaic
168
+ >>> client = GeoboxClient()
169
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
170
+ or
171
+ >>> mosaic = client.get_mosaic(uuid="12345678-1234-5678-1234-567812345678")
172
+ """
173
+ params = {
174
+ 'f': 'json',
175
+ 'user_id': user_id
176
+ }
177
+ return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Mosaic(api, item['uuid'], item))
178
+
179
+
180
+ @classmethod
181
+ def get_mosaic_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Mosaic', None]:
182
+ """
183
+ Get a mosaic by name
184
+
185
+ Args:
186
+ api (GeoboxClient): The GeoboxClient instance for making requests.
187
+ name (str): the name of the mosaic to get
188
+ user_id (int, optional): specific user. privileges required.
189
+
190
+ Returns:
191
+ Mosaic | None: returns the mosaic if a mosaic matches the given name, else None
192
+
193
+ Example:
194
+ >>> from geobox import GeoboxClient
195
+ >>> from geobox.mosaic import Mosaic
196
+ >>> client = GeoboxClient()
197
+ >>> mosaic = Mosaic.get_mosaic_by_name(client, name='test')
198
+ or
199
+ >>> mosaic = client.get_mosaic_by_name(name='test')
200
+ """
201
+ mosaics = cls.get_mosaics(api, q=f"name = '{name}'", user_id=user_id)
202
+ if mosaics and mosaics[0].name == name:
203
+ return mosaics[0]
204
+ else:
205
+ return None
206
+
207
+
208
+ def update(self, **kwargs) -> Dict:
209
+ """
210
+ Update a mosaic.
211
+
212
+ Keyword Args:
213
+ name (str): The name of the mosaic.
214
+ display_name (str): The display name of the mosaic.
215
+ description (str): The description of the mosaic.
216
+ pixel_selection (str): The pixel selection of the mosaic.
217
+ min_zoom (int): The minimum zoom of the mosaic.
218
+
219
+ Returns:
220
+ Dict: the updated data
221
+
222
+ Example:
223
+ >>> from geobox import GeoboxClient
224
+ >>> from geobox.mosaic import Mosaic
225
+ >>> client = GeoboxClient()
226
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
227
+ >>> mosaic.update(name='new_name', display_name='new_display_name', description='new_description', pixel_selection='new_pixel_selection', min_zoom=10)
228
+ """
229
+ data = {
230
+ 'name': kwargs.get('name'),
231
+ 'display_name': kwargs.get('display_name'),
232
+ 'description': kwargs.get('description'),
233
+ 'pixel_selection': kwargs.get('pixel_selection'),
234
+ 'min_zoom': kwargs.get('min_zoom')
235
+ }
236
+ return super()._update(self.endpoint, data)
237
+
238
+
239
+ def delete(self) -> None:
240
+ """
241
+ Delete the mosaic.
242
+
243
+ Returns:
244
+ None
245
+
246
+ Example:
247
+ >>> from geobox import GeoboxClient
248
+ >>> from geobox.mosaic import Mosaic
249
+ >>> client = GeoboxClient()
250
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
251
+ >>> mosaic.delete()
252
+ """
253
+ super()._delete(self.endpoint)
254
+
255
+
256
+ @property
257
+ def thumbnail(self) -> str:
258
+ """
259
+ Get the thumbnail of the mosaic.
260
+
261
+ Returns:
262
+ str: The thumbnail url of the mosaic.
263
+
264
+ Example:
265
+ >>> from geobox import GeoboxClient
266
+ >>> from geobox.mosaic import Mosaic
267
+ >>> client = GeoboxClient()
268
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
269
+ >>> mosaic.thumbnail
270
+ """
271
+ return super()._thumbnail(format="")
272
+
273
+
274
+ def get_point(self, lat: float, lng: float) -> List[float]:
275
+ """
276
+ Get the points of the mosaic.
277
+
278
+ Args:
279
+ lat (float): The latitude of the point.
280
+ lng (float): The longitude of the point.
281
+
282
+ Returns:
283
+ List[float]: The points of the mosaic.
284
+
285
+ Example:
286
+ >>> from geobox import GeoboxClient
287
+ >>> from geobox.mosaic import Mosaic
288
+ >>> client = GeoboxClient()
289
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
290
+ >>> mosaic.get_point(lat=60, lng=50)
291
+ """
292
+ return super().get_point(lat, lng)
293
+
294
+
295
+ def get_render_png_url(self, x: int = '{x}', y: int = '{y}', z: int = '{z}', **kwargs) -> str:
296
+ """
297
+ Get the tile render URL of the mosaic.
298
+
299
+ Args:
300
+ x (int, optional): The x coordinate of the tile.
301
+ y (int, optional): The y coordinate of the tile.
302
+ z (int, optional): The zoom level of the tile.
303
+
304
+ Keyword Args:
305
+ indexes (str, optional): list of comma separated band indexes to be rendered. e.g. 1, 2, 3
306
+ nodata (int, optional)
307
+ expression (str, optional): band math expression. e.g. b1*b2+b3
308
+ rescale (List, optional): comma (',') separated Min,Max range. Can set multiple time for multiple bands.
309
+ color_formula (str, optional): Color formula. e.g. gamma R 0.5
310
+ colormap_name (str, optional)
311
+ colormap (str, optional): JSON encoded custom Colormap. e.g. {"0": "#ff0000", "1": "#00ff00"} or [[[0, 100], "#ff0000"], [[100, 200], "#00ff00"]]
312
+
313
+ Returns:
314
+ str: The tile render URL of the mosaic.
315
+
316
+ Example:
317
+ >>> from geobox import GeoboxClient
318
+ >>> from geobox.mosaic import Mosaic
319
+ >>> client = GeoboxClient()
320
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
321
+ >>> mosaic.get_tile_render_url(x=1, y=1, z=1)
322
+ """
323
+ return super().get_render_png_url(x, y, z, **kwargs)
324
+
325
+
326
+ def get_tile_png_url(self, x: int = '{x}', y: int = '{y}', z: int = '{z}') -> str:
327
+ """
328
+ Get the tile PNG URL of the mosaic.
329
+
330
+ Args:
331
+ x (int, optional): The x coordinate of the tile.
332
+ y (int, optional): The y coordinate of the tile.
333
+ z (int, optional): The zoom level of the tile.
334
+
335
+ Returns:
336
+ str: The tile PNG URL of the mosaic.
337
+
338
+ Example:
339
+ >>> from geobox import GeoboxClient
340
+ >>> from geobox.mosaic import Mosaic
341
+ >>> client = GeoboxClient()
342
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
343
+ >>> mosaic.get_tile_png_url(x=1, y=1, z=1)
344
+ """
345
+ return super().get_tile_png_url(x, y, z)
346
+
347
+
348
+ def get_tile_json(self) -> str:
349
+ """
350
+ Get the tile JSON of the raster.
351
+
352
+ Returns:
353
+ str: The tile JSON of the raster.
354
+
355
+ Example:
356
+ >>> from geobox import GeoboxClient
357
+ >>> from geobox.mosaic import Mosaic
358
+ >>> client = GeoboxClient()
359
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
360
+ >>> mosaic.get_tile_json()
361
+ """
362
+ return super().get_tile_json()
363
+
364
+
365
+ def wmts(self, scale: int = None) -> str:
366
+ """
367
+ Get the WMTS URL
368
+
369
+ Args:
370
+ scale (int, optional): The scale of the raster. values are: 1, 2
371
+
372
+ Returns:
373
+ str: The WMTS URL of the mosaic.
374
+
375
+ Example:
376
+ >>> from geobox import GeoboxClient
377
+ >>> from geobox.mosaic import Mosaic
378
+ >>> client = GeoboxClient()
379
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
380
+ >>> mosaic.wmts(scale=1)
381
+ """
382
+ return super().wmts(scale)
383
+
384
+ @property
385
+ def settings(self) -> Dict:
386
+ """
387
+ Get the settings of the mosaic.
388
+
389
+ Returns:
390
+ Dict: The settings of the mosaic.
391
+
392
+ Example:
393
+ >>> from geobox import GeoboxClient
394
+ >>> from geobox.mosaic import Mosaic
395
+ >>> client = GeoboxClient()
396
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
397
+ >>> mosaic.settings
398
+ """
399
+ return super().settings
400
+
401
+
402
+ def update_settings(self, settings: Dict) -> Dict:
403
+ """
404
+ Update the settings
405
+
406
+ settings (Dict): settings dictionary
407
+
408
+ Returns:
409
+ Dict: updated settings
410
+
411
+ Example:
412
+ >>> from geobox import GeoboxClient
413
+ >>> client = GeoboxClient()
414
+ >>> mosaic1 = client.get_mosaic(uuid="12345678-1234-5678-1234-567812345678")
415
+ >>> mosaic2 = client.get_mosaic(uuid="12345678-1234-5678-1234-567812345678")
416
+ >>> mosaic1.update_settings(mosaic2.settings)
417
+ """
418
+ return super().update_settings(settings)
419
+
420
+
421
+ def set_settings(self, **kwargs) -> None:
422
+ """
423
+ Set the settings of the mosaic.
424
+
425
+ Keyword Args:
426
+ nodata (int): The nodata value of the raster.
427
+ indexes (list[int]): The indexes of the raster.
428
+ rescale (list[int]): The rescale of the raster.
429
+ colormap_name (str): The colormap name of the raster.
430
+ color_formula (str): The color formula of the raster.
431
+ expression (str): The expression of the raster.
432
+ exaggeraion (int): The exaggeraion of the raster.
433
+ min_zoom (int): The min zoom of the raster.
434
+ max_zoom (int): The max zoom of the raster.
435
+ use_cache (bool): Whether to use cache of the raster.
436
+ cache_until_zoom (int): The cache until zoom of the raster.
437
+
438
+ Returns:
439
+ None
440
+
441
+ Example:
442
+ >>> from geobox import GeoboxClient
443
+ >>> from geobox.mosaic import Mosaic
444
+ >>> client = GeoboxClient()
445
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
446
+ >>> mosaic.set_settings(nodata=0,
447
+ ... indexes=[1],
448
+ ... rescale=[[0, 10000]],
449
+ ... colormap_name='gist_rainbow',
450
+ ... color_formula='Gamma R 0.5',
451
+ ... expression='b1 * 2',
452
+ ... exaggeraion=10,
453
+ ... min_zoom=0,
454
+ ... max_zoom=22,
455
+ ... use_cache=True,
456
+ ... cache_until_zoom=17)
457
+ """
458
+ return super().set_settings(**kwargs)
459
+
460
+
461
+ def get_rasters(self, user_id: int = None) -> List[Raster]:
462
+ """
463
+ Get the rasters of the mosaic
464
+
465
+ Args:
466
+ user_id (int, optional): specific user. privileges required.
467
+
468
+ Returns:
469
+ List[Raster]: The rasters of the mosaic.
470
+
471
+ Example:
472
+ >>> from geobox import GeoboxClient
473
+ >>> from geobox.mosaic import Mosaic
474
+ >>> client = GeoboxClient()
475
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
476
+ >>> rasters = mosaic.get_rasters()
477
+ """
478
+ params = clean_data({
479
+ 'user_id': user_id
480
+ })
481
+ query_string = urlencode(params)
482
+ endpoint = urljoin(self.BASE_ENDPOINT, f'{self.uuid}/rasters?{query_string}')
483
+ response = self.api.get(endpoint)
484
+ return [Raster(self.api, raster_data['uuid'], raster_data) for raster_data in response]
485
+
486
+
487
+ def add_rasters(self, rasters: List['Raster']) -> None:
488
+ """
489
+ Add a raster to the mosaic.
490
+
491
+ Args:
492
+ rasters (List[Raster]): list of raster objects to add
493
+
494
+ Returns:
495
+ None
496
+
497
+ Example:
498
+ >>> from geobox import GeoboxClient
499
+ >>> from geobox.mosaic import Mosaic
500
+ >>> client = GeoboxClient()
501
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
502
+ >>> rasters = client.get_rasters()
503
+ >>> mosaic.add_raster(rasters=rasters)
504
+ """
505
+ data = clean_data({
506
+ 'raster_ids': [raster.id for raster in rasters]
507
+ })
508
+ endpoint = urljoin(self.BASE_ENDPOINT, f'{self.uuid}/rasters/')
509
+ self.api.post(endpoint, data, is_json=False)
510
+
511
+
512
+ def remove_rasters(self, rasters: List['Raster']) -> None:
513
+ """
514
+ Remove a raster from the mosaic.
515
+
516
+ Args:
517
+ rasters (List[Raster]): list of raster objects to remove
518
+
519
+ Returns:
520
+ None
521
+
522
+ Example:
523
+ >>> from geobox import GeoboxClient
524
+ >>> from geobox.mosaic import Mosaic
525
+ >>> client = GeoboxClient()
526
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
527
+ >>> rasters = client.get_raster()
528
+ >>> mosaic.remove_rasters(rasters=rasters)
529
+ """
530
+ param = clean_data({
531
+ 'raster_ids': [raster.id for raster in rasters]
532
+ })
533
+ query_string = urlencode(param)
534
+ endpoint = urljoin(self.BASE_ENDPOINT, f'{self.uuid}/rasters/?{query_string}')
535
+ self.api.delete(endpoint, is_json=False)
536
+
537
+
538
+ def share(self, users: List['User']) -> None:
539
+ """
540
+ Shares the mosaic with specified users.
541
+
542
+ Args:
543
+ users (List[User]): The list of user objects to share the mosaic with.
544
+
545
+ Returns:
546
+ None
547
+
548
+ Example:
549
+ >>> from geobox import GeoboxClient
550
+ >>> from geobox.mosaic import Mosaic
551
+ >>> client = GeoboxClient()
552
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
553
+ >>> users = client.search_users(search='John')
554
+ >>> mosaic.share(users=users)
555
+ """
556
+ super()._share(self.endpoint, users)
557
+
558
+
559
+ def unshare(self, users: List['User']) -> None:
560
+ """
561
+ Unshares the mosaic with specified users.
562
+
563
+ Args:
564
+ users (List[User]): The list of user objects to unshare the mosaic with.
565
+
566
+ Returns:
567
+ None
568
+
569
+ Example:
570
+ >>> from geobox import GeoboxClient
571
+ >>> from geobox.mosaic import Mosaic
572
+ >>> client = GeoboxClient()
573
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
574
+ >>> users = client.search_users(search='John')
575
+ >>> mosaic.unshare(users=users)
576
+ """
577
+ super()._unshare(self.endpoint, users)
578
+
579
+
580
+ def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
581
+ """
582
+ Retrieves the list of users the file is shared with.
583
+
584
+ Args:
585
+ search (str, optional): The search query.
586
+ skip (int, optional): The number of users to skip.
587
+ limit (int, optional): The maximum number of users to retrieve.
588
+
589
+ Returns:
590
+ List[User]: The list of shared users.
591
+
592
+ Example:
593
+ >>> from geobox import GeoboxClient
594
+ >>> from geobox.mosaic import Mosaic
595
+ >>> client = GeoboxClient()
596
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
597
+ >>> mosaic.get_shared_users(search='John', skip=0, limit=10)
598
+ """
599
+ params = {
600
+ 'search': search,
601
+ 'skip': skip,
602
+ 'limit': limit
603
+ }
604
+ return super()._get_shared_users(self.endpoint, params)
605
+
606
+
607
+ def seed_cache(self,
608
+ from_zoom: int = None,
609
+ to_zoom: int = None,
610
+ extent: List[int] = None,
611
+ workers: int = 1) -> List['Task']:
612
+ """
613
+ Seed the cache of the mosaic.
614
+
615
+ Args:
616
+ from_zoom (int, optional): The from zoom of the mosaic.
617
+ to_zoom (int, optional): The to zoom of the mosaic.
618
+ extent (list[int], optional): The extent of the mosaic.
619
+ workers (int, optional): The number of workers to use. default is 1.
620
+
621
+ Returns:
622
+ List[Task]: The task of the seed cache.
623
+
624
+ Example:
625
+ >>> from geobox import GeoboxClient
626
+ >>> from geobox.mosaic import Mosaic
627
+ >>> client = GeoboxClient()
628
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
629
+ >>> task = mosaic.seed_cache(from_zoom=0, to_zoom=22, extent=[0, 0, 100, 100], workers=1)
630
+ """
631
+ data = {
632
+ 'from_zoom': from_zoom,
633
+ 'to_zoom': to_zoom,
634
+ 'extent': extent,
635
+ 'workers': workers
636
+ }
637
+ return super()._seed_cache(endpoint=self.endpoint, data=data)
638
+
639
+
640
+ def clear_cache(self) -> None:
641
+ """
642
+ Clear the cache of the mosaic.
643
+
644
+ Returns:
645
+ None
646
+
647
+ Example:
648
+ >>> from geobox import GeoboxClient
649
+ >>> from geobox.mosaic import Mosaic
650
+ >>> client = GeoboxClient()
651
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
652
+ >>> mosaic.clear_cache()
653
+ """
654
+ return super().clear_cache()
655
+
656
+
657
+ @property
658
+ def cache_size(self) -> int:
659
+ """
660
+ Get the size of the cache of the mosaic.
661
+
662
+ Returns:
663
+ int: The size of the cache of the mosaic.
664
+
665
+ Example:
666
+ >>> from geobox import GeoboxClient
667
+ >>> from geobox.mosaic import Mosaic
668
+ >>> client = GeoboxClient()
669
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
670
+ >>> mosaic.cache_size
671
+ """
672
+ return super().cache_size
673
+
674
+
675
+ def to_async(self, async_client: 'AsyncGeoboxClient') -> 'AsyncMosaic':
676
+ """
677
+ Switch to async version of the mosaic instance to have access to the async methods
678
+
679
+ Args:
680
+ async_client (AsyncGeoboxClient): The async version of the GeoboxClient instance for making requests.
681
+
682
+ Returns:
683
+ AsyncMosaic: the async instance of the mosaic.
684
+
685
+ Example:
686
+ >>> from geobox import Geoboxclient
687
+ >>> from geobox.aio import AsyncGeoboxClient
688
+ >>> from geobox.mosaic import Mosaic
689
+ >>> client = GeoboxClient()
690
+ >>> mosaic = Mosaic.get_mosaic(client, uuid="12345678-1234-5678-1234-567812345678")
691
+ >>> async with AsyncGeoboxClient() as async_client:
692
+ >>> async_mosaic = mosaic.to_async(async_client)
693
+ """
694
+ from .aio.mosaic import AsyncMosaic
695
+
696
+ return AsyncMosaic(api=async_client, uuid=self.uuid, data=self.data)