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/raster.py
ADDED
@@ -0,0 +1,756 @@
|
|
1
|
+
import os
|
2
|
+
from urllib.parse import urljoin, urlencode
|
3
|
+
from typing import Optional, Dict, List, Optional, Union, TYPE_CHECKING
|
4
|
+
import mimetypes
|
5
|
+
import requests
|
6
|
+
|
7
|
+
from .base import Base
|
8
|
+
from .utils import clean_data
|
9
|
+
from .task import Task
|
10
|
+
|
11
|
+
if TYPE_CHECKING:
|
12
|
+
from . import GeoboxClient
|
13
|
+
from .user import User
|
14
|
+
|
15
|
+
class Raster(Base):
|
16
|
+
"""
|
17
|
+
A class to represent a Raster in Geobox.
|
18
|
+
|
19
|
+
This class provides functionality to interact with rasters in Geobox.
|
20
|
+
It supports various operations including CRUD operations on rasters, as well as advanced operations like getting statistics, points, and tiles.
|
21
|
+
It also provides properties to access the raster data, and a method to download the raster.
|
22
|
+
"""
|
23
|
+
BASE_ENDPOINT: str = 'rasters/'
|
24
|
+
|
25
|
+
def __init__(self,
|
26
|
+
api: 'GeoboxClient',
|
27
|
+
uuid: str,
|
28
|
+
data: Optional[Dict] = {}):
|
29
|
+
"""
|
30
|
+
Constructs all the necessary attributes for the Raster object.
|
31
|
+
|
32
|
+
Args:
|
33
|
+
api (GeoboxClient): The API instance.
|
34
|
+
uuid (str): The UUID of the raster.
|
35
|
+
data (Dict, optional): The raster data.
|
36
|
+
"""
|
37
|
+
super().__init__(api, uuid=uuid, data=data)
|
38
|
+
|
39
|
+
|
40
|
+
@classmethod
|
41
|
+
def get_rasters(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Raster'], int]:
|
42
|
+
"""
|
43
|
+
Get all rasters.
|
44
|
+
|
45
|
+
Args:
|
46
|
+
api (GeoboxClient): The API instance.
|
47
|
+
|
48
|
+
Keyword Args:
|
49
|
+
terrain (bool): whether to get terrain rasters.
|
50
|
+
q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
|
51
|
+
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.
|
52
|
+
search_fields (str): comma separated list of fields for searching
|
53
|
+
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.
|
54
|
+
return_count (bool): whether to return the total count of rasters. default is False.
|
55
|
+
skip (int): number of rasters to skip. minimum is 0.
|
56
|
+
limit (int): number of rasters to return. minimum is 1.
|
57
|
+
user_id (int): user id to show the rasters of the user. privileges required.
|
58
|
+
shared (bool): whether to return shared rasters. default is False.
|
59
|
+
|
60
|
+
Returns:
|
61
|
+
List[Raster] | int: A list of Raster objects or the total count of rasters.
|
62
|
+
|
63
|
+
Example:
|
64
|
+
>>> from geobox import GeoboxClient
|
65
|
+
>>> from geobox.raster import Raster
|
66
|
+
>>> client = GeoboxClient()
|
67
|
+
>>> rasters = Raster.get_rasters(client, terrain=True, q="name LIKE '%GIS%'")
|
68
|
+
or
|
69
|
+
>>> rasters = client.get_rasters(terrain=True, q="name LIKE '%GIS%'")
|
70
|
+
"""
|
71
|
+
params = {
|
72
|
+
'terrain': kwargs.get('terrain', None),
|
73
|
+
'f': 'json',
|
74
|
+
'q': kwargs.get('q', None),
|
75
|
+
'search': kwargs.get('search', None),
|
76
|
+
'search_fields': kwargs.get('search_fields', None),
|
77
|
+
'order_by': kwargs.get('order_by', None),
|
78
|
+
'return_count': kwargs.get('return_count', False),
|
79
|
+
'skip': kwargs.get('skip', 0),
|
80
|
+
'limit': kwargs.get('limit', 100),
|
81
|
+
'user_id': kwargs.get('user_id', None),
|
82
|
+
'shared': kwargs.get('shared', False)
|
83
|
+
}
|
84
|
+
return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Raster(api, item['uuid'], item))
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
@classmethod
|
89
|
+
def get_rasters_by_ids(cls, api: 'GeoboxClient', ids: List[str], user_id: int = None) -> List['Raster']:
|
90
|
+
"""
|
91
|
+
Get rasters by their IDs.
|
92
|
+
|
93
|
+
Args:
|
94
|
+
api (GeoboxClient): The API instance.
|
95
|
+
ids (List[str]): The IDs of the rasters.
|
96
|
+
user_id (int, optional): specific user. privileges required.
|
97
|
+
|
98
|
+
Returns:
|
99
|
+
List['Raster']: A list of Raster objects.
|
100
|
+
|
101
|
+
Example:
|
102
|
+
>>> from geobox import GeoboxClient
|
103
|
+
>>> from geobox.raster import Raster
|
104
|
+
>>> client = GeoboxClient()
|
105
|
+
>>> rasters = Raster.get_rasters_by_ids(client, ids=['123', '456'])
|
106
|
+
or
|
107
|
+
>>> rasters = client.get_rasters_by_ids(ids=['123', '456'])
|
108
|
+
"""
|
109
|
+
params = {
|
110
|
+
'ids': ids,
|
111
|
+
'user_id': user_id,
|
112
|
+
}
|
113
|
+
endpoint = urljoin(cls.BASE_ENDPOINT, 'get-rasters/')
|
114
|
+
|
115
|
+
return super()._get_list_by_ids(api, endpoint, params, factory_func=lambda api, item: Raster(api, item['uuid'], item))
|
116
|
+
|
117
|
+
|
118
|
+
@classmethod
|
119
|
+
def get_raster(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Raster':
|
120
|
+
"""
|
121
|
+
Get a raster by its UUID.
|
122
|
+
|
123
|
+
Args:
|
124
|
+
api (GeoboxClient): The API instance.
|
125
|
+
uuid (str): The UUID of the raster.
|
126
|
+
user_id (int, optional): specific user. privileges required.
|
127
|
+
|
128
|
+
Returns:
|
129
|
+
Raster: A Raster object.
|
130
|
+
|
131
|
+
Example:
|
132
|
+
>>> from geobox import GeoboxClient
|
133
|
+
>>> from geobox.raster import Raster
|
134
|
+
>>> client = GeoboxClient()
|
135
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
136
|
+
or
|
137
|
+
>>> raster = client.get_raster(uuid="12345678-1234-5678-1234-567812345678")
|
138
|
+
"""
|
139
|
+
params = {
|
140
|
+
'f': 'json',
|
141
|
+
'user_id': user_id
|
142
|
+
}
|
143
|
+
return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Raster(api, item['uuid'], item))
|
144
|
+
|
145
|
+
|
146
|
+
@classmethod
|
147
|
+
def get_raster_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Raster', None]:
|
148
|
+
"""
|
149
|
+
Get a raster by name
|
150
|
+
|
151
|
+
Args:
|
152
|
+
api (GeoboxClient): The GeoboxClient instance for making requests.
|
153
|
+
name (str): the name of the raster to get
|
154
|
+
user_id (int, optional): specific user. privileges required.
|
155
|
+
|
156
|
+
Returns:
|
157
|
+
Raster | None: returns the raster if a raster matches the given name, else None
|
158
|
+
|
159
|
+
Example:
|
160
|
+
>>> from geobox import GeoboxClient
|
161
|
+
>>> from geobox.raster import Raster
|
162
|
+
>>> client = GeoboxClient()
|
163
|
+
>>> raster = Raster.get_raster_by_name(client, name='test')
|
164
|
+
or
|
165
|
+
>>> raster = client.get_raster_by_name(name='test')
|
166
|
+
"""
|
167
|
+
rasters = cls.get_rasters(api, q=f"name = '{name}'", user_id=user_id)
|
168
|
+
if rasters and rasters[0].name == name:
|
169
|
+
return rasters[0]
|
170
|
+
else:
|
171
|
+
return None
|
172
|
+
|
173
|
+
|
174
|
+
def update(self, **kwargs) -> None:
|
175
|
+
"""
|
176
|
+
Update the raster.
|
177
|
+
|
178
|
+
Keyword Args:
|
179
|
+
name (str): The name of the raster.
|
180
|
+
display_name (str): The display name of the raster.
|
181
|
+
description (str): The description of the raster.
|
182
|
+
max_zoom (int): The max zoom of the raster.
|
183
|
+
|
184
|
+
Returns:
|
185
|
+
None
|
186
|
+
|
187
|
+
Example:
|
188
|
+
>>> from geobox import GeoboxClient
|
189
|
+
>>> from geobox.raster import Raster
|
190
|
+
>>> client = GeoboxClient()
|
191
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
192
|
+
>>> raster.update(name="new_name")
|
193
|
+
"""
|
194
|
+
params = {
|
195
|
+
'name': kwargs.get('name'),
|
196
|
+
'display_name': kwargs.get('display_name'),
|
197
|
+
'description': kwargs.get('description'),
|
198
|
+
'max_zoom': kwargs.get('max_zoom'),
|
199
|
+
}
|
200
|
+
super()._update(self.endpoint, params)
|
201
|
+
|
202
|
+
|
203
|
+
def delete(self) -> None:
|
204
|
+
"""
|
205
|
+
Delete the raster.
|
206
|
+
|
207
|
+
Returns:
|
208
|
+
None
|
209
|
+
|
210
|
+
Example:
|
211
|
+
>>> from geobox import GeoboxClient
|
212
|
+
>>> from geobox.raster import Raster
|
213
|
+
>>> client = GeoboxClient()
|
214
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
215
|
+
>>> raster.delete()
|
216
|
+
"""
|
217
|
+
super().delete(self.endpoint)
|
218
|
+
|
219
|
+
|
220
|
+
@property
|
221
|
+
def thumbnail(self) -> str:
|
222
|
+
"""
|
223
|
+
Get the thumbnail of the raster.
|
224
|
+
|
225
|
+
Returns:
|
226
|
+
str: The url of the thumbnail.
|
227
|
+
|
228
|
+
Example:
|
229
|
+
>>> from geobox import GeoboxClient
|
230
|
+
>>> from geobox.raster import Raster
|
231
|
+
>>> client = GeoboxClient()
|
232
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
233
|
+
>>> raster.thumbnail
|
234
|
+
"""
|
235
|
+
endpoint = urljoin(self.api.base_url, f'{self.endpoint}thumbnail/')
|
236
|
+
return endpoint
|
237
|
+
|
238
|
+
|
239
|
+
def get_raster_info(self) -> Dict:
|
240
|
+
"""
|
241
|
+
Get the info of the raster.
|
242
|
+
|
243
|
+
Returns:
|
244
|
+
Dict: The info of the raster.
|
245
|
+
|
246
|
+
Example:
|
247
|
+
>>> from geobox import GeoboxClient
|
248
|
+
>>> from geobox.raster import Raster
|
249
|
+
>>> client = GeoboxClient()
|
250
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
251
|
+
>>> raster.get_raster_info()
|
252
|
+
"""
|
253
|
+
endpoint = urljoin(self.endpoint, 'info/')
|
254
|
+
return self.api.get(endpoint)
|
255
|
+
|
256
|
+
|
257
|
+
def get_statistics(self, indexes: str = None) -> Dict:
|
258
|
+
"""
|
259
|
+
Get the statistics of the raster.
|
260
|
+
|
261
|
+
Args:
|
262
|
+
indexes (str): list of comma separated band indexes. e.g. 1, 2, 3
|
263
|
+
|
264
|
+
Returns:
|
265
|
+
Dict: The statistics of the raster.
|
266
|
+
|
267
|
+
Example:
|
268
|
+
>>> from geobox import GeoboxClient
|
269
|
+
>>> from geobox.raster import Raster
|
270
|
+
>>> client = GeoboxClient()
|
271
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
272
|
+
>>> raster.get_statistics(indexes='1, 2, 3')
|
273
|
+
"""
|
274
|
+
params = clean_data({
|
275
|
+
'indexes': indexes,
|
276
|
+
})
|
277
|
+
query_string = urlencode(params)
|
278
|
+
endpoint = urljoin(self.endpoint, f'statistics/?{query_string}')
|
279
|
+
return self.api.get(endpoint)
|
280
|
+
|
281
|
+
|
282
|
+
def get_point(self, lat: float, lng: float) -> Dict:
|
283
|
+
"""
|
284
|
+
Get the point of the raster.
|
285
|
+
|
286
|
+
Args:
|
287
|
+
lat (float): The latitude of the point. minimum is -90, maximum is 90.
|
288
|
+
lng (float): The longitude of the point. minimum is -180, maximum is 180.
|
289
|
+
|
290
|
+
Returns:
|
291
|
+
Dict: The point of the raster.
|
292
|
+
|
293
|
+
Example:
|
294
|
+
>>> from geobox import GeoboxClient
|
295
|
+
>>> from geobox.raster import Raster
|
296
|
+
>>> client = GeoboxClient()
|
297
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
298
|
+
>>> raster.get_point(lat=60, lng=50)
|
299
|
+
"""
|
300
|
+
if lat < -90 or lat > 90:
|
301
|
+
raise ValueError("lat must be between -90 and 90")
|
302
|
+
if lng < -180 or lng > 180:
|
303
|
+
raise ValueError("lng must be between -180 and 180")
|
304
|
+
|
305
|
+
params = clean_data({
|
306
|
+
'lat': lat,
|
307
|
+
'lng': lng,
|
308
|
+
})
|
309
|
+
query_string = urlencode(params)
|
310
|
+
endpoint = urljoin(self.endpoint, f'point?{query_string}')
|
311
|
+
return self.api.get(endpoint)
|
312
|
+
|
313
|
+
|
314
|
+
def _get_save_path(self, save_path: str = None) -> str:
|
315
|
+
"""
|
316
|
+
Get the path where the file should be saved.
|
317
|
+
|
318
|
+
Args:
|
319
|
+
save_path (str, optional): The path to save the file.
|
320
|
+
|
321
|
+
Returns:
|
322
|
+
str: The path where the file is saved.
|
323
|
+
|
324
|
+
Raises:
|
325
|
+
ValueError: If save_path does not end with a '/'.
|
326
|
+
"""
|
327
|
+
# Get the original filename from data or use uuid
|
328
|
+
if self.name:
|
329
|
+
filename = f"{self.name.split('.')[0]}" if len(self.name.split('.')) > 1 else f'{self.name}'
|
330
|
+
else:
|
331
|
+
filename = f'{self.uuid}'
|
332
|
+
|
333
|
+
# If save_path is provided, check if it ends with a '/'
|
334
|
+
if save_path and save_path.endswith('/'):
|
335
|
+
return f'{save_path}{filename}'
|
336
|
+
|
337
|
+
if save_path and not save_path.endswith('/'):
|
338
|
+
raise ValueError("save_path must end with a '/'")
|
339
|
+
|
340
|
+
return os.path.join(os.getcwd(), filename)
|
341
|
+
|
342
|
+
|
343
|
+
def _get_file_ext(self, response: requests.Response) -> str:
|
344
|
+
"""
|
345
|
+
Get the file extension of the response.
|
346
|
+
|
347
|
+
Args:
|
348
|
+
response (requests.Response): The response of the request.
|
349
|
+
|
350
|
+
Returns:
|
351
|
+
str: The file extension of the response.
|
352
|
+
"""
|
353
|
+
ext = ""
|
354
|
+
if 'Content-Disposition' in response.headers and 'filename=' in response.headers['Content-Disposition']:
|
355
|
+
content_disposition = response.headers['Content-Disposition']
|
356
|
+
filename = content_disposition.split('filename=')[-1].strip().strip('"')
|
357
|
+
ext = f".{filename.split('.')[-1]}"
|
358
|
+
|
359
|
+
else:
|
360
|
+
content_type = response.headers.get("Content-Type", "")
|
361
|
+
ext = mimetypes.guess_extension(content_type.split(";")[0])
|
362
|
+
|
363
|
+
return ext
|
364
|
+
|
365
|
+
|
366
|
+
def download(self, save_path: str = None) -> str:
|
367
|
+
"""
|
368
|
+
Download the raster.
|
369
|
+
|
370
|
+
Args:
|
371
|
+
save_path (str): The path to save the raster.
|
372
|
+
|
373
|
+
Returns:
|
374
|
+
str: The path to save the raster.
|
375
|
+
|
376
|
+
Raises:
|
377
|
+
ValueError: If file_uuid is not set
|
378
|
+
OSError: If there are issues with file operations
|
379
|
+
|
380
|
+
Example:
|
381
|
+
>>> from geobox import GeoboxClient
|
382
|
+
>>> from geobox.raster import Raster
|
383
|
+
>>> client = GeoboxClient()
|
384
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
385
|
+
>>> raster.download(save_path="path/to/save/")
|
386
|
+
"""
|
387
|
+
if not self.uuid:
|
388
|
+
raise ValueError("Raster UUID is required to download the raster file")
|
389
|
+
|
390
|
+
save_path = self._get_save_path(save_path)
|
391
|
+
os.makedirs(os.path.dirname(save_path), exist_ok=True)
|
392
|
+
|
393
|
+
with self.api.get(f"{self.endpoint}download/", stream=True) as response, \
|
394
|
+
open(save_path, 'wb') as f:
|
395
|
+
for chunk in response.iter_content(chunk_size=8192):
|
396
|
+
f.write(chunk)
|
397
|
+
|
398
|
+
final_path = os.path.abspath(save_path) + self._get_file_ext(response)
|
399
|
+
os.rename(os.path.abspath(save_path), os.path.abspath(final_path))
|
400
|
+
return os.path.abspath(final_path)
|
401
|
+
|
402
|
+
|
403
|
+
def get_content_file(self, save_path: str = None) -> str:
|
404
|
+
"""
|
405
|
+
Get Raster Content URL
|
406
|
+
|
407
|
+
Args:
|
408
|
+
save_path (str): The path to save the raster.
|
409
|
+
|
410
|
+
Returns:
|
411
|
+
str: The path to save the raster.
|
412
|
+
|
413
|
+
Raises:
|
414
|
+
ValueError: If uuid is not set
|
415
|
+
OSError: If there are issues with file operations
|
416
|
+
|
417
|
+
Examples:
|
418
|
+
>>> from geobox import GeoboxClient
|
419
|
+
>>> from geobox.raster import Raster
|
420
|
+
>>> client = GeoboxClient()
|
421
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
422
|
+
>>> raster_tiff = raste.get_content_file()
|
423
|
+
"""
|
424
|
+
if not self.uuid:
|
425
|
+
raise ValueError("Raster UUID is required to download the raster content")
|
426
|
+
|
427
|
+
save_path = self._get_save_path(save_path)
|
428
|
+
os.makedirs(os.path.dirname(save_path), exist_ok=True)
|
429
|
+
|
430
|
+
with self.api.get(f"{self.endpoint}content/", stream=True) as response, \
|
431
|
+
open(save_path, 'wb') as f:
|
432
|
+
for chunk in response.iter_content(chunk_size=8192):
|
433
|
+
f.write(chunk)
|
434
|
+
|
435
|
+
final_path = os.path.abspath(save_path) + self._get_file_ext(response)
|
436
|
+
os.rename(os.path.abspath(save_path), os.path.abspath(final_path))
|
437
|
+
return os.path.abspath(final_path)
|
438
|
+
|
439
|
+
|
440
|
+
def get_tile_render_url(self, x: int, y: int, z: int) -> str:
|
441
|
+
"""
|
442
|
+
Get the PNG URL of the raster.
|
443
|
+
|
444
|
+
Args:
|
445
|
+
x (int): The x coordinate of the tile.
|
446
|
+
y (int): The y coordinate of the tile.
|
447
|
+
z (int): The zoom level of the tile.
|
448
|
+
|
449
|
+
Returns:
|
450
|
+
str: The PNG Render URL of the raster.
|
451
|
+
|
452
|
+
Example:
|
453
|
+
>>> from geobox import GeoboxClient
|
454
|
+
>>> from geobox.raster import Raster
|
455
|
+
>>> client = GeoboxClient()
|
456
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
457
|
+
>>> raster.get_tile_render_url(x=10, y=20, z=1)
|
458
|
+
"""
|
459
|
+
endpoint = urljoin(self.api.base_url, f'{self.endpoint}render/{z}/{x}/{y}.png')
|
460
|
+
return endpoint
|
461
|
+
|
462
|
+
|
463
|
+
def get_tile_pbf_url(self, x: int, y: int, z: int) -> str:
|
464
|
+
"""
|
465
|
+
Get the URL of the tile.
|
466
|
+
|
467
|
+
Args:
|
468
|
+
x (int): The x coordinate of the tile.
|
469
|
+
y (int): The y coordinate of the tile.
|
470
|
+
z (int): The zoom level of the tile.
|
471
|
+
|
472
|
+
Returns:
|
473
|
+
str: The URL of the tile.
|
474
|
+
|
475
|
+
Example:
|
476
|
+
>>> from geobox import GeoboxClient
|
477
|
+
>>> from geobox.raster import Raster
|
478
|
+
>>> client = GeoboxClient()
|
479
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
480
|
+
>>> raster.get_tile_pbf_url(x=10, y=20, z=1)
|
481
|
+
"""
|
482
|
+
endpoint = urljoin(self.api.base_url, f'{self.endpoint}tiles/{z}/{x}/{y}.pbf')
|
483
|
+
return endpoint
|
484
|
+
|
485
|
+
|
486
|
+
def get_tile_png_url(self, x: int, y: int, z: int) -> str:
|
487
|
+
"""
|
488
|
+
Get the URL of the tile.
|
489
|
+
|
490
|
+
Args:
|
491
|
+
x (int): The x coordinate of the tile.
|
492
|
+
y (int): The y coordinate of the tile.
|
493
|
+
z (int): The zoom level of the tile.
|
494
|
+
|
495
|
+
Returns:
|
496
|
+
str: The URL of the tile.
|
497
|
+
|
498
|
+
Example:
|
499
|
+
>>> from geobox import GeoboxClient
|
500
|
+
>>> from geobox.raster import Raster
|
501
|
+
>>> client = GeoboxClient()
|
502
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
503
|
+
>>> raster.get_tile_png_url(x=10, y=20, z=1)
|
504
|
+
"""
|
505
|
+
endpoint = urljoin(self.api.base_url, f'{self.endpoint}tiles/{z}/{x}/{y}.png')
|
506
|
+
return endpoint
|
507
|
+
|
508
|
+
|
509
|
+
def get_tile_json(self) -> Dict:
|
510
|
+
"""
|
511
|
+
Get the tile JSON of the raster.
|
512
|
+
|
513
|
+
Returns:
|
514
|
+
Dict: The tile JSON of the raster.
|
515
|
+
|
516
|
+
Example:
|
517
|
+
>>> from geobox import GeoboxClient
|
518
|
+
>>> from geobox.raster import Raster
|
519
|
+
>>> client = GeoboxClient()
|
520
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
521
|
+
>>> raster.get_tile_json()
|
522
|
+
"""
|
523
|
+
endpoint = urljoin(self.endpoint, 'tilejson.json')
|
524
|
+
return self.api.get(endpoint)
|
525
|
+
|
526
|
+
|
527
|
+
def wmts(self, scale: int = None) -> str:
|
528
|
+
"""
|
529
|
+
Get the WMTS URL
|
530
|
+
|
531
|
+
Args:
|
532
|
+
scale (int, optional): The scale of the raster. values are: 1, 2
|
533
|
+
|
534
|
+
Returns:
|
535
|
+
str: the raster WMTS URL
|
536
|
+
|
537
|
+
Example:
|
538
|
+
>>> from geobox import GeoboxClient
|
539
|
+
>>> from geobox.raster import Raster
|
540
|
+
>>> client = GeoboxClient()
|
541
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
542
|
+
>>> raster.wmts(scale=1)
|
543
|
+
"""
|
544
|
+
endpoint = urljoin(self.api.base_url, f'{self.endpoint}wmts/')
|
545
|
+
if scale:
|
546
|
+
endpoint = f"{endpoint}?scale={scale}"
|
547
|
+
return endpoint
|
548
|
+
|
549
|
+
|
550
|
+
@property
|
551
|
+
def settings(self) -> Dict:
|
552
|
+
"""
|
553
|
+
Get the settings of the raster.
|
554
|
+
|
555
|
+
Returns:
|
556
|
+
Dict: The settings of the raster.
|
557
|
+
|
558
|
+
Example:
|
559
|
+
>>> from geobox import GeoboxClient
|
560
|
+
>>> from geobox.raster import Raster
|
561
|
+
>>> client = GeoboxClient()
|
562
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
563
|
+
>>> raster.settings
|
564
|
+
"""
|
565
|
+
return super()._get_settings(self.endpoint)
|
566
|
+
|
567
|
+
|
568
|
+
def set_settings(self, **kwargs) -> None:
|
569
|
+
"""
|
570
|
+
Set the settings of the raster.
|
571
|
+
|
572
|
+
Keyword Args:
|
573
|
+
nodata (int): The nodata value of the raster.
|
574
|
+
indexes (list[int]): The indexes of the raster.
|
575
|
+
rescale (list[int]): The rescale of the raster.
|
576
|
+
colormap_name (str): The colormap name of the raster.
|
577
|
+
color_formula (str): The color formula of the raster.
|
578
|
+
expression (str): The expression of the raster.
|
579
|
+
exaggeraion (int): The exaggeraion of the raster.
|
580
|
+
min_zoom (int): The min zoom of the raster.
|
581
|
+
max_zoom (int): The max zoom of the raster.
|
582
|
+
use_cache (bool): Whether to use cache of the raster.
|
583
|
+
cache_until_zoom (int): The cache until zoom of the raster.
|
584
|
+
|
585
|
+
|
586
|
+
Example:
|
587
|
+
>>> from geobox import GeoboxClient
|
588
|
+
>>> from geobox.raster import Raster
|
589
|
+
>>> client = GeoboxClient()
|
590
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
591
|
+
>>> raster.set_settings(nodata=0,
|
592
|
+
... indexes=[1],
|
593
|
+
... rescale=[[0, 10000]],
|
594
|
+
... colormap_name='gist_rainbow',
|
595
|
+
... color_formula='Gamma R 0.5',
|
596
|
+
... expression='b1 * 2',
|
597
|
+
... exaggeraion=10,
|
598
|
+
... min_zoom=0,
|
599
|
+
... max_zoom=22,
|
600
|
+
... use_cache=True,
|
601
|
+
... cache_until_zoom=17)
|
602
|
+
"""
|
603
|
+
visual_settings = {
|
604
|
+
'nodata', 'indexes', 'rescale', 'colormap_name',
|
605
|
+
'color_formula', 'expression', 'exaggeraion'
|
606
|
+
}
|
607
|
+
tile_settings = {
|
608
|
+
'min_zoom', 'max_zoom', 'use_cache', 'cache_until_zoom'
|
609
|
+
}
|
610
|
+
|
611
|
+
settings = {
|
612
|
+
'visual_settings': {},
|
613
|
+
'tile_settings': {}
|
614
|
+
}
|
615
|
+
|
616
|
+
for key, value in kwargs.items():
|
617
|
+
if key in visual_settings:
|
618
|
+
settings['visual_settings'][key] = value
|
619
|
+
elif key in tile_settings:
|
620
|
+
settings['tile_settings'][key] = value
|
621
|
+
|
622
|
+
|
623
|
+
super()._set_settings(self.endpoint, settings)
|
624
|
+
|
625
|
+
|
626
|
+
def share(self, users: List['User']) -> None:
|
627
|
+
"""
|
628
|
+
Shares the raster with specified users.
|
629
|
+
|
630
|
+
Args:
|
631
|
+
users (List[User]): The list of user objects to share the raster with.
|
632
|
+
|
633
|
+
Returns:
|
634
|
+
None
|
635
|
+
|
636
|
+
Example:
|
637
|
+
>>> from geobox import GeoboxClient
|
638
|
+
>>> from geobox.raster import Raster
|
639
|
+
>>> client = GeoboxClient()
|
640
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
641
|
+
>>> users = client.search_users(search="John")
|
642
|
+
>>> raster.share(users=users)
|
643
|
+
"""
|
644
|
+
super()._share(self.endpoint, users)
|
645
|
+
|
646
|
+
|
647
|
+
def unshare(self, users: List['User']) -> None:
|
648
|
+
"""
|
649
|
+
Unshares the raster with specified users.
|
650
|
+
|
651
|
+
Args:
|
652
|
+
users (List[User]): The list of user objects to unshare the raster with.
|
653
|
+
|
654
|
+
Returns:
|
655
|
+
None
|
656
|
+
|
657
|
+
Example:
|
658
|
+
>>> from geobox import GeoboxClient
|
659
|
+
>>> from geobox.raster import Raster
|
660
|
+
>>> client = GeoboxClient()
|
661
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
662
|
+
>>> users = client.search_users(search="John")
|
663
|
+
>>> raster.unshare(users=users)
|
664
|
+
"""
|
665
|
+
super()._unshare(self.endpoint, users)
|
666
|
+
|
667
|
+
|
668
|
+
def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
|
669
|
+
"""
|
670
|
+
Retrieves the list of users the raster is shared with.
|
671
|
+
|
672
|
+
Args:
|
673
|
+
search (str, optional): The search query.
|
674
|
+
skip (int, optional): The number of users to skip.
|
675
|
+
limit (int, optional): The maximum number of users to retrieve.
|
676
|
+
|
677
|
+
Returns:
|
678
|
+
List[User]: The list of shared users.
|
679
|
+
|
680
|
+
Example:
|
681
|
+
>>> from geobox import GeoboxClient
|
682
|
+
>>> from geobox.raster import Raster
|
683
|
+
>>> client = GeoboxClient()
|
684
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
685
|
+
>>> raster.get_shared_users(search='John', skip=0, limit=10)
|
686
|
+
"""
|
687
|
+
params = {
|
688
|
+
'search': search,
|
689
|
+
'skip': skip,
|
690
|
+
'limit': limit
|
691
|
+
}
|
692
|
+
return super()._get_shared_users(self.endpoint, params)
|
693
|
+
|
694
|
+
|
695
|
+
def seed_cache(self, from_zoom: int = None, to_zoom: int = None, extent: List[int] = None, workers: int = 1) -> List['Task']:
|
696
|
+
"""
|
697
|
+
Seed the cache of the raster.
|
698
|
+
|
699
|
+
Args:
|
700
|
+
from_zoom (int, optional): The from zoom of the raster.
|
701
|
+
to_zoom (int, optional): The to zoom of the raster.
|
702
|
+
extent (List[int], optional): The extent of the raster.
|
703
|
+
workers (int, optional): The number of workers to use. default is 1.
|
704
|
+
|
705
|
+
Returns:
|
706
|
+
Task: The task of the seed cache.
|
707
|
+
|
708
|
+
Example:
|
709
|
+
>>> from geobox import GeoboxClient
|
710
|
+
>>> from geobox.raster import Raster
|
711
|
+
>>> client = GeoboxClient()
|
712
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
713
|
+
>>> task = raster.seed_cache(from_zoom=0, to_zoom=22, extent=[0, 0, 100, 100], workers=1)
|
714
|
+
"""
|
715
|
+
data = {
|
716
|
+
'from_zoom': from_zoom,
|
717
|
+
'to_zoom': to_zoom,
|
718
|
+
'extent': extent,
|
719
|
+
'workers': workers
|
720
|
+
}
|
721
|
+
return super()._seed_cache(self.endpoint, data)
|
722
|
+
|
723
|
+
|
724
|
+
def clear_cache(self) -> None:
|
725
|
+
"""
|
726
|
+
Clear the cache of the raster.
|
727
|
+
|
728
|
+
Returns:
|
729
|
+
None
|
730
|
+
|
731
|
+
Example:
|
732
|
+
>>> from geobox import GeoboxClient
|
733
|
+
>>> from geobox.raster import Raster
|
734
|
+
>>> client = GeoboxClient()
|
735
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
736
|
+
>>> raster.clear_cache()
|
737
|
+
"""
|
738
|
+
super()._clear_cache(self.endpoint)
|
739
|
+
|
740
|
+
|
741
|
+
@property
|
742
|
+
def cache_size(self) -> int:
|
743
|
+
"""
|
744
|
+
Get the size of the cache of the raster.
|
745
|
+
|
746
|
+
Returns:
|
747
|
+
int: The size of the cache of the raster.
|
748
|
+
|
749
|
+
Example:
|
750
|
+
>>> from geobox import GeoboxClient
|
751
|
+
>>> from geobox.raster import Raster
|
752
|
+
>>> client = GeoboxClient()
|
753
|
+
>>> raster = Raster.get_raster(client, uuid="12345678-1234-5678-1234-567812345678")
|
754
|
+
>>> raster.cache_size
|
755
|
+
"""
|
756
|
+
return super()._cache_size(self.endpoint)
|