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