geobox 1.4.2__py3-none-any.whl → 2.0.1__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 (66) hide show
  1. geobox/__init__.py +2 -2
  2. geobox/aio/__init__.py +63 -0
  3. geobox/aio/api.py +2640 -0
  4. geobox/aio/apikey.py +263 -0
  5. geobox/aio/attachment.py +339 -0
  6. geobox/aio/base.py +262 -0
  7. geobox/aio/basemap.py +196 -0
  8. geobox/aio/dashboard.py +342 -0
  9. geobox/aio/feature.py +527 -0
  10. geobox/aio/field.py +321 -0
  11. geobox/aio/file.py +522 -0
  12. geobox/aio/layout.py +341 -0
  13. geobox/aio/log.py +145 -0
  14. geobox/aio/map.py +1034 -0
  15. geobox/aio/model3d.py +415 -0
  16. geobox/aio/mosaic.py +696 -0
  17. geobox/aio/plan.py +315 -0
  18. geobox/aio/query.py +693 -0
  19. geobox/aio/raster.py +869 -0
  20. geobox/aio/route.py +63 -0
  21. geobox/aio/scene.py +342 -0
  22. geobox/aio/settings.py +194 -0
  23. geobox/aio/task.py +402 -0
  24. geobox/aio/tile3d.py +339 -0
  25. geobox/aio/tileset.py +672 -0
  26. geobox/aio/usage.py +243 -0
  27. geobox/aio/user.py +507 -0
  28. geobox/aio/vectorlayer.py +1363 -0
  29. geobox/aio/version.py +273 -0
  30. geobox/aio/view.py +983 -0
  31. geobox/aio/workflow.py +341 -0
  32. geobox/api.py +14 -15
  33. geobox/apikey.py +28 -1
  34. geobox/attachment.py +27 -1
  35. geobox/base.py +4 -4
  36. geobox/basemap.py +30 -1
  37. geobox/dashboard.py +27 -0
  38. geobox/feature.py +33 -13
  39. geobox/field.py +33 -21
  40. geobox/file.py +40 -46
  41. geobox/layout.py +28 -1
  42. geobox/log.py +31 -7
  43. geobox/map.py +34 -2
  44. geobox/model3d.py +31 -37
  45. geobox/mosaic.py +28 -7
  46. geobox/plan.py +29 -3
  47. geobox/query.py +39 -14
  48. geobox/raster.py +26 -13
  49. geobox/scene.py +26 -0
  50. geobox/settings.py +30 -1
  51. geobox/task.py +28 -6
  52. geobox/tile3d.py +27 -1
  53. geobox/tileset.py +26 -5
  54. geobox/usage.py +32 -1
  55. geobox/user.py +62 -6
  56. geobox/utils.py +34 -0
  57. geobox/vectorlayer.py +40 -4
  58. geobox/version.py +25 -1
  59. geobox/view.py +37 -17
  60. geobox/workflow.py +27 -1
  61. {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/METADATA +4 -1
  62. geobox-2.0.1.dist-info/RECORD +68 -0
  63. geobox-1.4.2.dist-info/RECORD +0 -38
  64. {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/WHEEL +0 -0
  65. {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/licenses/LICENSE +0 -0
  66. {geobox-1.4.2.dist-info → geobox-2.0.1.dist-info}/top_level.txt +0 -0
geobox/aio/tileset.py ADDED
@@ -0,0 +1,672 @@
1
+ from urllib.parse import urljoin
2
+ from typing import Dict, List, Optional, Union, TYPE_CHECKING
3
+
4
+ from .base import AsyncBase
5
+ from .vectorlayer import VectorLayer
6
+ from .view import VectorLayerView
7
+ from .task import Task
8
+
9
+ if TYPE_CHECKING:
10
+ from . import AsyncGeoboxClient
11
+ from .user import User
12
+ from ..api import GeoboxClient as SyncGeoboxClient
13
+ from ..tileset import Tileset as SyncTileset
14
+
15
+ class Tileset(AsyncBase):
16
+
17
+ BASE_ENDPOINT: str = 'tilesets/'
18
+
19
+ def __init__(self,
20
+ api: 'AsyncGeoboxClient',
21
+ uuid: str,
22
+ data: Optional[Dict] = {}):
23
+ """
24
+ Constructs all the necessary attributes for the Tilesets object.
25
+
26
+ Args:
27
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
28
+ uuid (str): The UUID of the tileset.
29
+ data (Dict, optional): The data of the tileset.
30
+ """
31
+ super().__init__(api=api, uuid=uuid, data=data)
32
+
33
+
34
+ @classmethod
35
+ async def create_tileset(cls, api: 'AsyncGeoboxClient', name: str, layers: List[Union['VectorLayer', 'VectorLayerView']], display_name: str = None, description: str = None,
36
+ min_zoom: int = None, max_zoom: int = None, user_id: int = None) -> 'Tileset':
37
+ """
38
+ [async] Create a new tileset.
39
+
40
+ Args:
41
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
42
+ name (str): The name of the tileset.
43
+ layers (List[VectorLayer | VectorLayerView]): list of vectorlayer and view objects to add to tileset.
44
+ display_name (str, optional): The display name of the tileset.
45
+ description (str, optional): The description of the tileset.
46
+ min_zoom (int, optional): The minimum zoom level of the tileset.
47
+ max_zoom (int, optional): The maximum zoom level of the tileset.
48
+ user_id (int, optional): Specific user. privileges required.
49
+
50
+ Returns:
51
+ Tileset: The created tileset instance.
52
+
53
+ Example:
54
+ >>> from geobox.aio import AsyncGeoboxClient
55
+ >>> from geobox.aio.tileset import Tileset
56
+ >>> async with AsyncGeoboxClient() as client:
57
+ >>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
58
+ >>> view = await client.get_view(uuid="12345678-1234-5678-1234-567812345678")
59
+ >>> tileset = await Tileset.create_tileset(client,
60
+ ... name="your_tileset_name",
61
+ ... display_name="Your Tileset",
62
+ ... description="Your description",
63
+ ... min_zoom=0,
64
+ ... max_zoom=14,
65
+ ... layers=[layer, view])
66
+ or
67
+ >>> tileset = await client.create_tileset(name="your_tileset_name",
68
+ ... display_name="Your Tileset",
69
+ ... description="Your description",
70
+ ... min_zoom=0,
71
+ ... max_zoom=14,
72
+ ... layers=[layer, view])
73
+ """
74
+ formatted_layers = []
75
+ for item in layers:
76
+ if type(item) == VectorLayer:
77
+ item_type = 'vector'
78
+
79
+ elif type(item) == VectorLayerView:
80
+ item_type = 'view'
81
+
82
+ else:
83
+ continue
84
+
85
+ formatted_layers.append({
86
+ 'layer_type': item_type,
87
+ 'layer_uuid': item.uuid
88
+ })
89
+
90
+ data = {
91
+ "name": name,
92
+ "display_name": display_name,
93
+ "description": description,
94
+ "min_zoom": min_zoom,
95
+ "max_zoom": max_zoom,
96
+ "layers": formatted_layers,
97
+ "user_id": user_id
98
+ }
99
+ return await super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Tileset(api, item['uuid'], item))
100
+
101
+
102
+ @classmethod
103
+ async def get_tilesets(cls, api: 'AsyncGeoboxClient', **kwargs) -> Union[List['Tileset'], int]:
104
+ """
105
+ [async] Retrieves a list of tilesets.
106
+
107
+ Args:
108
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
109
+
110
+ Keyword Args:
111
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
112
+ search (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.
113
+ search_fields (str): comma separated list of fields for searching.
114
+ 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.
115
+ return_count (bool): if True, returns the total number of tilesets matching the query. default is False.
116
+ skip (int): number of records to skip. default is 0.
117
+ limit (int): number of records to return. default is 10.
118
+ user_id (int): Specific user. privileges required.
119
+ shared (bool): Whether to return shared tilesets. default is False.
120
+
121
+ Returns:
122
+ List[Tileset] | int: A list of Tileset instances or the total number of tilesets
123
+
124
+ Example:
125
+ >>> from geobox.aio import AsyncGeoboxClient
126
+ >>> from geobox.aio.tileset import Tileset
127
+ >>> async with AsyncGeoboxClient() as client:
128
+ >>> tilesets = await Tileset.get_tilesets(client,
129
+ ... q="name LIKE '%your_tileset_name%'",
130
+ ... order_by="name A",
131
+ ... skip=0,
132
+ ... limit=10,
133
+ ... )
134
+ or
135
+ >>> tilesets = await client.get_tilesets(q="name LIKE '%your_tileset_name%'",
136
+ ... order_by="name A",
137
+ ... skip=0,
138
+ ... limit=10,
139
+ ... )
140
+ """
141
+ params = {
142
+ 'f': 'json',
143
+ 'q': kwargs.get('q', None),
144
+ 'search': kwargs.get('search', None),
145
+ 'search_fields': kwargs.get('search_fields', None),
146
+ 'order_by': kwargs.get('order_by', None),
147
+ 'return_count': kwargs.get('return_count', False),
148
+ 'skip': kwargs.get('skip', 0),
149
+ 'limit': kwargs.get('limit', 10),
150
+ 'user_id': kwargs.get('user_id', None),
151
+ 'shared': kwargs.get('shared', False)
152
+ }
153
+ return await super()._get_list(api=api, endpoint=cls.BASE_ENDPOINT, params=params, factory_func=lambda api, item: Tileset(api, item['uuid'], item))
154
+
155
+
156
+ @classmethod
157
+ async def get_tilesets_by_ids(cls, api: 'AsyncGeoboxClient', ids: List[str], user_id: int = None) -> List['Tileset']:
158
+ """
159
+ [async] Retrieves a list of tilesets by their IDs.
160
+
161
+ Args:
162
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
163
+ ids (List[str]): The list of tileset IDs.
164
+ user_id (int, optional): Specific user. privileges required.
165
+
166
+ Returns:
167
+ List[Tileset]: A list of Tileset instances.
168
+
169
+ Example:
170
+ >>> from geobox.aio import AsyncGeoboxClient
171
+ >>> from geobox.aio.tileset import Tileset
172
+ >>> async with AsyncGeoboxClient() as client:
173
+ >>> tilesets = await Tileset.get_tilesets_by_ids(client, ids=['123', '456'])
174
+ or
175
+ >>> tilesets = await client.get_tilesets_by_ids(ids=['123', '456'])
176
+ """
177
+ params = {
178
+ 'ids': ids,
179
+ 'user_id': user_id
180
+ }
181
+ return await super()._get_list_by_ids(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Tileset(api, item['uuid'], item))
182
+
183
+
184
+ @classmethod
185
+ async def get_tileset(cls, api: 'AsyncGeoboxClient', uuid: str) -> 'Tileset':
186
+ """
187
+ [async] Retrieves a tileset by its UUID.
188
+
189
+ Args:
190
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
191
+ uuid (str): The UUID of the tileset.
192
+
193
+ Returns:
194
+ Tileset: The retrieved tileset instance.
195
+
196
+ Example:
197
+ >>> from geobox.aio import AsyncGeoboxClient
198
+ >>> from geobox.aio.tileset import Tileset
199
+ >>> async with AsyncGeoboxClient() as client:
200
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
201
+ or
202
+ >>> tileset = await client.get_tileset(uuid="12345678-1234-5678-1234-567812345678")
203
+ """
204
+ return await super()._get_detail(api, cls.BASE_ENDPOINT, uuid, factory_func=lambda api, item: Tileset(api, item['uuid'], item))
205
+
206
+
207
+ @classmethod
208
+ async def get_tileset_by_name(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> Union['Tileset', None]:
209
+ """
210
+ [async] Get a tileset by name
211
+
212
+ Args:
213
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
214
+ name (str): the name of the tileset to get
215
+ user_id (int, optional): specific user. privileges required.
216
+
217
+ Returns:
218
+ Tileset | None: returns the tileset if a tileset matches the given name, else None
219
+
220
+ Example:
221
+ >>> from geobox.aio import AsyncGeoboxClient
222
+ >>> from geobox.aio.tileset import Tileset
223
+ >>> async with AsyncGeoboxClient() as client:
224
+ >>> tileset = await VectorLayer.get_tileset_by_name(client, name='test')
225
+ or
226
+ >>> tileset = await client.get_tileset_by_name(name='test')
227
+ """
228
+ tilesets = await cls.get_tilesets(api, q=f"name = '{name}'", user_id=user_id)
229
+ if tilesets and tilesets[0].name == name:
230
+ return tilesets[0]
231
+ else:
232
+ return None
233
+
234
+
235
+ async def update(self, **kwargs) -> None:
236
+ """
237
+ [async] Updates the properties of the tileset.
238
+
239
+ Keyword Args:
240
+ name (str): The new name of the tileset.
241
+ display_name (str): The new display name of the tileset.
242
+ description (str): The new description of the tileset.
243
+ min_zoom (int): The new minimum zoom level of the tileset.
244
+ max_zoom (int): The new maximum zoom level of the tileset.
245
+
246
+ Returns:
247
+ None
248
+
249
+ Example:
250
+ >>> from geobox.aio import AsyncGeoboxClient
251
+ >>> from geobox.aio.tileset import Tileset
252
+ >>> async with AsyncGeoboxClient() as client:
253
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
254
+ >>> await tileset.update_tileset(
255
+ ... name="new_name",
256
+ ... display_name="New Display Name",
257
+ ... description="New description",
258
+ ... min_zoom=0,
259
+ ... max_zoom=14
260
+ ... )
261
+ """
262
+ data = {
263
+ "name": kwargs.get('name'),
264
+ "display_name": kwargs.get('display_name'),
265
+ "description": kwargs.get('description'),
266
+ "min_zoom": kwargs.get('min_zoom'),
267
+ "max_zoom": kwargs.get('max_zoom')
268
+ }
269
+
270
+ return await super()._update(urljoin(self.BASE_ENDPOINT, f'{self.uuid}/'), data)
271
+
272
+
273
+ async def delete(self) -> None:
274
+ """
275
+ [async] Deletes the tileset.
276
+
277
+ Raises:
278
+ ValueError: if the tileset uuid is not set.
279
+
280
+ Returns:
281
+ None
282
+
283
+ Example:
284
+ >>> from geobox.aio import AsyncGeoboxClient
285
+ >>> from geobox.aio.tileset import Tileset
286
+ >>> async with AsyncGeoboxClient() as client:
287
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
288
+ >>> await tileset.delete()
289
+ """
290
+ await super().delete(urljoin(self.BASE_ENDPOINT, f'{self.uuid}/'))
291
+
292
+
293
+ async def get_layers(self, **kwargs) -> List['VectorLayer']:
294
+ """
295
+ [async] Retrieves the layers of the tileset with optional parameters.
296
+
297
+ Keyword Args:
298
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
299
+ search (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.
300
+ search_fields (str): comma separated list of fields for searching.
301
+ 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.
302
+ return_count (bool): if True, returns the total number of layers matching the query. default is False.
303
+ skip (int): number of records to skip. default is 0.
304
+ limit (int): number of records to return. default is 10.
305
+ user_id (int): specific user. privileges required.
306
+ shared (bool): if True, returns only the layers that has been shared with you. default is False.
307
+
308
+ Returns:
309
+ List: A list of VectorLayer instances.
310
+
311
+ Raises:
312
+ ApiRequestError: If the API request fails.
313
+
314
+ Example:
315
+
316
+ Returns:
317
+ List: A list of VectorLayer or VectorLayerView instances.
318
+
319
+ Example:
320
+ >>> from geobox.aio import AsyncGeoboxClient
321
+ >>> from geobox.aio.tileset import Tileset
322
+ >>> async with AsyncGeoboxClient() as client:
323
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
324
+ >>> layers = await tileset.get_layers()
325
+ """
326
+ params = {
327
+ 'f': 'json',
328
+ 'q': kwargs.get('q'),
329
+ 'search': kwargs.get('search'),
330
+ 'seacrh_fields': kwargs.get('seacrh_fields'),
331
+ 'order_by': kwargs.get('order_by'),
332
+ 'return_count': kwargs.get('return_count', False),
333
+ 'skip': kwargs.get('skip', 0),
334
+ 'limit': kwargs.get('limit', 10),
335
+ 'user_id': kwargs.get('user_id'),
336
+ 'shared': kwargs.get('shared', False)
337
+ }
338
+ endpoint = urljoin(self.BASE_ENDPOINT, f'{self.uuid}/layers/')
339
+ return await super()._get_list(self.api, endpoint, params, factory_func=lambda api, item: VectorLayer(api, item['uuid'], item['layer_type'], item) if not item['is_view'] else \
340
+ VectorLayerView(api, item['uuid'], item['layer_type'], item) )
341
+
342
+
343
+ async def add_layer(self, layer: Union['VectorLayer', 'VectorLayerView']) -> None:
344
+ """
345
+ [async] Adds a layer to the tileset.
346
+
347
+ Args:
348
+ layer (VectorLayer | VectorLayerView): the layer object to add to the tileset
349
+
350
+ Returns:
351
+ None
352
+
353
+ Raises:
354
+ ValueError: if the layer input is not a 'VectorLayer' or 'VetorLayerview' object
355
+
356
+ Example:
357
+ >>> from geobox.aio import AsyncGeoboxClient
358
+ >>> from geobox.aio.tileset import Tileset
359
+ >>> async with AsyncGeoboxClient() as client:
360
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
361
+ >>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
362
+ >>> await tileset.add_layer(layer)
363
+ """
364
+ if type(layer) == VectorLayer:
365
+ layer_type = 'vector'
366
+
367
+ elif type(layer) == VectorLayerView:
368
+ layer_type = 'view'
369
+
370
+ else:
371
+ raise ValueError("layer input must be either 'VectorLayer' or 'VetorLayerview' object")
372
+
373
+ data = {
374
+ "layer_type": layer_type,
375
+ "layer_uuid": layer.uuid
376
+ }
377
+
378
+ endpoint = urljoin(self.endpoint, 'layers/')
379
+ return await self.api.post(endpoint, data, is_json=False)
380
+
381
+
382
+ async def delete_layer(self, layer: Union['VectorLayer', 'VectorLayerView']) -> None:
383
+ """
384
+ [async] Deletes a layer from the tileset.
385
+
386
+ Args:
387
+ layer (VectorLayer | VectorLayerView): the layer object to delete from the tileset
388
+
389
+ Returns:
390
+ None
391
+
392
+ Raises:
393
+ ValueError: if the layer input is not a 'VectorLayer' or 'VetorLayerview' object
394
+
395
+ Example:
396
+ >>> from geobox.aio import AsyncGeoboxClient
397
+ >>> from geobox.aio.tileset import Tileset
398
+ >>> async with AsyncGeoboxClient() as client:
399
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
400
+ >>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
401
+ >>> await tileset.delete_layer(layer)
402
+ """
403
+ if type(layer) == VectorLayer:
404
+ layer_type = 'vector'
405
+
406
+ elif type(layer) == VectorLayerView:
407
+ layer_type = 'view'
408
+
409
+ else:
410
+ raise ValueError("layer input must be either 'VectorLayer' or 'VetorLayerview' object")
411
+
412
+ data = {
413
+ "layer_type": layer_type,
414
+ "layer_uuid": layer.uuid
415
+ }
416
+
417
+ endpoint = urljoin(self.endpoint, 'layers/')
418
+ return await self.api.delete(endpoint, data, is_json=False)
419
+
420
+
421
+ async def share(self, users: List['User']) -> None:
422
+ """
423
+ [async] Shares the file with specified users.
424
+
425
+ Args:
426
+ users (List[User]): The list of user IDs to share the file with.
427
+
428
+ Returns:
429
+ None
430
+
431
+ Example:
432
+ >>> from geobox.aio import AsyncGeoboxClient
433
+ >>> from geobox.aio.tileset import Tileset
434
+ >>> async with AsyncGeoboxClient() as client:
435
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
436
+ >>> users = await client.search_usesrs(search='John')
437
+ >>> await tileset.share(users=users)
438
+ """
439
+ await super()._share(self.endpoint, users)
440
+
441
+
442
+ async def unshare(self, users: List['User']) -> None:
443
+ """
444
+ [async] Unshares the file with specified users.
445
+
446
+ Args:
447
+ users (List[User]): The list of user IDs to unshare the file with.
448
+
449
+ Returns:
450
+ None
451
+
452
+ Example:
453
+ >>> from geobox.aio import AsyncGeoboxClient
454
+ >>> from geobox.aio.tileset import Tileset
455
+ >>> async with AsyncGeoboxClient() as client:
456
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
457
+ >>> users = await client.search_usesrs(search='John')
458
+ >>> await tileset.unshare(users=users)
459
+ """
460
+ await super()._unshare(self.endpoint, users)
461
+
462
+
463
+ async def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
464
+ """
465
+ [async] Retrieves the list of users the file is shared with.
466
+
467
+ Args:
468
+ search (str, optional): The search query.
469
+ skip (int, optional): The number of users to skip.
470
+ limit (int, optional): The maximum number of users to retrieve.
471
+
472
+ Returns:
473
+ List[User]: The list of shared users.
474
+
475
+ Example:
476
+ >>> from geobox.aio import AsyncGeoboxClient
477
+ >>> from geobox.aio.tileset import Tileset
478
+ >>> async with AsyncGeoboxClient() as client:
479
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
480
+ >>> await tileset.get_shared_users(search='John', skip=0, limit=10)
481
+ """
482
+ params = {
483
+ 'search': search,
484
+ 'skip': skip,
485
+ 'limit': limit
486
+ }
487
+ return await super()._get_shared_users(self.endpoint, params)
488
+
489
+
490
+ async def get_tile_json(self) -> Dict:
491
+ """
492
+ [async] Retrieves the tile JSON configuration.
493
+
494
+ Returns:
495
+ Dict: The tile JSON configuration.
496
+
497
+ Example:
498
+ >>> from geobox.aio import AsyncGeoboxClient
499
+ >>> from geobox.aio.tileset import Tileset
500
+ >>> async with AsyncGeoboxClient() as client:
501
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
502
+ >>> await tileset.get_tile_json()
503
+ """
504
+ endpoint = urljoin(self.endpoint, 'tilejson.json/')
505
+ return await self.api.get(endpoint)
506
+
507
+
508
+ async def update_tileset_extent(self) -> Dict:
509
+ """
510
+ [async] Updates the extent of the tileset.
511
+
512
+ Returns:
513
+ Dict: The response from the API.
514
+
515
+ Example:
516
+ >>> from geobox.aio import AsyncGeoboxClient
517
+ >>> from geobox.aio.tileset import Tileset
518
+ >>> async with AsyncGeoboxClient() as client:
519
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
520
+ >>> await tileset.update_tileset_extent()
521
+ """
522
+ endpoint = urljoin(self.endpoint, 'updateExtent/')
523
+ return await self.api.post(endpoint)
524
+
525
+
526
+ def get_tile_pbf_url(self, x: 'int' = '{x}', y: int = '{y}', z: int = '{z}') -> str:
527
+ """
528
+ Retrieves a tile from the tileset.
529
+
530
+ Args:
531
+ x (int, optional): The x coordinate of the tile.
532
+ y (int, optioanl): The y coordinate of the tile.
533
+ z (int, optional): The zoom level of the tile.
534
+
535
+ Returns:
536
+ str: The url of the tile.
537
+
538
+ Example:
539
+ >>> from geobox.aio import AsyncGeoboxClient
540
+ >>> from geobox.aio.tileset import Tileset
541
+ >>> async with AsyncGeoboxClient() as client:
542
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
543
+ >>> await tileset.get_tile_tileset(x=1, y=1, z=1)
544
+ """
545
+ endpoint = f'{self.api.base_url}{self.endpoint}tiles/{z}/{x}/{y}.pbf'
546
+
547
+ if not self.api.access_token and self.api.apikey:
548
+ endpoint = f'{endpoint}?apikey={self.api.apikey}'
549
+
550
+ return endpoint
551
+
552
+
553
+ async def seed_cache(self, from_zoom: int = 0, to_zoom: int = 14, extent: list = [], workers: int = 1, user_id: int = 0) -> List['Task']:
554
+ """
555
+ [async] Seeds the cache of the tileset.
556
+
557
+ Args:
558
+ from_zoom (int, optional): The starting zoom level.
559
+ to_zoom (int, optional): The ending zoom level.
560
+ extent (list, optional): The extent of the tileset.
561
+ workers (int, optional): The number of workers to use.
562
+ user_id (int, optional): The user ID.
563
+
564
+ Returns:
565
+ List[Task]: list of task objects.
566
+
567
+ Raises:
568
+ ValueError: If the number of workers is not one of the following: 1, 2, 4, 8, 12, 16, 20, 24.
569
+
570
+ Example:
571
+ >>> from geobox.aio import AsyncGeoboxClient
572
+ >>> from geobox.aio.tileset import Tileset
573
+ >>> async with AsyncGeoboxClient() as client:
574
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
575
+ >>> await tileset.seed_cache(from_zoom=0, to_zoom=14, extent=[], workers=1)
576
+ """
577
+ data = {
578
+ "from_zoom": from_zoom,
579
+ "to_zoom": to_zoom,
580
+ "extent": extent,
581
+ "workers": workers,
582
+ "user_id": user_id
583
+ }
584
+ return await super()._seed_cache(endpoint=self.endpoint, data=data)
585
+
586
+
587
+ async def update_cache(self, from_zoom: int, to_zoom: int, extents: List[List[float]] = None, user_id: int = 0) -> List['Task']:
588
+ """
589
+ [async] Updates the cache of the tileset.
590
+
591
+ Args:
592
+ from_zoom (int): The starting zoom level.
593
+ to_zoom (int): The ending zoom level.
594
+ extents (List[List[float]], optional): The list of extents to update the cache for.
595
+ user_id (int, optional): The user ID.
596
+
597
+ Returns:
598
+ List[Task]: list of task objects.
599
+
600
+ Example:
601
+ >>> from geobox.aio import AsyncGeoboxClient
602
+ >>> from geobox.aio.tileset import Tileset
603
+ >>> async with AsyncGeoboxClient() as client:
604
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
605
+ >>> await tileset.update_cache(from_zoom=0, to_zoom=14, extent=[])
606
+ """
607
+ data = {
608
+ "from_zoom": from_zoom,
609
+ "to_zoom": to_zoom,
610
+ "extents": extents,
611
+ "user_id": user_id
612
+ }
613
+ return await super()._update_cache(endpoint=self.endpoint, data=data)
614
+
615
+
616
+ @property
617
+ async def cache_size(self) -> int:
618
+ """
619
+ [async] Retrieves the size of the cache of the tileset.
620
+
621
+ Returns:
622
+ int: The size of the cache of the tileset.
623
+
624
+ Example:
625
+ >>> from geobox.aio import AsyncGeoboxClient
626
+ >>> from geobox.aio.tileset import Tileset
627
+ >>> async with AsyncGeoboxClient() as client:
628
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
629
+ >>> await tileset.cache_size
630
+ """
631
+ return await super()._cache_size(endpoint=self.endpoint)
632
+
633
+
634
+ async def clear_cache(self) -> None:
635
+ """
636
+ [async] Clears the cache of the tileset.
637
+
638
+ Returns:
639
+ None
640
+
641
+ Example:
642
+ >>> from geobox.aio import AsyncGeoboxClient
643
+ >>> from geobox.aio.tileset import Tileset
644
+ >>> async with AsyncGeoboxClient() as client:
645
+ >>> tileset = await Tileset.get_tileset(client, uuid="12345678-1234-5678-1234-567812345678")
646
+ >>> await tileset.clear_cache()
647
+ """
648
+ await super()._clear_cache(endpoint=self.endpoint)
649
+
650
+
651
+ def to_sync(self, sync_client: 'SyncGeoboxClient') -> 'SyncTileset':
652
+ """
653
+ Switch to sync version of the tileset instance to have access to the sync methods
654
+
655
+ Args:
656
+ sync_client (SyncGeoboxClient): The sync version of the GeoboxClient instance for making requests.
657
+
658
+ Returns:
659
+ geobox.tileset.Tileset: the sync instance of the tileset.
660
+
661
+ Example:
662
+ >>> from geobox import Geoboxclient
663
+ >>> from geobox.aio import AsyncGeoboxClient
664
+ >>> from geobox.aio.tileset import Tileset
665
+ >>> client = GeoboxClient()
666
+ >>> async with AsyncGeoboxClient() as async_client:
667
+ >>> tileset = await Tileset.get_tileset(async_client, uuid="12345678-1234-5678-1234-567812345678")
668
+ >>> sync_tileset = tileset.to_sync(client)
669
+ """
670
+ from ..tileset import Tileset as SyncTileset
671
+
672
+ return SyncTileset(api=sync_client, uuid=self.uuid, data=self.data)