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