pygeobox 1.0.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.
- pygeobox/__init__.py +63 -0
- pygeobox/api.py +2518 -0
- pygeobox/apikey.py +233 -0
- pygeobox/attachment.py +298 -0
- pygeobox/base.py +364 -0
- pygeobox/basemap.py +163 -0
- pygeobox/dashboard.py +316 -0
- pygeobox/enums.py +355 -0
- pygeobox/exception.py +47 -0
- pygeobox/feature.py +508 -0
- pygeobox/field.py +309 -0
- pygeobox/file.py +494 -0
- pygeobox/log.py +101 -0
- pygeobox/map.py +858 -0
- pygeobox/model3d.py +334 -0
- pygeobox/mosaic.py +647 -0
- pygeobox/plan.py +261 -0
- pygeobox/query.py +668 -0
- pygeobox/raster.py +756 -0
- pygeobox/route.py +63 -0
- pygeobox/scene.py +317 -0
- pygeobox/settings.py +166 -0
- pygeobox/task.py +354 -0
- pygeobox/tile3d.py +295 -0
- pygeobox/tileset.py +585 -0
- pygeobox/usage.py +211 -0
- pygeobox/user.py +424 -0
- pygeobox/utils.py +44 -0
- pygeobox/vectorlayer.py +1150 -0
- pygeobox/version.py +249 -0
- pygeobox/view.py +859 -0
- pygeobox/workflow.py +315 -0
- pygeobox-1.0.0.dist-info/METADATA +106 -0
- pygeobox-1.0.0.dist-info/RECORD +37 -0
- pygeobox-1.0.0.dist-info/WHEEL +5 -0
- pygeobox-1.0.0.dist-info/licenses/LICENSE +21 -0
- pygeobox-1.0.0.dist-info/top_level.txt +1 -0
pygeobox/task.py
ADDED
@@ -0,0 +1,354 @@
|
|
1
|
+
from urllib.parse import urljoin, urlencode
|
2
|
+
from typing import Optional, Dict, List, Optional, Union, TYPE_CHECKING
|
3
|
+
import time
|
4
|
+
|
5
|
+
from .base import Base
|
6
|
+
from .enums import TaskStatus
|
7
|
+
|
8
|
+
if TYPE_CHECKING:
|
9
|
+
from . import GeoboxClient
|
10
|
+
from .vectorlayer import VectorLayer
|
11
|
+
from .raster import Raster
|
12
|
+
from .model3d import Model
|
13
|
+
|
14
|
+
class Task(Base):
|
15
|
+
"""
|
16
|
+
A class to represent a task in Geobox.
|
17
|
+
|
18
|
+
This class provides functionality to interact with tasks in Geobox.
|
19
|
+
It supports various operations including getting tasks, as well as advanced operations like waiting for a task to finish.
|
20
|
+
It also provides properties to access the task data, and a method to abort the task.
|
21
|
+
"""
|
22
|
+
BASE_ENDPOINT: str = 'tasks/'
|
23
|
+
|
24
|
+
def __init__(self,
|
25
|
+
api: 'GeoboxClient',
|
26
|
+
uuid: str,
|
27
|
+
data: Optional[Dict] = {}):
|
28
|
+
"""
|
29
|
+
Constructs all the necessary attributes for the Task object.
|
30
|
+
|
31
|
+
Args:
|
32
|
+
api (GeoboxClient): The API instance.
|
33
|
+
uuid (str): The UUID of the task.
|
34
|
+
data (Dict, optional): The task data.
|
35
|
+
"""
|
36
|
+
super().__init__(api, uuid=uuid, data=data)
|
37
|
+
self._data = data if isinstance(data, dict) else {}
|
38
|
+
|
39
|
+
|
40
|
+
def refresh_data(self) -> None:
|
41
|
+
"""
|
42
|
+
Updates the task data.
|
43
|
+
"""
|
44
|
+
self._data = self.get_task(self.api, self.uuid).data
|
45
|
+
|
46
|
+
|
47
|
+
@property
|
48
|
+
def publised_asset(self) -> Union['VectorLayer', 'Raster', 'Model', None]:
|
49
|
+
"""
|
50
|
+
Published asset property
|
51
|
+
|
52
|
+
Returns:
|
53
|
+
VectorLayer | Raster | Model | None: if task type is publish, it returns the published layer
|
54
|
+
|
55
|
+
Example:
|
56
|
+
>>> from geobox import GeoboxClient
|
57
|
+
>>> from geobox.task import Task
|
58
|
+
>>> client = GeoboxClient()
|
59
|
+
>>> task = Task.get_task(client, uuid="12345678-1234-5678-1234-567812345678")
|
60
|
+
>>> task.publised_asset
|
61
|
+
"""
|
62
|
+
if self.name == 'import:publish-file-to-raster-dataset':
|
63
|
+
return self.api.get_raster(uuid=self.data['result']['raster_uuid'])
|
64
|
+
elif self.name == 'import:publish-file-to-vector-layer':
|
65
|
+
return self.api.get_vector(uuid=self.data['result']['layer_uuid'])
|
66
|
+
elif self.name == 'import:publish-file-to-3d-model':
|
67
|
+
return self.api.get_model(uuid=self.data['result']['model_uuid'])
|
68
|
+
else:
|
69
|
+
return None
|
70
|
+
|
71
|
+
|
72
|
+
@property
|
73
|
+
def data(self) -> Dict:
|
74
|
+
"""
|
75
|
+
Returns the task data.
|
76
|
+
|
77
|
+
Returns:
|
78
|
+
Dict: the task data as a dictionary
|
79
|
+
|
80
|
+
Example:
|
81
|
+
>>> from geobox import GeoboxClient
|
82
|
+
>>> from geobox.task import Task
|
83
|
+
>>> client = GeoboxClient()
|
84
|
+
>>> task = Task.get_task(client, uuid="12345678-1234-5678-1234-567812345678")
|
85
|
+
>>> task.data
|
86
|
+
"""
|
87
|
+
return self._data
|
88
|
+
|
89
|
+
|
90
|
+
@data.setter
|
91
|
+
def data(self, value: Dict) -> None:
|
92
|
+
"""
|
93
|
+
Sets the task data.
|
94
|
+
|
95
|
+
Example:
|
96
|
+
>>> from geobox import GeoboxClient
|
97
|
+
>>> from geobox.task import Task
|
98
|
+
>>> client = GeoboxClient()
|
99
|
+
>>> task = Task.get_task(client, uuid="12345678-1234-5678-1234-567812345678")
|
100
|
+
>>> task.data = {'name': 'test'}
|
101
|
+
"""
|
102
|
+
self._data = value if isinstance(value, dict) else {}
|
103
|
+
|
104
|
+
|
105
|
+
@property
|
106
|
+
def status(self) -> 'TaskStatus':
|
107
|
+
"""
|
108
|
+
Returns the status of the task. (auto refresh)
|
109
|
+
|
110
|
+
Returns:
|
111
|
+
TaskStatus: the status of the task(SUCCESS, FAILURE, ABORTED, PENDING, PROGRESS)
|
112
|
+
|
113
|
+
Example:
|
114
|
+
>>> from geobox import GeoboxClient
|
115
|
+
>>> from geobox.task import Task
|
116
|
+
>>> client = GeoboxClient()
|
117
|
+
>>> task = Task.get_task(client, uuid="12345678-1234-5678-1234-567812345678")
|
118
|
+
>>> task.status
|
119
|
+
"""
|
120
|
+
self.refresh_data()
|
121
|
+
return TaskStatus(self._data.get('state'))
|
122
|
+
|
123
|
+
|
124
|
+
@property
|
125
|
+
def errors(self) -> Union[Dict, None]:
|
126
|
+
"""
|
127
|
+
Get the task errors.
|
128
|
+
|
129
|
+
Returns:
|
130
|
+
Dict | None: if there are any errors
|
131
|
+
|
132
|
+
Example:
|
133
|
+
>>> from geobox import GeoboxClient
|
134
|
+
>>> from geobox.task import Task
|
135
|
+
>>> client = GeoboxClient()
|
136
|
+
>>> task = Task.get_task(client, uuid="12345678-1234-5678-1234-567812345678")
|
137
|
+
>>> task.errors
|
138
|
+
"""
|
139
|
+
result = self.data.get('result', {})
|
140
|
+
if result.get('errors') or result.get('detail', {}).get('msg'):
|
141
|
+
return result
|
142
|
+
else:
|
143
|
+
return None
|
144
|
+
|
145
|
+
|
146
|
+
@property
|
147
|
+
def progress(self) -> Union[int, None]:
|
148
|
+
"""
|
149
|
+
Returns the progress of the task.
|
150
|
+
|
151
|
+
Returns:
|
152
|
+
int | None: the progress of the task in percentage or None if the task is not running
|
153
|
+
|
154
|
+
Example:
|
155
|
+
>>> from geobox import GeoboxClient
|
156
|
+
>>> from geobox.task import Task
|
157
|
+
>>> client = GeoboxClient()
|
158
|
+
>>> task = Task.get_task(client, uuid="12345678-1234-5678-1234-567812345678")
|
159
|
+
>>> task.progress
|
160
|
+
"""
|
161
|
+
endpoint = urljoin(self.endpoint, 'status/')
|
162
|
+
response = self.api.get(endpoint)
|
163
|
+
|
164
|
+
current = response.get('current')
|
165
|
+
total = response.get('total')
|
166
|
+
if not total or not current:
|
167
|
+
return None
|
168
|
+
|
169
|
+
return int((current / total) * 100)
|
170
|
+
|
171
|
+
|
172
|
+
def wait(self, timeout: Union[int, None] = None, interval: int = 1, progress_bar: bool = True) -> 'TaskStatus':
|
173
|
+
"""
|
174
|
+
Wait for the task to finish.
|
175
|
+
|
176
|
+
Args:
|
177
|
+
timeout (int, optional): Maximum time to wait in seconds.
|
178
|
+
interval (int, optional): Time between status checks in seconds.
|
179
|
+
progress_bar (bool, optional): Whether to show a progress bar. default: True
|
180
|
+
|
181
|
+
Returns:
|
182
|
+
TaskStatus: the status of the task(SUCCESS, FAILURE, ABORTED, PENDING, PROGRESS)
|
183
|
+
|
184
|
+
Raises:
|
185
|
+
TimeoutError: If the task doesn't complete within timeout seconds.
|
186
|
+
|
187
|
+
Example:
|
188
|
+
>>> from geobox import GeoboxClient
|
189
|
+
>>> from geobox.task import Task
|
190
|
+
>>> client = GeoboxClient()
|
191
|
+
>>> task = Task.get_task(client, uuid="12345678-1234-5678-1234-567812345678")
|
192
|
+
>>> task.wait() # return the status of the task
|
193
|
+
"""
|
194
|
+
start_time = time.time()
|
195
|
+
last_progress = 0
|
196
|
+
pbar = self._create_progress_bar() if progress_bar else None
|
197
|
+
|
198
|
+
try:
|
199
|
+
while True:
|
200
|
+
self._check_timeout(start_time, timeout)
|
201
|
+
status = self.status
|
202
|
+
|
203
|
+
if self._is_final_state(status):
|
204
|
+
self._update_progress_bar(pbar, last_progress, status)
|
205
|
+
return TaskStatus(status)
|
206
|
+
|
207
|
+
if pbar:
|
208
|
+
last_progress = self._update_progress_bar(pbar, last_progress)
|
209
|
+
|
210
|
+
time.sleep(interval)
|
211
|
+
finally:
|
212
|
+
if pbar:
|
213
|
+
pbar.close()
|
214
|
+
|
215
|
+
|
216
|
+
def _create_progress_bar(self) -> 'tqdm':
|
217
|
+
"""Creates a progress bar for the task."""
|
218
|
+
try:
|
219
|
+
from tqdm.auto import tqdm
|
220
|
+
except ImportError:
|
221
|
+
from .api import logger
|
222
|
+
logger.warning("[tqdm] extra is required to show the progress bar. install with: pip insatll pygeobox[tqdm]")
|
223
|
+
return None
|
224
|
+
|
225
|
+
return tqdm(total=100, colour='green', desc=f"Task: {self.name}", unit="%", leave=True)
|
226
|
+
|
227
|
+
|
228
|
+
def _check_timeout(self, start_time: float, timeout: Union[int, None]) -> None:
|
229
|
+
"""Checks if the task has exceeded the timeout period."""
|
230
|
+
if timeout and time.time() - start_time > timeout:
|
231
|
+
raise TimeoutError(f"Task {self.name} timed out after {timeout} seconds")
|
232
|
+
|
233
|
+
|
234
|
+
def _is_final_state(self, status: 'TaskStatus') -> bool:
|
235
|
+
"""Checks if the task has reached a final state."""
|
236
|
+
return status in [TaskStatus.FAILURE, TaskStatus.SUCCESS, TaskStatus.ABORTED]
|
237
|
+
|
238
|
+
|
239
|
+
def _update_progress_bar(self, pbar: Union['tqdm', None], last_progress: int, status: 'TaskStatus' = None) -> int:
|
240
|
+
"""
|
241
|
+
Updates the progress bar with current progress and returns the new last_progress.
|
242
|
+
|
243
|
+
Args:
|
244
|
+
pbar (tqdm | None): The progress bar to update
|
245
|
+
last_progress (int): The last progress value
|
246
|
+
status (TaskStatus, optional): The task status. If provided and SUCCESS, updates to 100%
|
247
|
+
|
248
|
+
Returns:
|
249
|
+
int: The new last_progress value
|
250
|
+
"""
|
251
|
+
if not pbar:
|
252
|
+
return last_progress
|
253
|
+
|
254
|
+
if status == TaskStatus.SUCCESS:
|
255
|
+
pbar.update(100 - last_progress)
|
256
|
+
return 100
|
257
|
+
|
258
|
+
current_progress = self.progress
|
259
|
+
if current_progress is not None:
|
260
|
+
progress_diff = current_progress - last_progress
|
261
|
+
if progress_diff > 0:
|
262
|
+
pbar.update(progress_diff)
|
263
|
+
return current_progress
|
264
|
+
return last_progress
|
265
|
+
|
266
|
+
|
267
|
+
def abort(self) -> None:
|
268
|
+
"""
|
269
|
+
Aborts the task.
|
270
|
+
|
271
|
+
Returns:
|
272
|
+
None
|
273
|
+
|
274
|
+
Example:
|
275
|
+
>>> from geobox import GeoboxClient
|
276
|
+
>>> from geobox.task import Task
|
277
|
+
>>> client = GeoboxClient()
|
278
|
+
>>> task = Task.get_task(client, uuid="12345678-1234-5678-1234-567812345678")
|
279
|
+
>>> task.abort()
|
280
|
+
"""
|
281
|
+
endpoint = urljoin(self.endpoint, 'abort/')
|
282
|
+
self.api.post(endpoint)
|
283
|
+
|
284
|
+
|
285
|
+
@classmethod
|
286
|
+
def get_tasks(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Task'], int]:
|
287
|
+
"""
|
288
|
+
Get a list of tasks
|
289
|
+
|
290
|
+
Args:
|
291
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
292
|
+
|
293
|
+
Keyword Args:
|
294
|
+
state (TaskStatus): Available values : TaskStatus.PENDING, TaskStatus.PROGRESS, TaskStatus.SUCCESS, TaskStatus.FAILURE, TaskStatus.ABORTED
|
295
|
+
q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
|
296
|
+
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.
|
297
|
+
search_fields (str): comma separated list of fields for searching.
|
298
|
+
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.
|
299
|
+
return_count (bool): The count of the tasks. default is False.
|
300
|
+
skip (int): The skip of the task. default is 0.
|
301
|
+
limit (int): The limit of the task. default is 10.
|
302
|
+
user_id (int): Specific user. privileges required.
|
303
|
+
shared (bool): Whether to return shared tasks. default is False.
|
304
|
+
|
305
|
+
Returns:
|
306
|
+
List[Task] | int: The list of task objects or the count of the tasks if return_count is True.
|
307
|
+
|
308
|
+
Example:
|
309
|
+
>>> from geobox import GeoboxClient
|
310
|
+
>>> from geobox.task import Task
|
311
|
+
>>> client = GeoboxClient()
|
312
|
+
>>> tasks = Task.get_tasks(client)
|
313
|
+
or
|
314
|
+
>>> tasks = client.get_tasks()
|
315
|
+
"""
|
316
|
+
params = {
|
317
|
+
'f': 'json',
|
318
|
+
'state': kwargs.get('state').value if kwargs.get('state') else None,
|
319
|
+
'q': kwargs.get('q'),
|
320
|
+
'search': kwargs.get('search'),
|
321
|
+
'search_fields': kwargs.get('search_fields'),
|
322
|
+
'order_by': kwargs.get('order_by'),
|
323
|
+
'return_count': kwargs.get('return_count', False),
|
324
|
+
'skip': kwargs.get('skip'),
|
325
|
+
'limit': kwargs.get('limit'),
|
326
|
+
'user_id': kwargs.get('user_id'),
|
327
|
+
'shared': kwargs.get('shared', False)
|
328
|
+
}
|
329
|
+
return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Task(api, item['uuid'], item))
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
@classmethod
|
334
|
+
def get_task(cls, api: 'GeoboxClient', uuid: str) -> 'Task':
|
335
|
+
"""
|
336
|
+
Gets a task.
|
337
|
+
|
338
|
+
Args:
|
339
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
340
|
+
uuid (str): The UUID of the task.
|
341
|
+
|
342
|
+
Returns:
|
343
|
+
Task: The task object.
|
344
|
+
|
345
|
+
Example:
|
346
|
+
>>> from geobox import GeoboxClient
|
347
|
+
>>> from geobox.task import Task
|
348
|
+
>>> client = GeoboxClient()
|
349
|
+
>>> task = Task.get_task(client, uuid="12345678-1234-5678-1234-567812345678")
|
350
|
+
or
|
351
|
+
>>> task = client.get_task(uuid="12345678-1234-5678-1234-567812345678")
|
352
|
+
"""
|
353
|
+
return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, factory_func=lambda api, item: Task(api, item['uuid'], item))
|
354
|
+
|
pygeobox/tile3d.py
ADDED
@@ -0,0 +1,295 @@
|
|
1
|
+
from typing import List, Dict, Optional, TYPE_CHECKING, Union
|
2
|
+
from urllib.parse import urljoin
|
3
|
+
|
4
|
+
from .base import Base
|
5
|
+
|
6
|
+
if TYPE_CHECKING:
|
7
|
+
from . import GeoboxClient
|
8
|
+
|
9
|
+
|
10
|
+
class Tile3d(Base):
|
11
|
+
|
12
|
+
BASE_ENDPOINT = '3dtiles/'
|
13
|
+
|
14
|
+
def __init__(self,
|
15
|
+
api: 'GeoboxClient',
|
16
|
+
uuid: str,
|
17
|
+
data: Optional[Dict] = {}):
|
18
|
+
"""
|
19
|
+
Initialize a 3D Tile instance.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
23
|
+
name (str): The name of the 3D Tile.
|
24
|
+
uuid (str): The unique identifier for the 3D Tile.
|
25
|
+
data (Dict): The data of the 3D Tile.
|
26
|
+
"""
|
27
|
+
super().__init__(api, uuid=uuid, data=data)
|
28
|
+
|
29
|
+
|
30
|
+
@classmethod
|
31
|
+
def get_3dtiles(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Tile3d'], int]:
|
32
|
+
"""
|
33
|
+
Get list of 3D Tiles with optional filtering and pagination.
|
34
|
+
|
35
|
+
Args:
|
36
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
37
|
+
|
38
|
+
Keyword Args:
|
39
|
+
q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
|
40
|
+
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.
|
41
|
+
search_fields (str): comma separated list of fields for searching.
|
42
|
+
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.
|
43
|
+
return_count (bool): Whether to return total count. default is False.
|
44
|
+
skip (int): Number of items to skip. default is 0.
|
45
|
+
limit (int): Number of items to return. default is 10.
|
46
|
+
user_id (int): Specific user. privileges required.
|
47
|
+
shared (bool): Whether to return shared maps. default is False.
|
48
|
+
|
49
|
+
Returns:
|
50
|
+
List[Tile3d] | int: A list of 3D Tile instances or the total number of 3D Tiles.
|
51
|
+
|
52
|
+
Example:
|
53
|
+
>>> from geobox import GeoboxClient
|
54
|
+
>>> from geobox.tile3d import Tile3d
|
55
|
+
>>> client = GeoboxClient()
|
56
|
+
>>> tiles = Tile3d.get_3dtiles(client, q="name LIKE '%My tile%'")
|
57
|
+
or
|
58
|
+
>>> tiles = client.get_3dtiles(q="name LIKE '%My tile%'")
|
59
|
+
"""
|
60
|
+
params = {
|
61
|
+
'f': 'json',
|
62
|
+
'q': kwargs.get('q'),
|
63
|
+
'search': kwargs.get('search'),
|
64
|
+
'search_fields': kwargs.get('search_fields'),
|
65
|
+
'order_by': kwargs.get('order_by'),
|
66
|
+
'return_count': kwargs.get('return_count', False),
|
67
|
+
'skip': kwargs.get('skip', 0),
|
68
|
+
'limit': kwargs.get('limit', 10),
|
69
|
+
'user_id': kwargs.get('user_id'),
|
70
|
+
'shared': kwargs.get('shared', False)
|
71
|
+
}
|
72
|
+
return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Tile3d(api, item['uuid'], item))
|
73
|
+
|
74
|
+
|
75
|
+
@classmethod
|
76
|
+
def get_3dtile(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Tile3d':
|
77
|
+
"""
|
78
|
+
Get a 3D Tile by its UUID.
|
79
|
+
|
80
|
+
Args:
|
81
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
82
|
+
uuid (str): The UUID of the map to 3D Tile.
|
83
|
+
user_id (int): Specific user. privileges required.
|
84
|
+
|
85
|
+
Returns:
|
86
|
+
Tile3d: The 3D Tile object.
|
87
|
+
|
88
|
+
Raises:
|
89
|
+
NotFoundError: If the 3D Tile with the specified UUID is not found.
|
90
|
+
|
91
|
+
Example:
|
92
|
+
>>> from geobox import GeoboxClient
|
93
|
+
>>> from geobox.tile3d import Tile3d
|
94
|
+
>>> client = GeoboxClient()
|
95
|
+
>>> tile = Tile3d.get_3dtile(client, uuid="12345678-1234-5678-1234-567812345678")
|
96
|
+
or
|
97
|
+
>>> tile = client.get_3dtile(uuid="12345678-1234-5678-1234-567812345678")
|
98
|
+
"""
|
99
|
+
params = {
|
100
|
+
'f': 'json',
|
101
|
+
'user_id': user_id,
|
102
|
+
}
|
103
|
+
return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Tile3d(api, item['uuid'], item))
|
104
|
+
|
105
|
+
|
106
|
+
@classmethod
|
107
|
+
def get_3dtile_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Tile3d', None]:
|
108
|
+
"""
|
109
|
+
Get a 3dtile by name
|
110
|
+
|
111
|
+
Args:
|
112
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
113
|
+
name (str): the name of the 3dtile to get
|
114
|
+
user_id (int, optional): specific user. privileges required.
|
115
|
+
|
116
|
+
Returns:
|
117
|
+
Tile3d | None: returns the 3dtile if a 3dtile matches the given name, else None
|
118
|
+
|
119
|
+
Example:
|
120
|
+
>>> from geobox import GeoboxClient
|
121
|
+
>>> from geobox.tile3d import Tile3d
|
122
|
+
>>> client = GeoboxClient()
|
123
|
+
>>> tile3d = Tile3d.get_3dtile_by_name(client, name='test')
|
124
|
+
or
|
125
|
+
>>> tile3d = client.get_3dtile_by_name(name='test')
|
126
|
+
"""
|
127
|
+
tile3ds = cls.get_3dtiles(api, q=f"name = '{name}'", user_id=user_id)
|
128
|
+
if tile3ds and tile3ds[0].name == name:
|
129
|
+
return tile3ds[0]
|
130
|
+
else:
|
131
|
+
return None
|
132
|
+
|
133
|
+
|
134
|
+
def update(self, **kwargs) -> Dict:
|
135
|
+
"""
|
136
|
+
Update the 3D Tile.
|
137
|
+
|
138
|
+
Keyword Args:
|
139
|
+
name (str): The name of the 3D Tile.
|
140
|
+
display_name (str): The display name of the 3D Tile.
|
141
|
+
description (str): The description of the 3D Tile.
|
142
|
+
settings (Dict): The settings of the 3D Tile.
|
143
|
+
thumbnail (str): The thumbnail of the 3D Tile.
|
144
|
+
|
145
|
+
Returns:
|
146
|
+
Dict: The updated 3D Tile data.
|
147
|
+
|
148
|
+
Raises:
|
149
|
+
ApiRequestError: If the API request fails.
|
150
|
+
ValidationError: If the 3D Tile data is invalid.
|
151
|
+
|
152
|
+
Example:
|
153
|
+
>>> from geobox import GeoboxClient
|
154
|
+
>>> from geobox.tile3d import Tile3d
|
155
|
+
>>> client = GeoboxClient()
|
156
|
+
>>> tile = Tile3d.get_3dtile(client, uuid="12345678-1234-5678-1234-567812345678")
|
157
|
+
>>> tile.update_3dtile(display_name="New Display Name")
|
158
|
+
"""
|
159
|
+
data = {
|
160
|
+
"name": kwargs.get('name'),
|
161
|
+
"display_name": kwargs.get('display_name'),
|
162
|
+
"description": kwargs.get('description'),
|
163
|
+
"settings": kwargs.get('settings'),
|
164
|
+
"thumbnail": kwargs.get('thumbnail'),
|
165
|
+
}
|
166
|
+
return super()._update(self.endpoint, data)
|
167
|
+
|
168
|
+
|
169
|
+
def delete(self) -> None:
|
170
|
+
"""
|
171
|
+
Delete the 3D Tile.
|
172
|
+
|
173
|
+
Returns:
|
174
|
+
None
|
175
|
+
|
176
|
+
Example:
|
177
|
+
>>> from geobox import GeoboxClient
|
178
|
+
>>> from geobox.tile3d import Tile3d
|
179
|
+
>>> client = GeoboxClient()
|
180
|
+
>>> tile = Map.get_3dtile(client, uuid="12345678-1234-5678-1234-567812345678")
|
181
|
+
>>> tile.delete()
|
182
|
+
"""
|
183
|
+
super().delete(self.endpoint)
|
184
|
+
|
185
|
+
|
186
|
+
@property
|
187
|
+
def thumbnail(self) -> str:
|
188
|
+
"""
|
189
|
+
Get the thumbnail URL of the 3D Tile.
|
190
|
+
|
191
|
+
Returns:
|
192
|
+
str: The thumbnail url of the 3D Tile.
|
193
|
+
|
194
|
+
Example:
|
195
|
+
>>> from geobox import GeoboxClient
|
196
|
+
>>> from geobox.tile3d import Tile3d
|
197
|
+
>>> client = GeoboxClient()
|
198
|
+
>>> tile = Tile3d.get_3dtile(client, uuid="12345678-1234-5678-1234-567812345678")
|
199
|
+
>>> tile.thumbnail
|
200
|
+
'https://example.com/thumbnail.png'
|
201
|
+
"""
|
202
|
+
endpoint = urljoin(self.api.base_url, f'{self.endpoint}thumbnail.png')
|
203
|
+
return endpoint
|
204
|
+
|
205
|
+
|
206
|
+
def get_item(self, path: str) -> Dict:
|
207
|
+
"""
|
208
|
+
Get an Item from 3D Tiles
|
209
|
+
|
210
|
+
Args:
|
211
|
+
path (str): the path of the item.
|
212
|
+
|
213
|
+
Returns:
|
214
|
+
Dict: the data of the item.
|
215
|
+
|
216
|
+
Example:
|
217
|
+
>>> from geobox imoprt GeoboxClient
|
218
|
+
>>> from geobox.tile3d import Tile3d
|
219
|
+
>>> client = GeoboxClient()
|
220
|
+
>>> tile = Tile3d.get_3dtile(client, uuid="12345678-1234-5678-1234-567812345678")
|
221
|
+
or
|
222
|
+
>>> tile = client.get_3dtile(uuid="12345678-1234-5678-1234-567812345678")
|
223
|
+
>>> item = tile.get_item()
|
224
|
+
"""
|
225
|
+
endpoint = f"{self.endpoint}{path}"
|
226
|
+
return self.api.get(endpoint)
|
227
|
+
|
228
|
+
|
229
|
+
def share(self, users: List['User']) -> None:
|
230
|
+
"""
|
231
|
+
Shares the 3D Tile with specified users.
|
232
|
+
|
233
|
+
Args:
|
234
|
+
users (List[User]): The list of user objects to share the 3D Tile with.
|
235
|
+
|
236
|
+
Returns:
|
237
|
+
None
|
238
|
+
|
239
|
+
Example:
|
240
|
+
>>> from geobox import GeoboxClient
|
241
|
+
>>> from geobox.tile3d import Tile3d
|
242
|
+
>>> client = GeoboxClient()
|
243
|
+
>>> tile = Tile3d.get_3dtile(client, uuid="12345678-1234-5678-1234-567812345678")
|
244
|
+
>>> users = client.search_users(search='John')
|
245
|
+
>>> tile.share(users=users)
|
246
|
+
"""
|
247
|
+
super()._share(self.endpoint, users)
|
248
|
+
|
249
|
+
|
250
|
+
def unshare(self, users: List['User']) -> None:
|
251
|
+
"""
|
252
|
+
Unshares the 3D Tile with specified users.
|
253
|
+
|
254
|
+
Args:
|
255
|
+
users (List[User]): The list of user objects to unshare the 3D Tile with.
|
256
|
+
|
257
|
+
Returns:
|
258
|
+
None
|
259
|
+
|
260
|
+
Example:
|
261
|
+
>>> from geobox import GeoboxClient
|
262
|
+
>>> from geobox.tile3d import Tile3d
|
263
|
+
>>> client = GeoboxClient()
|
264
|
+
>>> tile = Tile3d.get_3dtile(client, uuid="12345678-1234-5678-1234-567812345678")
|
265
|
+
>>> users = client.search_users(search='John')
|
266
|
+
>>> tile.unshare(users=users)
|
267
|
+
"""
|
268
|
+
super()._unshare(self.endpoint, users)
|
269
|
+
|
270
|
+
|
271
|
+
def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
|
272
|
+
"""
|
273
|
+
Retrieves the list of users the 3D Tile is shared with.
|
274
|
+
|
275
|
+
Args:
|
276
|
+
search (str, optional): The search query.
|
277
|
+
skip (int, optional): The number of users to skip.
|
278
|
+
limit (int, optional): The maximum number of users to retrieve.
|
279
|
+
|
280
|
+
Returns:
|
281
|
+
List[User]: The list of shared users.
|
282
|
+
|
283
|
+
Example:
|
284
|
+
>>> from geobox import GeoboxClient
|
285
|
+
>>> from geobox.tile3d import Tile3d
|
286
|
+
>>> client = GeoboxClient()
|
287
|
+
>>> tile = Tile3d.get_3dtile(client, uuid="12345678-1234-5678-1234-567812345678")
|
288
|
+
>>> tile.get_shared_users(search='John', skip=0, limit=10)
|
289
|
+
"""
|
290
|
+
params = {
|
291
|
+
'search': search,
|
292
|
+
'skip': skip,
|
293
|
+
'limit': limit
|
294
|
+
}
|
295
|
+
return super()._get_shared_users(self.endpoint, params)
|