geobox 1.4.1__py3-none-any.whl → 2.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.
Files changed (66) hide show
  1. geobox/__init__.py +2 -2
  2. geobox/aio/__init__.py +63 -0
  3. geobox/aio/api.py +2640 -0
  4. geobox/aio/apikey.py +263 -0
  5. geobox/aio/attachment.py +339 -0
  6. geobox/aio/base.py +262 -0
  7. geobox/aio/basemap.py +196 -0
  8. geobox/aio/dashboard.py +342 -0
  9. geobox/aio/feature.py +527 -0
  10. geobox/aio/field.py +321 -0
  11. geobox/aio/file.py +522 -0
  12. geobox/aio/layout.py +341 -0
  13. geobox/aio/log.py +145 -0
  14. geobox/aio/map.py +1034 -0
  15. geobox/aio/model3d.py +415 -0
  16. geobox/aio/mosaic.py +696 -0
  17. geobox/aio/plan.py +315 -0
  18. geobox/aio/query.py +702 -0
  19. geobox/aio/raster.py +869 -0
  20. geobox/aio/route.py +63 -0
  21. geobox/aio/scene.py +342 -0
  22. geobox/aio/settings.py +194 -0
  23. geobox/aio/task.py +402 -0
  24. geobox/aio/tile3d.py +339 -0
  25. geobox/aio/tileset.py +672 -0
  26. geobox/aio/usage.py +243 -0
  27. geobox/aio/user.py +507 -0
  28. geobox/aio/vectorlayer.py +1363 -0
  29. geobox/aio/version.py +273 -0
  30. geobox/aio/view.py +983 -0
  31. geobox/aio/workflow.py +341 -0
  32. geobox/api.py +14 -13
  33. geobox/apikey.py +28 -1
  34. geobox/attachment.py +27 -1
  35. geobox/base.py +4 -4
  36. geobox/basemap.py +30 -1
  37. geobox/dashboard.py +27 -0
  38. geobox/feature.py +33 -13
  39. geobox/field.py +33 -21
  40. geobox/file.py +40 -46
  41. geobox/layout.py +28 -1
  42. geobox/log.py +31 -7
  43. geobox/map.py +56 -5
  44. geobox/model3d.py +98 -19
  45. geobox/mosaic.py +47 -7
  46. geobox/plan.py +29 -3
  47. geobox/query.py +41 -5
  48. geobox/raster.py +45 -13
  49. geobox/scene.py +26 -0
  50. geobox/settings.py +30 -1
  51. geobox/task.py +28 -6
  52. geobox/tile3d.py +27 -1
  53. geobox/tileset.py +26 -5
  54. geobox/usage.py +32 -1
  55. geobox/user.py +62 -6
  56. geobox/utils.py +34 -0
  57. geobox/vectorlayer.py +59 -4
  58. geobox/version.py +25 -1
  59. geobox/view.py +54 -15
  60. geobox/workflow.py +27 -1
  61. {geobox-1.4.1.dist-info → geobox-2.0.0.dist-info}/METADATA +4 -1
  62. geobox-2.0.0.dist-info/RECORD +68 -0
  63. geobox-1.4.1.dist-info/RECORD +0 -38
  64. {geobox-1.4.1.dist-info → geobox-2.0.0.dist-info}/WHEEL +0 -0
  65. {geobox-1.4.1.dist-info → geobox-2.0.0.dist-info}/licenses/LICENSE +0 -0
  66. {geobox-1.4.1.dist-info → geobox-2.0.0.dist-info}/top_level.txt +0 -0
geobox/aio/query.py ADDED
@@ -0,0 +1,702 @@
1
+ from urllib.parse import urljoin
2
+ from typing import Dict, List, TYPE_CHECKING, Union
3
+
4
+ from ..utils import clean_data
5
+ from .base import AsyncBase
6
+ from .task import Task
7
+ from ..enums import QueryResultType, QueryGeometryType, QueryParamType
8
+
9
+ if TYPE_CHECKING:
10
+ from . import AsyncGeoboxClient
11
+ from .user import User
12
+ from ..api import GeoboxClient as SyncGeoboxClient
13
+ from ..query import Query as SyncQuery
14
+
15
+
16
+ class Query(AsyncBase):
17
+
18
+ BASE_ENDPOINT: str = 'queries/'
19
+
20
+ def __init__(self,
21
+ api: 'AsyncGeoboxClient',
22
+ uuid: str = None,
23
+ data: Dict = {}):
24
+ """
25
+ Constructs all the necessary attributes for the Query object.
26
+
27
+ Args:
28
+ api (AsyncGeoboxClient): The API instance.
29
+ uuid (str): The UUID of the query.
30
+ data (dict, optional): The data of the query.
31
+ """
32
+ self.result = {}
33
+ self._system_query = False
34
+ super().__init__(api, uuid=uuid, data=data)
35
+
36
+
37
+ def _check_access(self) -> None:
38
+ """
39
+ Check if the query is a system query.
40
+
41
+ Returns:
42
+ None
43
+
44
+ Raises:
45
+ PermissionError: If the query is a read-only system query.
46
+ """
47
+ if self._system_query:
48
+ raise PermissionError("Cannot modify system queries - they are read-only")
49
+
50
+
51
+ @property
52
+ def sql(self) -> str:
53
+ """
54
+ Get the SQL of the query.
55
+
56
+ Returns:
57
+ str: The SQL of the query.
58
+
59
+ Example:
60
+ >>> from geobox.aio import AsyncGeoboxClient
61
+ >>> from geobox.aio.query import Query
62
+ >>> async with AsyncGeoboxClient() as client:
63
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
64
+ >>> query.sql
65
+ 'SELECT * FROM some_layer'
66
+ """
67
+ return self.data['sql']
68
+
69
+
70
+ @sql.setter
71
+ def sql(self, value: str) -> None:
72
+ """
73
+ Set the SQL of the query.
74
+
75
+ Args:
76
+ value (str): The SQL of the query.
77
+
78
+ Returns:
79
+ None
80
+
81
+ Example:
82
+ >>> from geobox.aio import AsyncGeoboxClient
83
+ >>> from geobox.aio.query import Query
84
+ >>> async with AsyncGeoboxClient() as client:
85
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
86
+ >>> query.sql = 'SELECT * FROM some_layer'
87
+ >>> await query.save()
88
+ """
89
+ self.data['sql'] = value
90
+
91
+
92
+ @property
93
+ def params(self) -> List[Dict]:
94
+ """
95
+ Get the parameters of the query.
96
+
97
+ Returns:
98
+ List[Dict]: The parameters of the query.
99
+
100
+ Example:
101
+ >>> from geobox.aio import AsyncGeoboxClient
102
+ >>> from geobox.aio.query import Query
103
+ >>> async with AsyncGeoboxClient() as client:
104
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
105
+ >>> query.params
106
+ [{'name': 'layer', 'value': '12345678-1234-5678-1234-567812345678', 'type': 'Layer'}]
107
+ """
108
+ if not isinstance(self.data.get('params'), list):
109
+ self.data['params'] = []
110
+
111
+ return self.data['params']
112
+
113
+
114
+ @params.setter
115
+ def params(self, value: Dict) -> None:
116
+ """
117
+ Set the parameters of the query.
118
+
119
+ Args:
120
+ value (Dict): The parameters of the query.
121
+
122
+ Returns:
123
+ None
124
+
125
+ Example:
126
+ >>> from geobox.aio import AsyncGeoboxClient
127
+ >>> from geobox.aio.query import Query
128
+ >>> async with AsyncGeoboxClient() as client:
129
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
130
+ >>> query.params = [{'name': 'layer', 'value': '12345678-1234-5678-1234-567812345678', 'type': 'Layer'}]
131
+ >>> await query.save()
132
+ """
133
+ if not isinstance(self.data.get('params'), list):
134
+ self.data['params'] = []
135
+
136
+ self.data['params'] = value
137
+
138
+
139
+ @classmethod
140
+ async def get_queries(cls, api: 'AsyncGeoboxClient', **kwargs) -> Union[List['Query'], int]:
141
+ """
142
+ [async] Get Queries
143
+
144
+ Args:
145
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
146
+
147
+ Keyword Args:
148
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
149
+ 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.
150
+ search_fields (str): comma separated list of fields for searching
151
+ 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.
152
+ return_count (bool): Whether to return total count. default is False.
153
+ skip (int): Number of queries to skip. default is 0.
154
+ limit(int): Maximum number of queries to return. default is 10.
155
+ user_id (int): Specific user. privileges required.
156
+ shared (bool): Whether to return shared queries. default is False.
157
+
158
+ Returns:
159
+ List[Query] | int: list of queries or the number of queries.
160
+
161
+ Example:
162
+ >>> from geobox.aio import AsyncGeoboxClient
163
+ >>> from geobox.aio.query import Query
164
+ >>> async with AsyncGeoboxClient() as client:
165
+ >>> queries = await Query.get_queries(client)
166
+ or
167
+ >>> queries = await client.get_queries()
168
+ """
169
+ params = {
170
+ 'f': 'json',
171
+ 'q': kwargs.get('q'),
172
+ 'search': kwargs.get('search'),
173
+ 'search_field': kwargs.get('search_field'),
174
+ 'order_by': kwargs.get('order_by'),
175
+ 'return_count': kwargs.get('return_count', False),
176
+ 'skip': kwargs.get('skip', 0),
177
+ 'limit': kwargs.get('limit', 10),
178
+ 'user_id': kwargs.get('user_id'),
179
+ 'shared': kwargs.get('shared', False)
180
+ }
181
+ return await super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Query(api, item['uuid'], item))
182
+
183
+
184
+ @classmethod
185
+ async def create_query(cls, api: 'AsyncGeoboxClient', name: str, display_name: str = None, description:str = None, sql: str = None, params: List = None) -> 'Query':
186
+ """
187
+ [async] Creates a new query.
188
+
189
+ Args:
190
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
191
+ name (str): The name of the query.
192
+ display_name (str, optional): The display name of the query.
193
+ description (str, optional): The description of the query.
194
+ sql (str, optional): The SQL statement for the query.
195
+ params (list, optional): The parameters for the SQL statement.
196
+
197
+ Returns:
198
+ Query: The created query instance.
199
+
200
+ Example:
201
+ >>> from geobox.aio import AsyncGeoboxClient
202
+ >>> from geobox.aio.query import Query
203
+ >>> async with AsyncGeoboxClient() as client:
204
+ >>> query = await Query.create_query(client, name='query_name', display_name='Query Name', sql='SELECT * FROM some_layer')
205
+ or
206
+ >>> query = await client.create_query(name='query_name', display_name='Query Name', sql='SELECT * FROM some_layer')
207
+ """
208
+ data = {
209
+ "name": name,
210
+ "display_name": display_name,
211
+ "description": description,
212
+ "sql": sql,
213
+ "params": params
214
+ }
215
+ return await super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Query(api, item['uuid'], item))
216
+
217
+
218
+ @classmethod
219
+ async def get_query(cls, api: 'AsyncGeoboxClient', uuid: str, user_id: int = None) -> 'Query':
220
+ """
221
+ [async] Retrieves a query by its UUID.
222
+
223
+ Args:
224
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
225
+ uuid (str): The UUID of the query.
226
+ user_id (int, optional): specific user ID. privileges required.
227
+
228
+ Returns:
229
+ Query: The retrieved query instance.
230
+
231
+ Example:
232
+ >>> from geobox.aio import AsyncGeoboxClient
233
+ >>> from geobox.aio.query import Query
234
+ >>> async with AsyncGeoboxClient() as client:
235
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
236
+ or
237
+ >>> query = await client.get_query(uuid="12345678-1234-5678-1234-567812345678")
238
+ """
239
+ params = {
240
+ 'f': 'json',
241
+ 'user_id': user_id
242
+ }
243
+ return await super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Query(api, item['uuid'], item))
244
+
245
+
246
+ @classmethod
247
+ async def get_query_by_name(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> Union['Query', None]:
248
+ """
249
+ [async] Get a query by name
250
+
251
+ Args:
252
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
253
+ name (str): the name of the query to get
254
+ user_id (int, optional): specific user. privileges required.
255
+
256
+ Returns:
257
+ Query | None: returns the query if a query matches the given name, else None
258
+
259
+ Example:
260
+ >>> from geobox.aio import AsyncGeoboxClient
261
+ >>> from geobox.aio.query import Query
262
+ >>> async with AsyncGeoboxClient() as client:
263
+ >>> query = await Query.get_query_by_name(client, name='test')
264
+ or
265
+ >>> query = await client.get_query_by_name(name='test')
266
+ """
267
+ queries = await cls.get_queries(api, q=f"name = '{name}'", user_id=user_id)
268
+ if queries and queries[0].name == name:
269
+ return queries[0]
270
+ else:
271
+ return None
272
+
273
+
274
+ @classmethod
275
+ async def get_system_queries(cls, api: 'AsyncGeoboxClient', **kwargs) -> List['Query']:
276
+ """
277
+ [async] Returns the system queries as a list of Query objects.
278
+
279
+ Args:
280
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
281
+
282
+ Keyword Args:
283
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'".
284
+ 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.
285
+ search_fields (str): comma separated list of fields for searching.
286
+ 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.
287
+ return_count (bool): whether to return the total count of queries. default is False.
288
+ skip (int): number of queries to skip. minimum is 0. default is 0.
289
+ limit (int): number of queries to return. minimum is 1. default is 100.
290
+ user_id (int): specific user. privileges required.
291
+ shared (bool): whether to return shared queries. default is False.
292
+
293
+ Returns:
294
+ List[Query]: list of system queries.
295
+
296
+ Example:
297
+ >>> from geobox.aio import AsyncGeoboxClient
298
+ >>> from geobox.aio.query import Query
299
+ >>> async with AsyncGeoboxClient() as client:
300
+ >>> queries = await Query.get_system_queries(client)
301
+ or
302
+ >>> queries = await client.get_system_queries()
303
+ """
304
+ params = {
305
+ 'f': 'json',
306
+ 'q': kwargs.get('q'),
307
+ 'search': kwargs.get('search'),
308
+ 'search_fields': kwargs.get('search_fields'),
309
+ 'order_by': kwargs.get('order_by'),
310
+ 'return_count': kwargs.get('return_count', False),
311
+ 'skip': kwargs.get('skip', 0),
312
+ 'limit': kwargs.get('limit', 100),
313
+ 'user_id': kwargs.get('user_id'),
314
+ 'shared': kwargs.get('shared', False)
315
+ }
316
+ endpoint = urljoin(cls.BASE_ENDPOINT, 'systemQueries/')
317
+ def factory_func(api, item):
318
+ query = Query(api, item['uuid'], item)
319
+ query._system_query = True
320
+ return query
321
+
322
+ return await super()._get_list(api, endpoint, params, factory_func=factory_func)
323
+
324
+
325
+ def add_param(self, name: str, value: str, type: 'QueryParamType', default_value: str = None, Domain: Dict = None) -> None:
326
+ """
327
+ Add a parameter to the query parameters.
328
+
329
+ Args:
330
+ name (str): The name of the parameter.
331
+ value (str): The value of the parameter.
332
+ type (str): The type of the parameter (default: 'Layer').
333
+ default_value (str, optional): The default value for the parameter.
334
+ Domain (Dict, optional): Domain information for the parameter.
335
+
336
+ Returns:
337
+ None
338
+
339
+ Raises:
340
+ PermissionError: If the query is a read-only system query.
341
+
342
+ Example:
343
+ >>> from geobox.aio import AsyncGeoboxClient
344
+ >>> from geobox.aio.query import Query
345
+ >>> async with AsyncGeoboxClient() as client:
346
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
347
+ or
348
+ >>> query = await client.get_query(uuid="12345678-1234-5678-1234-567812345678")
349
+ >>> query.add_param(name='param_name', value='param_value', type=QueryParamType.LAYER)
350
+ >>> await query.save()
351
+ """
352
+ self._check_access()
353
+
354
+ self.params.append({
355
+ 'name': name,
356
+ 'value': value,
357
+ 'type': type.value,
358
+ 'default_value': default_value,
359
+ 'Domain': Domain
360
+ })
361
+
362
+
363
+ def remove_param(self, name: str) -> None:
364
+ """
365
+ Remove a parameter from the query parameters by name.
366
+
367
+ Args:
368
+ name (str): The name of the parameter to remove.
369
+
370
+ Returns:
371
+ None
372
+
373
+ Raises:
374
+ ValueError: If the parameter is not found in query parameters.
375
+ PermissionError: If the query is a read-only system query.
376
+
377
+ Example:
378
+ >>> from geobox.aio import AsyncGeoboxClient
379
+ >>> from geobox.aio.query import Query
380
+ >>> async with AsyncGeoboxClient() as client:
381
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
382
+ or
383
+ >>> query = await client.get_query(uuid="12345678-1234-5678-1234-567812345678")
384
+ >>> query.remove_param(name='param_name')
385
+ >>> await quary.save()
386
+ """
387
+ self._check_access()
388
+
389
+ for i, param in enumerate(self.params):
390
+ if param.get('name') == name:
391
+ self.params.pop(i)
392
+ return
393
+
394
+ raise ValueError(f"Parameter with name '{name}' not found in query parameters")
395
+
396
+
397
+ async def execute(self,
398
+ f: str = "json",
399
+ result_type: QueryResultType = QueryResultType.both,
400
+ return_count: bool = None,
401
+ out_srid: int = None,
402
+ quant_factor: int = 1000000,
403
+ bbox_srid: int = None,
404
+ skip: int = None,
405
+ limit: int = None,
406
+ skip_geometry: bool = False) -> Union[Dict, int]:
407
+ """
408
+ [async] Executes a query with the given SQL statement and parameters.
409
+
410
+ Args:
411
+ f (str): the output format of the executed query. options are: json, topojson. default is json.
412
+ result_type (QueryResultType, optional): The type of result to return (default is "both").
413
+ return_count (bool, optional): Whether to return the count of results.
414
+ out_srid (int, optional): The output spatial reference ID.
415
+ quant_factor (int, optional): The quantization factor (default is 1000000).
416
+ bbox_srid (int, optional): The bounding box spatial reference ID.
417
+ skip (int, optional): The number of results to skip.
418
+ limit (int, optional): The maximum number of results to return.
419
+ skip_geometry (bool): Whether to skip the geometry part of the features or not. default is False.
420
+
421
+ Returns:
422
+ Dict | int: The result of the query execution or the count number of the result
423
+
424
+ Example:
425
+ >>> from geobox.aio import AsyncGeoboxClient
426
+ >>> from geobox.aio.query import Query
427
+ >>> async with AsyncGeoboxClient() as client:
428
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
429
+ or
430
+ >>> query = await client.get_query(uuid="12345678-1234-5678-1234-567812345678")
431
+ >>> await query.execute(f='json')
432
+ """
433
+ self._check_access()
434
+
435
+ if not self.sql:
436
+ raise ValueError('"sql" parameter is required for this action!')
437
+ if not self.params:
438
+ raise ValueError('"params" parameter is required for this action!')
439
+
440
+ data = clean_data({
441
+ "f": f if f in ['json', 'topojson'] else None,
442
+ "sql": self.sql,
443
+ "params": self.params,
444
+ "result_type": result_type.value,
445
+ "return_count": return_count,
446
+ "out_srid": out_srid,
447
+ "quant_factor": quant_factor,
448
+ "bbox_srid": bbox_srid,
449
+ "skip": skip,
450
+ "limit": limit,
451
+ "skip_geometry": skip_geometry
452
+ })
453
+
454
+ endpoint = urljoin(self.BASE_ENDPOINT, 'exec/')
455
+ self.result = await self.api.post(endpoint, data)
456
+ return self.result
457
+
458
+
459
+ async def update(self, **kwargs) -> Dict:
460
+ """
461
+ [async] Updates the query with new data.
462
+
463
+ Keyword Args:
464
+ name (str): The new name of the query.
465
+ display_name (str): The new display name of the query.
466
+ sql (str): The new SQL statement for the query.
467
+ params (list): The new parameters for the SQL statement.
468
+
469
+ Returns:
470
+ Dict: The updated query data.
471
+
472
+ Raises:
473
+ PermissionError: If the query is a read-only system query.
474
+
475
+ Example:
476
+ >>> from geobox.aio import AsyncGeoboxClient
477
+ >>> from geobox.aio.query import Query
478
+ >>> async with AsyncGeoboxClient() as client:
479
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
480
+ or
481
+ >>> query = await client.get_query(uuid="12345678-1234-5678-1234-567812345678")
482
+ >>> await query.update(name='new_name')
483
+ """
484
+ self._check_access()
485
+
486
+ data = {
487
+ "name": kwargs.get('name'),
488
+ "display_name": kwargs.get('display_name'),
489
+ "sql": kwargs.get('sql'),
490
+ "params": kwargs.get('params')
491
+ }
492
+ await super()._update(self.endpoint, data)
493
+
494
+
495
+ async def save(self) -> None:
496
+ """
497
+ [async] Save the query. Creates a new query if query uuid is None, updates existing query otherwise.
498
+
499
+ Returns:
500
+ None
501
+
502
+ Example:
503
+ >>> from geobox.aio import AsyncGeoboxClient
504
+ >>> from geobox.aio.query import Query
505
+ >>> async with AsyncGeoboxClient() as client:
506
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
507
+ >>> await query.save()
508
+ """
509
+ self.params = [item for item in self.params if item.get('value')]
510
+
511
+ try:
512
+ if self.__getattr__('uuid'):
513
+ await self.update(name=self.data['name'], display_name=self.data['display_name'], sql=self.sql, params=self.params)
514
+ except AttributeError:
515
+ response = await self.api.post(self.BASE_ENDPOINT, self.data)
516
+ self.endpoint = urljoin(self.BASE_ENDPOINT, f'{response["uuid"]}/')
517
+ self.data.update(response)
518
+
519
+
520
+ async def delete(self) -> str:
521
+ """
522
+ [async] Deletes a query.
523
+
524
+ Returns:
525
+ str: The response from the API.
526
+
527
+ Raises:
528
+ PermissionError: If the query is a read-only system query
529
+
530
+ Example:
531
+ >>> from geobox.aio import AsyncGeoboxClient
532
+ >>> from geobox.aio.query import Query
533
+ >>> async with AsyncGeoboxClient() as client:
534
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
535
+ >>> await query.delete()
536
+ """
537
+ self._check_access()
538
+ await super().delete(self.endpoint)
539
+
540
+
541
+ async def share(self, users: List['User']) -> None:
542
+ """
543
+ [async] Shares the query with specified users.
544
+
545
+ Args:
546
+ users (List[User]): The list of user objects to share the query with.
547
+
548
+ Returns:
549
+ None
550
+
551
+ Raises:
552
+ PermissionError: If the query is a read-only system query.
553
+
554
+ Example:
555
+ >>> from geobox.aio import AsyncGeoboxClient
556
+ >>> from geobox.aio.query import Query
557
+ >>> async with AsyncGeoboxClient() as client:
558
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
559
+ >>> users = await client.search_users(search="John")
560
+ >>> await query.share(users=users)
561
+ """
562
+ self._check_access()
563
+ await super()._share(self.endpoint, users)
564
+
565
+
566
+ async def unshare(self, users: List['User']) -> None:
567
+ """
568
+ [async] Unshares the query with specified users.
569
+
570
+ Args:
571
+ users (List[User]): The list of user objects to unshare the query with.
572
+
573
+ Returns:
574
+ None
575
+
576
+ Raises:
577
+ PermissionError: If the query is a read-only system query.
578
+
579
+ Example:
580
+ >>> from geobox.aio import AsyncGeoboxClient
581
+ >>> from geobox.aio.query import Query
582
+ >>> async with AsyncGeoboxClient() as client:
583
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
584
+ >>> users = await client.search_users(search="John")
585
+ >>> await query.unshare(users=users)
586
+ """
587
+ self._check_access()
588
+ await super()._unshare(self.endpoint, users)
589
+
590
+
591
+ async def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
592
+ """
593
+ [async] Retrieves the list of users the query is shared with.
594
+
595
+ Args:
596
+ search (str, optional): the search query.
597
+ skip (int, optional): The number of users to skip.
598
+ limit (int, optional): The maximum number of users to retrieve.
599
+
600
+ Returns:
601
+ List[User]: The list of shared users.
602
+
603
+ Example:
604
+ >>> from geobox.aio import AsyncGeoboxClient
605
+ >>> from geobox.aio.query import Query
606
+ >>> async with AsyncGeoboxClient() as client:
607
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
608
+ >>> users = await client.search_users(search="John")
609
+ >>> await query.get_shared_users(search='John', skip=0, limit=10)
610
+ """
611
+ self._check_access()
612
+ params = {
613
+ 'search': search,
614
+ 'skip': skip,
615
+ 'limit': limit
616
+ }
617
+ return await super()._get_shared_users(self.endpoint, params)
618
+
619
+
620
+ @property
621
+ def thumbnail(self) -> str:
622
+ """
623
+ Retrieves the thumbnail URL for the query.
624
+
625
+ Returns:
626
+ str: The thumbnail URL.
627
+
628
+ Example:
629
+ >>> from geobox.aio import AsyncGeoboxClient
630
+ >>> from geobox.aio.query import Query
631
+ >>> async with AsyncGeoboxClient() as client:
632
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
633
+ >>> query.thumbnail
634
+ """
635
+ self._check_access()
636
+ return super().thumbnail()
637
+
638
+
639
+ async def save_as_layer(self, layer_name: str, layer_type: 'QueryGeometryType' = None) -> Task:
640
+ """
641
+ [async] Saves the query as a new layer.
642
+
643
+ Args:
644
+ layer_name (str): The name of the new layer.
645
+ layer_type (QueryGeometryType, optional): The type of the new layer.
646
+
647
+ Returns:
648
+ Task: The response task object.
649
+
650
+ Raises:
651
+ PermissionError: If the query is a read-only system query.
652
+
653
+ Example:
654
+ >>> from geobox.aio import AsyncGeoboxClient
655
+ >>> from geobox.aio.query import Query
656
+ >>> async with AsyncGeoboxClient() as client:
657
+ >>> query = await Query.get_query(client, uuid="12345678-1234-5678-1234-567812345678")
658
+ >>> await query.save_as_layer(layer_name='test')
659
+ """
660
+ self._check_access()
661
+
662
+ params = [{
663
+ "name": item.get('name'),
664
+ "type": item.get('type'),
665
+ "value": item.get('default_value') if not item.get('value') else item.get('value')
666
+ } for item in self.params]
667
+
668
+ data = clean_data({
669
+ "sql": self.sql,
670
+ "params": params,
671
+ "layer_name": layer_name,
672
+ "layer_type": layer_type.value if layer_type else None
673
+ })
674
+
675
+ endpoint = urljoin(self.BASE_ENDPOINT, 'saveAsLayer/')
676
+ response = await self.api.post(endpoint, data)
677
+ task = await Task.get_task(self.api, response.get('task_id'))
678
+ return task
679
+
680
+
681
+ def to_sync(self, sync_client: 'SyncGeoboxClient') -> 'SyncQuery':
682
+ """
683
+ Switch to sync version of the query instance to have access to the sync methods
684
+
685
+ Args:
686
+ sync_client (SyncGeoboxClient): The sync version of the GeoboxClient instance for making requests.
687
+
688
+ Returns:
689
+ geobox.query.Query: the sync instance of the query.
690
+
691
+ Example:
692
+ >>> from geobox import Geoboxclient
693
+ >>> from geobox.aio import AsyncGeoboxClient
694
+ >>> from geobox.aio.query import Query
695
+ >>> client = GeoboxClient()
696
+ >>> async with AsyncGeoboxClient() as async_client:
697
+ >>> query = await Query.get_query(async_client, uuid="12345678-1234-5678-1234-567812345678")
698
+ >>> sync_query = query.to_sync(client)
699
+ """
700
+ from ..query import Query as SyncQuery
701
+
702
+ return SyncQuery(api=sync_client, uuid=self.uuid, data=self.data)