geobox 2.1.0__py3-none-any.whl → 2.2.1__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 (70) hide show
  1. geobox/__init__.py +61 -63
  2. geobox/aio/__init__.py +61 -63
  3. geobox/aio/api.py +491 -574
  4. geobox/aio/apikey.py +263 -263
  5. geobox/aio/attachment.py +341 -339
  6. geobox/aio/base.py +261 -262
  7. geobox/aio/basemap.py +196 -196
  8. geobox/aio/dashboard.py +340 -342
  9. geobox/aio/feature.py +35 -35
  10. geobox/aio/field.py +315 -321
  11. geobox/aio/file.py +72 -72
  12. geobox/aio/layout.py +340 -341
  13. geobox/aio/log.py +23 -23
  14. geobox/aio/map.py +1033 -1034
  15. geobox/aio/model3d.py +415 -415
  16. geobox/aio/mosaic.py +696 -696
  17. geobox/aio/plan.py +314 -314
  18. geobox/aio/query.py +693 -693
  19. geobox/aio/raster.py +88 -454
  20. geobox/aio/{analysis.py → raster_analysis.py} +153 -170
  21. geobox/aio/route.py +4 -4
  22. geobox/aio/scene.py +340 -342
  23. geobox/aio/settings.py +18 -18
  24. geobox/aio/task.py +404 -402
  25. geobox/aio/tile3d.py +337 -339
  26. geobox/aio/tileset.py +102 -103
  27. geobox/aio/usage.py +52 -51
  28. geobox/aio/user.py +506 -507
  29. geobox/aio/vector_tool.py +1968 -0
  30. geobox/aio/vectorlayer.py +316 -414
  31. geobox/aio/version.py +272 -273
  32. geobox/aio/view.py +1019 -983
  33. geobox/aio/workflow.py +340 -341
  34. geobox/api.py +14 -98
  35. geobox/apikey.py +262 -262
  36. geobox/attachment.py +336 -337
  37. geobox/base.py +384 -384
  38. geobox/basemap.py +194 -194
  39. geobox/dashboard.py +339 -341
  40. geobox/enums.py +31 -1
  41. geobox/feature.py +31 -10
  42. geobox/field.py +320 -320
  43. geobox/file.py +4 -4
  44. geobox/layout.py +339 -340
  45. geobox/log.py +4 -4
  46. geobox/map.py +1031 -1032
  47. geobox/model3d.py +410 -410
  48. geobox/mosaic.py +696 -696
  49. geobox/plan.py +313 -313
  50. geobox/query.py +691 -691
  51. geobox/raster.py +5 -368
  52. geobox/{analysis.py → raster_analysis.py} +108 -128
  53. geobox/scene.py +341 -342
  54. geobox/settings.py +194 -194
  55. geobox/task.py +399 -400
  56. geobox/tile3d.py +337 -338
  57. geobox/tileset.py +4 -4
  58. geobox/usage.py +3 -3
  59. geobox/user.py +503 -503
  60. geobox/vector_tool.py +1968 -0
  61. geobox/vectorlayer.py +5 -110
  62. geobox/version.py +272 -272
  63. geobox/view.py +981 -981
  64. geobox/workflow.py +338 -339
  65. {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/METADATA +15 -1
  66. geobox-2.2.1.dist-info/RECORD +72 -0
  67. geobox-2.1.0.dist-info/RECORD +0 -70
  68. {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/WHEEL +0 -0
  69. {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/licenses/LICENSE +0 -0
  70. {geobox-2.1.0.dist-info → geobox-2.2.1.dist-info}/top_level.txt +0 -0
geobox/aio/view.py CHANGED
@@ -1,983 +1,1019 @@
1
- from typing import List, Optional, Dict, List, Union, TYPE_CHECKING
2
-
3
- from .vectorlayer import VectorLayer, LayerType, FileOutputFormat
4
- from .feature import Feature
5
-
6
- if TYPE_CHECKING:
7
- from . import AsyncGeoboxClient
8
- from .field import Field
9
- from .user import User
10
- from .task import Task
11
- from .file import File
12
- from .attachment import Attachment
13
- from ..enums import InputGeomType
14
- from ..api import GeoboxClient as SyncGeoboxClient
15
- from ..view import VectorLayerView as SyncVectorLayerView
16
-
17
-
18
- class VectorLayerView(VectorLayer):
19
-
20
- BASE_ENDPOINT = 'vectorLayerViews/'
21
-
22
- def __init__(self,
23
- api: 'AsyncGeoboxClient',
24
- uuid: str,
25
- layer_type: 'LayerType',
26
- data: Optional[Dict] = {}) -> None:
27
- """
28
- Initialize an async VectorLayerView instance.
29
-
30
- Args:
31
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
32
- uuid (str): The UUID of the vector layer view.
33
- layer_type (LayerType): The type of the vector layer view.
34
- data (Dict, optional): The data of the vector layer view.
35
- """
36
- super().__init__(api, uuid, layer_type, data)
37
-
38
-
39
- def __repr__(self) -> str:
40
- """
41
- Return a string representation of the VectorLayerView instance.
42
-
43
- Returns:
44
- str: A string representation of the VectorLayerView instance.
45
- """
46
- return f"VectorLayerView(uuid={self.uuid}, name={self.name}, layer_type={self.layer_type})"
47
-
48
-
49
- @property
50
- def vector_layer(self) -> 'VectorLayer':
51
- """
52
- Get the vector layer.
53
-
54
- Returns:
55
- VectorLayer: The vector layer.
56
-
57
- Example:
58
- >>> from geobox.aio import AsyncGeoboxClient
59
- >>> from geobox.aio.view import VectorLayerView
60
- >>> async with AsyncGeoboxClient() as client:
61
- >>> view = await VectorLayerView.get_view(client, uuid='e21e085a-8d30-407d-a740-ca9be9122c42')
62
- >>> view.vector_layer
63
- """
64
- return VectorLayer(self.api, self.data['vector_layer']['uuid'], LayerType(self.data['vector_layer']['layer_type']), self.data['vector_layer'])
65
-
66
-
67
- @classmethod
68
- async def get_views(cls, api: 'AsyncGeoboxClient', **kwargs) -> Union[List['VectorLayerView'], int]:
69
- """
70
- [async] Get vector layer views.
71
-
72
- Args:
73
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
74
-
75
- Keyword Args:
76
- layer_id(int): The id of the source vector layer.
77
- include_settings(bool): Whether to include the settings of the layer. default is False.
78
- q(str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
79
- 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.
80
- search_fields(str): Comma separated list of fields for searching.
81
- 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.
82
- return_count(bool): Whether to return the count of the layer views. default is False.
83
- skip(int): The number of layer views to skip. minimum is 0.
84
- limit(int): The maximum number of layer views to return. minimum is 1. default is 10.
85
- user_id(int): Specific user. privileges required.
86
- shared(bool): Whether to return shared views. default is False.
87
-
88
- Returns:
89
- list[VectorLayerView] | int: A list of VectorLayerView instances or the layer views count if return_count is True.
90
-
91
- Example:
92
- >>> from geobox.aio import AsyncGeoboxClient
93
- >>> from geobox.aio.view import VectorLayerView
94
- >>> async with AsyncGeoboxClient() as client:
95
- >>> views = await VectorLayerView.get_views(client,
96
- ... layer_id=1,
97
- ... include_settings=True,
98
- ... search="test",
99
- ... search_fields="name",
100
- ... order_by="name A",
101
- ... return_count=False,
102
- ... skip=0,
103
- ... limit=10,
104
- ... shared=True)
105
- or
106
- >>> views = await client.get_views(layer_id=1,
107
- ... include_settings=True,
108
- ... search="test",
109
- ... search_fields="name",
110
- ... order_by="name A",
111
- ... return_count=False,
112
- ... skip=0,
113
- ... limit=10,
114
- ... shared=True)
115
- """
116
- params = {
117
- 'f': 'json',
118
- 'include_settings': kwargs.get('include_settings', False),
119
- 'temporary': kwargs.get('temporary', False),
120
- 'q': kwargs.get('q', None),
121
- 'search': kwargs.get('search', None),
122
- 'search_fields': kwargs.get('search_fields', None),
123
- 'order_by': kwargs.get('order_by', None),
124
- 'return_count': kwargs.get('return_count', False),
125
- 'skip': kwargs.get('skip', 0),
126
- 'limit': kwargs.get('limit', 10),
127
- 'user_id': kwargs.get('user_id', None),
128
- 'shared': kwargs.get('shared', False)
129
- }
130
- return await super()._get_list(api=api,
131
- endpoint=cls.BASE_ENDPOINT,
132
- params=params,
133
- factory_func=lambda api, item: VectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
134
-
135
-
136
- @classmethod
137
- async def get_views_by_ids(cls, api: 'AsyncGeoboxClient', ids: List[int], user_id: int = None, include_settings: bool = False) -> List['VectorLayerView']:
138
- """
139
- [async] Get vector layer views by their IDs.
140
-
141
- Args:
142
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
143
- ids (List[int]): list of comma separated layer ids to be returned. e.g. 1, 2, 3
144
- user_id (int, optional): specific user. privileges required.
145
- include_settings (bool, optional): Whether to include the settings of the vector layer views. default is False.
146
-
147
- Returns:
148
- List[VectorLayerView]: A list of VectorLayerView instances.
149
-
150
- Example:
151
- >>> from geobox.aio import AsyncGeoboxClient
152
- >>> from geobox.aio.view import VectorLayerView
153
- >>> async with AsyncGeoboxClient() as client:
154
- >>> views = await VectorLayerView.get_views_by_ids(client, ids=[1,2,3])
155
- or
156
- >>> views = await client.get_views_by_ids(ids=[1,2,3])
157
- """
158
- params = {
159
- 'ids': ids,
160
- 'user_id': user_id,
161
- 'include_settings': include_settings
162
- }
163
- return await super()._get_list_by_ids(api=api,
164
- endpoint=f'{cls.BASE_ENDPOINT}get-layers/',
165
- params=params,
166
- factory_func=lambda api, item: VectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
167
-
168
-
169
- @classmethod
170
- async def get_view(cls, api: 'AsyncGeoboxClient', uuid: str, user_id: int = None) -> 'VectorLayerView':
171
- """
172
- [async] Get a specific vector layer view by its UUID.
173
-
174
- Args:
175
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
176
- uuid (str): The UUID of the vector layer view.
177
- user_id (int, optional): Specific user. privileges required.
178
-
179
- Returns:
180
- VectorLayerView: A VectorLayerView instance.
181
-
182
- Example:
183
- >>> from geobox.aio import AsyncGeoboxClient
184
- >>> from geobox.aio.view import VectorLayerView
185
- >>> async with AsyncGeoboxClient() as client:
186
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
187
- or
188
- >>> view = await client.get_view(uuid="12345678-1234-5678-1234-567812345678")
189
- """
190
- params = {
191
- 'f': 'json',
192
- 'user_id': user_id
193
- }
194
- return await super()._get_detail(api=api,
195
- endpoint=cls.BASE_ENDPOINT,
196
- uuid=uuid,
197
- params=params,
198
- factory_func=lambda api, item: VectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
199
-
200
-
201
- @classmethod
202
- async def get_view_by_name(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> Union['VectorLayerView', None]:
203
- """
204
- [async] Get a view by name
205
-
206
- Args:
207
- api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
208
- name (str): the name of the view to get
209
- user_id (int, optional): specific user. privileges required.
210
-
211
- Returns:
212
- VectorLayerView | None: returns the view if a view matches the given name, else None
213
-
214
- Example:
215
- >>> from geobox.aio import AsyncGeoboxClient
216
- >>> from geobox.aio.view import VectorLayerView
217
- >>> async with AsyncGeoboxClient() as client:
218
- >>> view = await VectorLayerView.get_view_by_name(client, name='test')
219
- or
220
- >>> view = await client.get_view_by_name(name='test')
221
- """
222
- views = await cls.get_views(api, q=f"name = '{name}'", user_id=user_id)
223
- if views and views[0].name == name:
224
- return views[0]
225
- else:
226
- return None
227
-
228
-
229
- async def update(self, **kwargs) -> Dict:
230
- """
231
- [async] Update the vector layer view.
232
-
233
- Keyword Args:
234
- name (str): The name of the vector layer view.
235
- display_name (str): The display name of the vector layer view.
236
- description (str): The description of the vector layer view.
237
-
238
- Returns:
239
- Dict: The updated vector layer view.
240
-
241
- Raises:
242
- ValidationError: If the update data is invalid.
243
-
244
- Example:
245
- >>> from geobox.aio import AsyncGeoboxClient
246
- >>> from geobox.aio.view import VectorLayerView
247
- >>> async with AsyncGeoboxClient() as client:
248
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
249
- >>> await view.update(name="new_name")
250
- >>> await view.update(display_name="new_display_name")
251
- >>> await view.update(description="new_description")
252
- """
253
- return await super().update(name=kwargs.get('name'), display_name=kwargs.get('display_name'), description=kwargs.get('description'))
254
-
255
-
256
- async def delete(self) -> None:
257
- """
258
- [async] Delete the vector layer view.
259
-
260
- Returns:
261
- None
262
-
263
- Example:
264
- >>> from geobox.aio import AsyncGeoboxClient
265
- >>> from geobox.aio.view import VectorLayerView
266
- >>> async with AsyncGeoboxClient() as client:
267
- >>> view = async VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
268
- >>> async view.delete()
269
- """
270
- return await super().delete()
271
-
272
-
273
- async def share(self, users: List['User']) -> None:
274
- """
275
- [async] Shares the view with specified users.
276
-
277
- Args:
278
- users (List[User]): The list of user IDs to share the view with.
279
-
280
- Returns:
281
- None
282
-
283
- Example:
284
- >>> from geobox.aio import AsyncGeoboxClient
285
- >>> from geobox.aio.view import VectorLayerView
286
- >>> async with AsyncGeoboxClient() as client:
287
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
288
- >>> users = await client.search_users(search='John')
289
- >>> await view.share(users=users)
290
- """
291
- await super()._share(self.endpoint, users)
292
-
293
-
294
- async def unshare(self, users: List['User']) -> None:
295
- """
296
- [async] Unshares the view with specified users.
297
-
298
- Args:
299
- users (List[User]): The list of user IDs to unshare the view with.
300
-
301
- Returns:
302
- None
303
-
304
- Example:
305
- >>> from geobox.aio import AsyncGeoboxClient
306
- >>> from geobox.aio.view import VectorLayerView
307
- >>> async with AsyncGeoboxClient() as client:
308
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
309
- >>> users = await client.search_users(search='John')
310
- >>> await view.unshare(users=users)
311
- """
312
- await super()._unshare(self.endpoint, users)
313
-
314
-
315
- async def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
316
- """
317
- [async] Retrieves the list of users the view is shared with.
318
-
319
- Args:
320
- search (str, optional): The search query.
321
- skip (int, optional): The number of users to skip.
322
- limit (int, optional): The maximum number of users to retrieve.
323
-
324
- Returns:
325
- List[User]: The list of shared users.
326
-
327
- Example:
328
- >>> from geobox.aio import AsyncGeoboxClient
329
- >>> from geobox.aio.view import VectorLayerView
330
- >>> async with AsyncGeoboxClient() as client:
331
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
332
- >>> await view.get_shared_users(search='John', skip=0, limit=10)
333
- """
334
- params = {
335
- 'search': search,
336
- 'skip': skip,
337
- 'limit': limit
338
- }
339
- return await super()._get_shared_users(self.endpoint, params)
340
-
341
-
342
- async def get_fields(self) -> List['Field']:
343
- """
344
- [async] Get all fields in the vector layer view.
345
-
346
- Returns:
347
- List[Field]: A list of Field instances representing the vector layer view's fields.
348
-
349
- Raises:
350
- ApiRequestError: If the API request fails.
351
-
352
- Example:
353
- >>> from geobox.aio import AsyncGeoboxClient
354
- >>> from geobox.aio.view import VectorLayerView
355
- >>> async with AsyncGeoboxClient() as client:
356
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
357
- >>> fields = await view.get_fields()
358
- """
359
- return await super().get_fields()
360
-
361
-
362
- async def get_field(self, field_id: int) -> 'Field':
363
- """
364
- [async] Get a specific field by its ID or name.
365
-
366
- Args:
367
- field_id (int): The ID of the field to retrieve.
368
-
369
- Returns:
370
- Field: The requested field instance.
371
-
372
- Raises:
373
- NotFoundError: If the field with the specified ID is not found.
374
- ApiRequestError: If the API request fails.
375
-
376
- Example:
377
- >>> from geobox.aio import AsyncGeoboxClient
378
- >>> from geobox.aio.view import VectorLayerView
379
- >>> async with AsyncGeoboxClient() as client:
380
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
381
- >>> field = await view.get_field(id=1)
382
- """
383
- return await super().get_field(field_id)
384
-
385
-
386
- async def get_field_by_name(self, name: str) -> 'Field':
387
- """
388
- [async] Get a specific field by its name.
389
-
390
- Args:
391
- name (str, optional): The name of the field to retrieve.
392
-
393
- Returns:
394
- Field: The requested field instance.
395
-
396
- Raises:
397
- NotFoundError: If the field with the specified name is not found.
398
-
399
- Example:
400
- >>> from geobox.aio import AsyncGeoboxClient
401
- >>> from geobox.aio.view import VectorLayerView
402
- >>> async with AsyncGeoboxClient() as client:
403
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
404
- >>> field = await view.get_field_by_name(name='test')
405
- """
406
- return await super().get_field_by_name(name)
407
-
408
-
409
- async def calculate_field(self, target_field: str, expression: str, q: str = None, bbox: List[float] = None,
410
- bbox_srid: int = None, feature_ids: List = None, run_async: bool = True,
411
- user_id: int = None) -> Union['Task', Dict]:
412
- """
413
- [async] Calculate values for a field based on an expression.
414
-
415
- Args:
416
- target_field (str): The field to calculate values for.
417
- expression (str): The expression to use for calculation.
418
- q (Optional[str]): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
419
- bbox (Optional[List[float]]): Bounding box to filter features.
420
- bbox_srid (Optional[int]): Spatial reference ID for the bounding box.
421
- feature_ids (Optional[List[int]]): List of specific feature IDs to include.
422
- run_async (Optional[bool]): Whether to run the calculation asynchronously.
423
- user_id (Optional[int]): ID of the user running the calculation.
424
-
425
- Returns:
426
- Task | Dict: The task instance of the calculation operation or the api response if the run_async=False.
427
-
428
- Raises:
429
- ValidationError: If the calculation parameters are invalid.
430
- ApiRequestError: If the API request fails.
431
-
432
- Example:
433
- >>> from geobox.aio import AsyncGeoboxClient
434
- >>> from geobox.aio.view import VectorLayerView
435
- >>> async with AsyncGeoboxClient() as client:
436
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
437
- >>> task = await view.calculate_field(target_field="target_field",
438
- ... expression="expression",
439
- ... q="name like 'my_layer'",
440
- ... bbox=[10, 20, 30, 40],
441
- ... bbox_srid=3857,
442
- ... feature_ids=[1, 2, 3],
443
- ... run_async=True)
444
- """
445
- return await super().calculate_field(target_field, expression, q, bbox, bbox_srid, feature_ids, run_async, user_id)
446
-
447
-
448
- async def get_features(self, **kwargs) -> Union[List['Feature'], int]:
449
- """
450
- [async] Get features from the layer with optional filtering and pagination.
451
-
452
- Keyword Args:
453
- quant_factor (int): Quantization factor. This parameter is only used by topojson encoder and is ignored for other formats. Higher quantizaion value means higher geometry precision. default is 1000000.
454
- skip (int): Number of features to skip. default is 0.
455
- limit (int): Maximum number of features to return. default is 100.
456
- user_id (int): Specific user. privileges required.
457
- 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.
458
- search_fields (str): comma separated list of fields for searching.
459
- skip_geometry (bool): Whether to exclude geometry data. default is False.
460
- return_count (bool): Whether to return total count. default is False.
461
- feature_ids (List[int]): comma separated list of feature ids which should be filtered.
462
- select_fields (str): comma separated field names which should be included to the result. default is "[ALL]".
463
- skip_fields (str): comma separated field names which should be excluded from the result.
464
- out_srid (int): srid (epsg code) of result features. e.g. 4326. default is 3857
465
- order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, length D. NOTE: "A" denotes ascending order and "D" denotes descending order.
466
- q (str): query filter based on OGC CQL standard. e.g. Name LIKE '%GIS%' AND INTERSECTS(geometry, 'SRID=3857;POLYGON((4901948 2885079, 7049893 2885079, 7049893 4833901, 4901948 4833901, 4901948 2885079))').
467
- bbox (str): Bounding box to filter features by. e.g. [50.275, 35.1195, 51.4459, 36.0416].
468
- bbox_srid (int): srid (epsg code) of bbox. e.g. 4326. default is 3857.
469
-
470
- Returns:
471
- List[Feature] | int: A list of Feature instances or the features count if return_count is True.
472
-
473
-
474
- Example:
475
- >>> from geobox.aio import AsyncGeoboxClient
476
- >>> from geobox.aio.view import VectorLayerView
477
- >>> async with AsyncGeoboxClient() as client:
478
- >>> layer = await VectorLayerView(api=client, name="my_layer", layer_type=LayerType.Point)
479
- >>> features = await layer.get_features(quant_factor=1000000,
480
- ... skip=0,
481
- ... limit=100,
482
- ... skip_geometry=False,
483
- ... return_count=False,
484
- ... select_fields="fclass, osm_id",
485
- ... out_srid=4326,
486
- ... bbox_srid=4326)
487
- """
488
- return await super().get_features(**kwargs)
489
-
490
-
491
- async def get_feature(self, feature_id: int, out_srid: int = Feature.BASE_SRID) -> 'Feature':
492
- """
493
- [async] Get a specific feature by its ID.
494
-
495
- Args:
496
- feature_id (int): The ID of the feature to retrieve.
497
- out_srid (int, optional): Output spatial reference ID
498
-
499
- Returns:
500
- Feature: The requested feature instance.
501
-
502
- Raises:
503
- NotFoundError: If the feature with the specified ID is not found.
504
-
505
- Example:
506
- >>> from geobox.aio import AsyncGeoboxClient
507
- >>> from geobox.aio.view import VectorLayerView
508
- >>> async with AsyncGeoboxClient() as client:
509
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
510
- >>> feature = await view.get_feature(id=1)
511
- """
512
- return await super().get_feature(feature_id, out_srid)
513
-
514
-
515
- async def create_feature(self, geojson: Dict) -> 'Feature':
516
- """
517
- [async] Create a new feature in the layer.
518
-
519
- Args:
520
- geojson (dict): The feature data including properties and geometry.
521
-
522
- Returns:
523
- Feature: The newly created feature instance.
524
-
525
- Raises:
526
- ValidationError: If the feature data is invalid.
527
-
528
- Example:
529
- >>> from geobox.aio import AsyncGeoboxClient
530
- >>> from geobox.aio.view import VectorLayerView
531
- >>> async with AsyncGeoboxClient() as client:
532
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
533
- >>> feature = await view.create_feature(geojson=geojson)
534
- """
535
- return await super().create_feature(geojson)
536
-
537
-
538
- async def delete_features(self, q: str = None, bbox: List[float] = None, bbox_srid: int = None, feature_ids: List[int] = None,
539
- run_async: bool = True, user_id: int = None) -> Union['Task', Dict]:
540
- """
541
- [async] Delete features from the layer based on specified criteria.
542
-
543
- Args:
544
- q (Optional[str]): Query to filter features to delete.
545
- bbox (Optional[List[float]]): Bounding box to filter features.
546
- bbox_srid (Optional[int]): Spatial reference ID for the bounding box.
547
- feature_ids (Optional[List[int]]): List of specific feature IDs to delete.
548
- run_async (Optional[bool]): Whether to run the deletion asynchronously.
549
- user_id (Optional[int]): ID of the user performing the deletion.
550
-
551
- Returns:
552
- Task | Dict: The task instance of the deletion operation or the api response if run_async=False.
553
-
554
- Raises:
555
- ValidationError: If the deletion parameters are invalid.
556
-
557
- Example:
558
- >>> from geobox.aio import AsyncGeoboxClient
559
- >>> from geobox.aio.view import VectorLayerView
560
- >>> async with AsyncGeoboxClient() as client:
561
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
562
- >>> await view.delete_features(q="name like 'my_layer'",
563
- ... bbox=[10, 20, 30, 40],
564
- ... bbox_srid=3857,
565
- ... feature_ids=[1, 2, 3],
566
- ... run_async=True)
567
- """
568
- return await super().delete_features(q, bbox, bbox_srid, feature_ids, run_async, user_id)
569
-
570
-
571
- async def import_features(self,
572
- file: 'File',
573
- input_geom_type: 'InputGeomType' = None,
574
- input_layer_name: str = None,
575
- input_dataset: str = None,
576
- user_id: int = None,
577
- input_srid: int = None,
578
- file_encoding: str = "utf-8",
579
- replace_domain_codes_by_values: bool = False,
580
- report_errors: bool = True) -> 'Task':
581
- """
582
- [async] Import features from a file into the layer.
583
-
584
- Args:
585
- file (File): file object to import.
586
- input_geom_type (InputGeomType, optional): Type of geometry in the input file.
587
- input_layer_name (str, optional): Name of the layer in the input file.
588
- input_dataset (str, optional): Name of the dataset in the input file.
589
- user_id (int, optional): Specific user.privileges requied.
590
- input_srid (int, optional): Spatial reference ID of the input data.
591
- file_encoding (str, optional): Character encoding of the input file.
592
- replace_domain_codes_by_values (bool, optional): Whether to replace domain codes with values.
593
- report_errors (bool, optional): Whether to report import errors.
594
-
595
- Returns:
596
- Task: The task instance of the import operation.
597
-
598
- Raises:
599
- ValidationError: If the import parameters are invalid.
600
-
601
- Example:
602
- >>> from geobox.aio import AsyncGeoboxClient
603
- >>> from geobox.aio.view import VectorLayerView
604
- >>> async with AsyncGeoboxClient() as client:
605
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
606
- >>> file = await client.get_file(uuid="12345678-1234-5678-1234-567812345678")
607
- >>> task = await view.import_features(file=file,
608
- ... input_geom_type=InputGeomType.POINT,
609
- ... input_layer="my_layer",
610
- ... input_dataset="my_dataset",
611
- ... input_srid=3857,
612
- ... file_encoding="utf-8",
613
- ... replace_domain_codes_by_values=False,
614
- ... report_errors=True)
615
- """
616
- return await super().import_features(file, input_geom_type, input_layer_name, input_dataset, user_id,
617
- input_srid, file_encoding, replace_domain_codes_by_values, report_errors)
618
-
619
-
620
- async def export_features(self, out_filename: str, out_format: 'FileOutputFormat', replace_domain_codes_by_values: bool = False,
621
- run_async: bool = True, bbox: List[float] = None, out_srid: int = None, zipped: bool = True,
622
- feature_ids: List[int] = None, bbox_srid: int = None, q: str = None, fields: List[str] = None) -> Union['Task', Dict]:
623
- """
624
- [async] Export features from the layer to a file.
625
-
626
- Args:
627
- out_filename (str): Name of the output file.
628
- out_format (FileOutputFormat): Format of the output file (e.g., 'Shapefile', 'GPKG', 'GeoJSON', 'CSV', 'KML', 'DXF').
629
- replace_domain_codes_by_values (bool, optional): Whether to replace domain codes with values.
630
- run_async (bool, optional): Whether to run the export asynchronously.
631
- bbox (List[float], optional): Bounding box to filter features.
632
- out_srid (int, optional): Spatial reference ID for the output.
633
- zipped (bool, optional): Whether to compress the output file.
634
- feature_ids (List[int], optional): List of specific feature IDs to export.
635
- bbox_srid (int, optional): Spatial reference ID for the bounding box.
636
- q (str, optional): Query to filter features.
637
- fields (List[str], optional): List of fields to include in the export.
638
-
639
- Returns:
640
- Task | Dict: The task instance of the export operation or the api response if run_async=False.
641
-
642
- Raises:
643
- ValidationError: If the export parameters are invalid.
644
- ApiRequestError: If the API request fails.
645
-
646
- Example:
647
- >>> from geobox.aio import AsyncGeoboxClient
648
- >>> from geobox.aio.view import VectorLayerView
649
- >>> async with AsyncGeoboxClient() as client:
650
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
651
- >>> task = await view.export_features(out_filename="output.shp",
652
- ... out_format="shp",
653
- ... replace_domain_codes_by_values=False,
654
- ... run_async=True,
655
- ... bbox=[10, 20, 30, 40],
656
- ... out_srid=3857,
657
- ... zipped=True,
658
- ... feature_ids=[1, 2, 3])
659
- """
660
- return await super().export_features(out_filename, out_format, replace_domain_codes_by_values, run_async,
661
- bbox, out_srid, zipped, feature_ids, bbox_srid, q, fields)
662
-
663
-
664
- def get_tile_pbf_url(self, x: int = '{x}', y: int = '{y}', z: int = '{z}') -> str:
665
- """
666
- Get a vector tile pbf url for the view.
667
-
668
- Args:
669
- x (int): X coordinate of the tile.
670
- y (int): Y coordinate of the tile.
671
- z (int): Zoom level of the tile.
672
-
673
- Returns:
674
- str: the vector tile url.
675
-
676
- Example:
677
- >>> from geobox.aio import AsyncGeoboxClient
678
- >>> from geobox.aio.view import VectorLayerView
679
- >>> async with AsyncGeoboxClient() as client:
680
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
681
- >>> tile = view.get_tile(x=10, y=20, z=1)
682
- """
683
- return super().get_tile_pbf_url(x, y, z)
684
-
685
-
686
- async def get_tile_json(self) -> Dict:
687
- """
688
- [async] Get the vector tile JSON configuration for the layer.
689
-
690
- Returns:
691
- Dict: The vector tile JSON configuration.
692
-
693
- Example:
694
- >>> from geobox.aio import AsyncGeoboxClient
695
- >>> from geobox.aio.view import VectorLayerView
696
- >>> async with AsyncGeoboxClient() as client:
697
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
698
- >>> tile_json = await view.get_tile_json()
699
- """
700
- return await super().get_tile_json()
701
-
702
-
703
- @property
704
- async def settings(self) -> Dict:
705
- """
706
- [async] Get the layer's settings.
707
-
708
- Returns:
709
- Dict: The layer settings.
710
-
711
- Example:
712
- >>> from geobox.aio import AsyncGeoboxClient
713
- >>> from geobox.aio.view import VectorLayerView
714
- >>> async with AsyncGeoboxClient() as client:
715
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
716
- >>> setting = await view.settings
717
- """
718
- return await super().settings
719
-
720
-
721
- async def update_settings(self, settings: Dict) -> Dict:
722
- """
723
- [async] Update the settings
724
-
725
- settings (Dict): settings dictionary
726
-
727
- Returns:
728
- Dict: updated settings
729
-
730
- Example:
731
- >>> from geobox.aio import AsyncGeoboxClient
732
- >>> async with AsyncGeoboxClient() as client:
733
- >>> view1 = await client.get_view(uuid="12345678-1234-5678-1234-567812345678")
734
- >>> view2 = await client.get_view(uuid="12345678-1234-5678-1234-567812345678")
735
- >>> await view1.update_settings(view2.settings)
736
- """
737
- return await super().update_settings(settings)
738
-
739
-
740
- async def set_settings(self, **kwargs) -> Dict:
741
- """
742
- [async] Set the settings of the Vector Layer.
743
-
744
- Keyword Args:
745
- title_field (str): The field to use as the title.
746
- domain_display_type (str): The type of domain display.
747
- allow_export (bool): Whether to allow export.
748
- editable (bool): Whether to allow editing.
749
- edit_geometry (bool): Whether to allow editing the geometry.
750
- editable_attributes (str): The attributes to allow editing.
751
- allow_insert (bool): Whether to allow inserting.
752
- allow_delete (bool): Whether to allow deleting.
753
- min_zoom (int): The minimum zoom level.
754
- max_zoom (int): The maximum zoom level.
755
- max_features (int): The maximum number of features.
756
- filter_features (bool): Whether to filter features.
757
- fields (List[str]): The fields to include in the layer.
758
- use_cache (bool): Whether to use caching.
759
- cache_until_zoom (int): The zoom level to cache until.
760
-
761
- Returns:
762
- Dict: The updated settings.
763
-
764
- Raises:
765
- ValidationError: If the settings data is invalid.
766
-
767
- Example:
768
- >>> from geobox.aio import AsyncGeoboxClient
769
- >>> from geobox.aio.view import VectorLayerView
770
- >>> async with AsyncGeoboxClient() as client:
771
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
772
- >>> await view.set_setting(title_field="name",
773
- ... domain_display_type="Value",
774
- ... allow_export=True,
775
- ... editable=True,
776
- ... edit_geometry=True,
777
- ... editable_attributes="[ALL]",
778
- ... allow_insert=True,
779
- ... allow_delete=True,
780
- ... min_zoom=0,
781
- ... max_zoom=24,
782
- ... max_features=65536,
783
- ... filter_features=True,
784
- ... fields=["id"],
785
- ... use_cache=True,
786
- ... cache_until_zoom=17)
787
- """
788
- return await super().set_settings(**kwargs)
789
-
790
-
791
- async def seed_cache(self, from_zoom: int = None, to_zoom: int = None, ignore_cache: bool = False, workers: int = 1, user_id: int = None) -> List['Task']:
792
- """
793
- [async] Seed the cache for the view.
794
-
795
- Args:
796
- from_zoom (int, optional): The zoom level to start caching from.
797
- to_zoom (int, optional): The zoom level to stop caching at.
798
- ignore_cache (bool, optional): Whether to ignore the cache. default is False.
799
- workers (int, optional): The number of workers to use. default is 1.
800
- user_id (int, optional): specified user. privileges required.
801
-
802
- Returns:
803
- List[Task]: The task instance of the cache seeding operation.
804
-
805
- Example:
806
- >>> from geobox.aio import AsyncGeoboxClient
807
- >>> from geobox.aio.view import VectorLayerView
808
- >>> async with AsyncGeoboxClient() as client:
809
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
810
- >>> task = await view.cache_seed(from_zoom=0, to_zoom=10, ignore_cache=False, workers=1)
811
- """
812
- return await super().seed_cache(from_zoom, to_zoom, ignore_cache, workers, user_id)
813
-
814
-
815
- async def clear_cache(self) -> None:
816
- """
817
- [async] Clear the view's cache.
818
-
819
- Returns:
820
- None
821
-
822
- Example:
823
- >>> from geobox.aio import AsyncGeoboxClient
824
- >>> from geobox.aio.view import VectorLayerView
825
- >>> async with AsyncGeoboxClient() as client:
826
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
827
- >>> await view.clear_cache()
828
- """
829
- return await super().clear_cache()
830
-
831
-
832
- @property
833
- async def cache_size(self) -> int:
834
- """
835
- [async] Get the size of the view's cache.
836
-
837
- Returns:
838
- int: The size of the view's cache.
839
-
840
- Example:
841
- >>> from geobox.aio import AsyncGeoboxClient
842
- >>> from geobox.aio.view import VectorLayerView
843
- >>> async with AsyncGeoboxClient() as client:
844
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
845
- >>> await view.cache_size
846
- """
847
- return await super().cache_size
848
-
849
-
850
- async def update_stats(self) -> None:
851
- """
852
- [async] Update the view's statistics.
853
-
854
- Returns:
855
- None
856
-
857
- Example:
858
- >>> from geobox.aio import AsyncGeoboxClient
859
- >>> from geobox.aio.view import VectorLayerView
860
- >>> async with AsyncGeoboxClient() as client:
861
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
862
- >>> await view.update_stats()
863
- """
864
- return await super().update_stats()
865
-
866
-
867
- async def prune_edited_areas(self) -> None:
868
- """
869
- [async] Prune edited areas. This method eliminates edited areas when there are too many of them. Cache builder uses this edited areas for partial cache generating.
870
-
871
- Returns:
872
- None
873
-
874
- Example:
875
- >>> from geobox.aio import AsyncGeoboxClient
876
- >>> from geobox.aio.view import VectorLayerView
877
- >>> async with AsyncGeoboxClient() as client:
878
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
879
- >>> await view.prune_edited_areas()
880
- """
881
- return await super().prune_edited_areas()
882
-
883
-
884
- async def get_attachments(self, **kwargs) -> List['Attachment']:
885
- """
886
- [async] Get the resouces attachments
887
-
888
- Keyword Args:
889
- element_id (str): the id of the element with attachment.
890
- search (str): search term for keyword-based searching among all textual fields.
891
- 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.
892
- skip (int): Number of items to skip. default is 0.
893
- limit (int): Number of items to return. default is 10.
894
- return_count (bool): Whether to return total count. default is False.
895
-
896
- Returns:
897
- List[Attachment] | int: A list of attachments instances or the total number of attachments.
898
-
899
- Raises:
900
- TypeError: if the resource type is not supported
901
-
902
- Example:
903
- >>> from geobox.aio import AsyncGeoboxClient
904
- >>> from geobox.aio.view import VectorLayerView
905
- >>> async with AsyncGeoboxClient() as client:
906
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
907
- >>> await view.get_attachments()
908
- """
909
- from .attachment import Attachment
910
-
911
- return await Attachment.get_attachments(self.api, resource=self, **kwargs)
912
-
913
-
914
- async def create_attachment(self,
915
- name: str,
916
- loc_x: int,
917
- loc_y: int,
918
- file: 'File',
919
- feature: 'Feature' = None,
920
- display_name: str = None,
921
- description: str = None) -> 'Attachment':
922
- """
923
- [async] Create a new Attachment.
924
-
925
- Args:
926
- name (str): The name of the scene.
927
- loc_x (int): x parameter of the attachment location.
928
- loc_y (int): y parameter of the attachment location.
929
- file (File): the file object.
930
- feature (Feature, optional): the feature object.
931
- display_name (str, optional): The display name of the scene.
932
- description (str, optional): The description of the scene.
933
-
934
- Returns:
935
- Attachment: The newly created Attachment instance.
936
-
937
- Raises:
938
- ValidationError: If the Attachment data is invalid.
939
-
940
- Example:
941
- >>> from geobox.aio import AsyncGeoboxClient
942
- >>> from geobox.aio.view import VectorLayerView
943
- >>> async with AsyncGeoboxClient() as client:
944
- >>> view = await VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
945
- >>> files = await client.get_files()
946
- >>> file = file[0]
947
- >>> await view.create_attachment(name='test', loc_x=10, loc_y=10, file=file)
948
- """
949
- from .attachment import Attachment
950
-
951
- return await Attachment.create_attachment(self.api,
952
- name=name,
953
- loc_x=loc_x,
954
- loc_y=loc_y,
955
- resource=self,
956
- file=file,
957
- feature=feature,
958
- display_name=display_name,
959
- description=description)
960
-
961
-
962
- def to_sync(self, sync_client: 'SyncGeoboxClient') -> 'SyncVectorLayerView':
963
- """
964
- Switch to sync version of the view instance to have access to the sync methods
965
-
966
- Args:
967
- sync_client (SyncGeoboxClient): The sync version of the GeoboxClient instance for making requests.
968
-
969
- Returns:
970
- geobox.view.VectorLayerView: the sync instance of the view.
971
-
972
- Example:
973
- >>> from geobox import Geoboxclient
974
- >>> from geobox.aio import AsyncGeoboxClient
975
- >>> from geobox.aio.view import VectorLayerView
976
- >>> client = GeoboxClient()
977
- >>> async with AsyncGeoboxClient() as async_client:
978
- >>> view = await VectorLayerView.get_view(async_client, uuid="12345678-1234-5678-1234-567812345678")
979
- >>> sync_view = view.to_sync(client)
980
- """
981
- from ..view import VectorLayerView as SyncVectorLayerView
982
-
983
- return SyncVectorLayerView(api=sync_client, uuid=self.uuid, layer_type=self.layer_type, data=self.data)
1
+ from typing import List, Optional, Dict, List, Union, TYPE_CHECKING
2
+
3
+ from .vectorlayer import AsyncVectorLayer, LayerType, FileOutputFormat
4
+ from .feature import AsyncFeature
5
+
6
+ if TYPE_CHECKING:
7
+ from . import AsyncGeoboxClient
8
+ from .field import AsyncField
9
+ from .user import AsyncUser
10
+ from .task import AsyncTask
11
+ from .file import AsyncFile
12
+ from .attachment import AsyncAttachment
13
+ from ..enums import InputGeomType
14
+ from ..api import GeoboxClient
15
+ from ..view import VectorLayerView
16
+
17
+
18
+ class AsyncVectorLayerView(AsyncVectorLayer):
19
+
20
+ BASE_ENDPOINT = 'vectorLayerViews/'
21
+
22
+ def __init__(self,
23
+ api: 'AsyncGeoboxClient',
24
+ uuid: str,
25
+ layer_type: 'LayerType',
26
+ data: Optional[Dict] = {}) -> None:
27
+ """
28
+ Initialize an async VectorLayerView instance.
29
+
30
+ Args:
31
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
32
+ uuid (str): The UUID of the vector layer view.
33
+ layer_type (LayerType): The type of the vector layer view.
34
+ data (Dict, optional): The data of the vector layer view.
35
+ """
36
+ super().__init__(api, uuid, layer_type, data)
37
+
38
+
39
+ def __repr__(self) -> str:
40
+ """
41
+ Return a string representation of the AsyncVectorLayerView instance.
42
+
43
+ Returns:
44
+ str: A string representation of the AsyncVectorLayerView instance.
45
+ """
46
+ return f"AsyncVectorLayerView(uuid={self.uuid}, name={self.name}, layer_type={self.layer_type})"
47
+
48
+
49
+ @property
50
+ def vector_layer(self) -> 'AsyncVectorLayer':
51
+ """
52
+ Get the vector layer.
53
+
54
+ Returns:
55
+ VectorLayer: The vector layer.
56
+
57
+ Example:
58
+ >>> from geobox.aio import AsyncGeoboxClient
59
+ >>> from geobox.aio.view import AsyncVectorLayerView
60
+ >>> async with AsyncGeoboxClient() as client:
61
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid='e21e085a-8d30-407d-a740-ca9be9122c42')
62
+ >>> view.vector_layer
63
+ """
64
+ return AsyncVectorLayer(self.api, self.data['vector_layer']['uuid'], LayerType(self.data['vector_layer']['layer_type']), self.data['vector_layer'])
65
+
66
+
67
+ @classmethod
68
+ async def get_views(cls, api: 'AsyncGeoboxClient', **kwargs) -> Union[List['AsyncVectorLayerView'], int]:
69
+ """
70
+ [async] Get vector layer views.
71
+
72
+ Args:
73
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
74
+
75
+ Keyword Args:
76
+ layer_id(int): The id of the source vector layer.
77
+ include_settings(bool): Whether to include the settings of the layer. default is False.
78
+ q(str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
79
+ 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.
80
+ search_fields(str): Comma separated list of fields for searching.
81
+ 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.
82
+ return_count(bool): Whether to return the count of the layer views. default is False.
83
+ skip(int): The number of layer views to skip. minimum is 0.
84
+ limit(int): The maximum number of layer views to return. minimum is 1. default is 10.
85
+ user_id(int): Specific user. privileges required.
86
+ shared(bool): Whether to return shared views. default is False.
87
+
88
+ Returns:
89
+ list[AsyncVectorLayerView] | int: A list of AsyncVectorLayerView instances or the layer views count if return_count is True.
90
+
91
+ Example:
92
+ >>> from geobox.aio import AsyncGeoboxClient
93
+ >>> from geobox.aio.view import AsyncVectorLayerView
94
+ >>> async with AsyncGeoboxClient() as client:
95
+ >>> views = await AsyncVectorLayerView.get_views(client,
96
+ ... layer_id=1,
97
+ ... include_settings=True,
98
+ ... search="test",
99
+ ... search_fields="name",
100
+ ... order_by="name A",
101
+ ... return_count=False,
102
+ ... skip=0,
103
+ ... limit=10,
104
+ ... shared=True)
105
+ or
106
+ >>> views = await client.get_views(layer_id=1,
107
+ ... include_settings=True,
108
+ ... search="test",
109
+ ... search_fields="name",
110
+ ... order_by="name A",
111
+ ... return_count=False,
112
+ ... skip=0,
113
+ ... limit=10,
114
+ ... shared=True)
115
+ """
116
+ params = {
117
+ 'f': 'json',
118
+ 'include_settings': kwargs.get('include_settings', False),
119
+ 'temporary': kwargs.get('temporary', False),
120
+ 'q': kwargs.get('q', None),
121
+ 'search': kwargs.get('search', None),
122
+ 'search_fields': kwargs.get('search_fields', None),
123
+ 'order_by': kwargs.get('order_by', None),
124
+ 'return_count': kwargs.get('return_count', False),
125
+ 'skip': kwargs.get('skip', 0),
126
+ 'limit': kwargs.get('limit', 10),
127
+ 'user_id': kwargs.get('user_id', None),
128
+ 'shared': kwargs.get('shared', False)
129
+ }
130
+ return await super()._get_list(api=api,
131
+ endpoint=cls.BASE_ENDPOINT,
132
+ params=params,
133
+ factory_func=lambda api, item: AsyncVectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
134
+
135
+
136
+ @classmethod
137
+ async def get_views_by_ids(cls, api: 'AsyncGeoboxClient', ids: List[int], user_id: int = None, include_settings: bool = False) -> List['AsyncVectorLayerView']:
138
+ """
139
+ [async] Get vector layer views by their IDs.
140
+
141
+ Args:
142
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
143
+ ids (List[int]): list of comma separated layer ids to be returned. e.g. 1, 2, 3
144
+ user_id (int, optional): specific user. privileges required.
145
+ include_settings (bool, optional): Whether to include the settings of the vector layer views. default is False.
146
+
147
+ Returns:
148
+ List[AsyncVectorLayerView]: A list of AsyncVectorLayerView instances.
149
+
150
+ Example:
151
+ >>> from geobox.aio import AsyncGeoboxClient
152
+ >>> from geobox.aio.view import AsyncVectorLayerView
153
+ >>> async with AsyncGeoboxClient() as client:
154
+ >>> views = await AsyncVectorLayerView.get_views_by_ids(client, ids=[1,2,3])
155
+ or
156
+ >>> views = await client.get_views_by_ids(ids=[1,2,3])
157
+ """
158
+ params = {
159
+ 'ids': ids,
160
+ 'user_id': user_id,
161
+ 'include_settings': include_settings
162
+ }
163
+ return await super()._get_list_by_ids(api=api,
164
+ endpoint=f'{cls.BASE_ENDPOINT}get-layers/',
165
+ params=params,
166
+ factory_func=lambda api, item: AsyncVectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
167
+
168
+
169
+ @classmethod
170
+ async def get_view(cls, api: 'AsyncGeoboxClient', uuid: str, user_id: int = None) -> 'AsyncVectorLayerView':
171
+ """
172
+ [async] Get a specific vector layer view by its UUID.
173
+
174
+ Args:
175
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
176
+ uuid (str): The UUID of the vector layer view.
177
+ user_id (int, optional): Specific user. privileges required.
178
+
179
+ Returns:
180
+ AsyncVectorLayerView: A AsyncVectorLayerView instance.
181
+
182
+ Example:
183
+ >>> from geobox.aio import AsyncGeoboxClient
184
+ >>> from geobox.aio.view import AsyncVectorLayerView
185
+ >>> async with AsyncGeoboxClient() as client:
186
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
187
+ or
188
+ >>> view = await client.get_view(uuid="12345678-1234-5678-1234-567812345678")
189
+ """
190
+ params = {
191
+ 'f': 'json',
192
+ 'user_id': user_id
193
+ }
194
+ return await super()._get_detail(api=api,
195
+ endpoint=cls.BASE_ENDPOINT,
196
+ uuid=uuid,
197
+ params=params,
198
+ factory_func=lambda api, item: AsyncVectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
199
+
200
+
201
+ @classmethod
202
+ async def get_view_by_name(cls, api: 'AsyncGeoboxClient', name: str, user_id: int = None) -> Union['AsyncVectorLayerView', None]:
203
+ """
204
+ [async] Get a view by name
205
+
206
+ Args:
207
+ api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
208
+ name (str): the name of the view to get
209
+ user_id (int, optional): specific user. privileges required.
210
+
211
+ Returns:
212
+ AsyncVectorLayerView | None: returns the view if a view matches the given name, else None
213
+
214
+ Example:
215
+ >>> from geobox.aio import AsyncGeoboxClient
216
+ >>> from geobox.aio.view import AsyncVectorLayerView
217
+ >>> async with AsyncGeoboxClient() as client:
218
+ >>> view = await AsyncVectorLayerView.get_view_by_name(client, name='test')
219
+ or
220
+ >>> view = await client.get_view_by_name(name='test')
221
+ """
222
+ views = await cls.get_views(api, q=f"name = '{name}'", user_id=user_id)
223
+ if views and views[0].name == name:
224
+ return views[0]
225
+ else:
226
+ return None
227
+
228
+
229
+ async def update(self, **kwargs) -> Dict:
230
+ """
231
+ [async] Update the vector layer view.
232
+
233
+ Keyword Args:
234
+ name (str): The name of the vector layer view.
235
+ display_name (str): The display name of the vector layer view.
236
+ description (str): The description of the vector layer view.
237
+
238
+ Returns:
239
+ Dict: The updated vector layer view.
240
+
241
+ Raises:
242
+ ValidationError: If the update data is invalid.
243
+
244
+ Example:
245
+ >>> from geobox.aio import AsyncGeoboxClient
246
+ >>> from geobox.aio.view import AsyncVectorLayerView
247
+ >>> async with AsyncGeoboxClient() as client:
248
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
249
+ >>> await view.update(name="new_name")
250
+ >>> await view.update(display_name="new_display_name")
251
+ >>> await view.update(description="new_description")
252
+ """
253
+ return await super().update(name=kwargs.get('name'), display_name=kwargs.get('display_name'), description=kwargs.get('description'))
254
+
255
+
256
+ async def delete(self) -> None:
257
+ """
258
+ [async] Delete the vector layer view.
259
+
260
+ Returns:
261
+ None
262
+
263
+ Example:
264
+ >>> from geobox.aio import AsyncGeoboxClient
265
+ >>> from geobox.aio.view import AsyncVectorLayerView
266
+ >>> async with AsyncGeoboxClient() as client:
267
+ >>> view = async AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
268
+ >>> async view.delete()
269
+ """
270
+ return await super()._delete(self.endpoint)
271
+
272
+
273
+ async def share(self, users: List['AsyncUser']) -> None:
274
+ """
275
+ [async] Shares the view with specified users.
276
+
277
+ Args:
278
+ users (List[AsyncUser]): The list of user IDs to share the view with.
279
+
280
+ Returns:
281
+ None
282
+
283
+ Example:
284
+ >>> from geobox.aio import AsyncGeoboxClient
285
+ >>> from geobox.aio.view import AsyncVectorLayerView
286
+ >>> async with AsyncGeoboxClient() as client:
287
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
288
+ >>> users = await client.search_users(search='John')
289
+ >>> await view.share(users=users)
290
+ """
291
+ await super()._share(self.endpoint, users)
292
+
293
+
294
+ async def unshare(self, users: List['AsyncUser']) -> None:
295
+ """
296
+ [async] Unshares the view with specified users.
297
+
298
+ Args:
299
+ users (List[AsyncUser]): The list of user IDs to unshare the view with.
300
+
301
+ Returns:
302
+ None
303
+
304
+ Example:
305
+ >>> from geobox.aio import AsyncGeoboxClient
306
+ >>> from geobox.aio.view import AsyncVectorLayerView
307
+ >>> async with AsyncGeoboxClient() as client:
308
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
309
+ >>> users = await client.search_users(search='John')
310
+ >>> await view.unshare(users=users)
311
+ """
312
+ await super()._unshare(self.endpoint, users)
313
+
314
+
315
+ async def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['AsyncUser']:
316
+ """
317
+ [async] Retrieves the list of users the view is shared with.
318
+
319
+ Args:
320
+ search (str, optional): The search query.
321
+ skip (int, optional): The number of users to skip.
322
+ limit (int, optional): The maximum number of users to retrieve.
323
+
324
+ Returns:
325
+ List[AsyncUser]: The list of shared users.
326
+
327
+ Example:
328
+ >>> from geobox.aio import AsyncGeoboxClient
329
+ >>> from geobox.aio.view import AsyncVectorLayerView
330
+ >>> async with AsyncGeoboxClient() as client:
331
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
332
+ >>> await view.get_shared_users(search='John', skip=0, limit=10)
333
+ """
334
+ params = {
335
+ 'search': search,
336
+ 'skip': skip,
337
+ 'limit': limit
338
+ }
339
+ return await super()._get_shared_users(self.endpoint, params)
340
+
341
+
342
+ async def get_fields(self) -> List['AsyncField']:
343
+ """
344
+ [async] Get all fields in the vector layer view.
345
+
346
+ Returns:
347
+ List[AsyncField]: A list of Field instances representing the vector layer view's fields.
348
+
349
+ Raises:
350
+ ApiRequestError: If the API request fails.
351
+
352
+ Example:
353
+ >>> from geobox.aio import AsyncGeoboxClient
354
+ >>> from geobox.aio.view import AsyncVectorLayerView
355
+ >>> async with AsyncGeoboxClient() as client:
356
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
357
+ >>> fields = await view.get_fields()
358
+ """
359
+ return await super().get_fields()
360
+
361
+
362
+ async def get_field(self, field_id: int) -> 'AsyncField':
363
+ """
364
+ [async] Get a specific field by its ID or name.
365
+
366
+ Args:
367
+ field_id (int): The ID of the field to retrieve.
368
+
369
+ Returns:
370
+ AsyncField: The requested field instance.
371
+
372
+ Raises:
373
+ NotFoundError: If the field with the specified ID is not found.
374
+ ApiRequestError: If the API request fails.
375
+
376
+ Example:
377
+ >>> from geobox.aio import AsyncGeoboxClient
378
+ >>> from geobox.aio.view import AsyncVectorLayerView
379
+ >>> async with AsyncGeoboxClient() as client:
380
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
381
+ >>> field = await view.get_field(id=1)
382
+ """
383
+ return await super().get_field(field_id)
384
+
385
+
386
+ async def get_field_by_name(self, name: str) -> 'AsyncField':
387
+ """
388
+ [async] Get a specific field by its name.
389
+
390
+ Args:
391
+ name (str, optional): The name of the field to retrieve.
392
+
393
+ Returns:
394
+ AsyncField: The requested field instance.
395
+
396
+ Raises:
397
+ NotFoundError: If the field with the specified name is not found.
398
+
399
+ Example:
400
+ >>> from geobox.aio import AsyncGeoboxClient
401
+ >>> from geobox.aio.view import AsyncVectorLayerView
402
+ >>> async with AsyncGeoboxClient() as client:
403
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
404
+ >>> field = await view.get_field_by_name(name='test')
405
+ """
406
+ return await super().get_field_by_name(name)
407
+
408
+
409
+ async def calculate_field(self,
410
+ target_field: str,
411
+ expression: str,
412
+ q: str = None,
413
+ bbox: List[float] = None,
414
+ bbox_srid: int = None,
415
+ feature_ids: List = None,
416
+ run_async: bool = True,
417
+ user_id: int = None) -> Union['AsyncTask', Dict]:
418
+ """
419
+ [async] Calculate values for a field based on an expression.
420
+
421
+ Args:
422
+ target_field (str): The field to calculate values for.
423
+ expression (str): The expression to use for calculation.
424
+ q (Optional[str]): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
425
+ bbox (Optional[List[float]]): Bounding box to filter features.
426
+ bbox_srid (Optional[int]): Spatial reference ID for the bounding box.
427
+ feature_ids (Optional[List[int]]): List of specific feature IDs to include.
428
+ run_async (Optional[bool]): Whether to run the calculation asynchronously.
429
+ user_id (Optional[int]): ID of the user running the calculation.
430
+
431
+ Returns:
432
+ AsyncTask | Dict: The task instance of the calculation operation or the api response if the run_async=False.
433
+
434
+ Raises:
435
+ ValidationError: If the calculation parameters are invalid.
436
+ ApiRequestError: If the API request fails.
437
+
438
+ Example:
439
+ >>> from geobox.aio import AsyncGeoboxClient
440
+ >>> from geobox.aio.view import AsyncVectorLayerView
441
+ >>> async with AsyncGeoboxClient() as client:
442
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
443
+ >>> task = await view.calculate_field(target_field="target_field",
444
+ ... expression="expression",
445
+ ... q="name like 'my_layer'",
446
+ ... bbox=[10, 20, 30, 40],
447
+ ... bbox_srid=3857,
448
+ ... feature_ids=[1, 2, 3],
449
+ ... run_async=True)
450
+ """
451
+ return await super().calculate_field(target_field, expression, q, bbox, bbox_srid, feature_ids, run_async, user_id)
452
+
453
+
454
+ async def get_features(self, **kwargs) -> Union[List['AsyncFeature'], int]:
455
+ """
456
+ [async] Get features from the layer with optional filtering and pagination.
457
+
458
+ Keyword Args:
459
+ quant_factor (int): Quantization factor. This parameter is only used by topojson encoder and is ignored for other formats. Higher quantizaion value means higher geometry precision. default is 1000000.
460
+ skip (int): Number of features to skip. default is 0.
461
+ limit (int): Maximum number of features to return. default is 100.
462
+ user_id (int): Specific user. privileges required.
463
+ 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.
464
+ search_fields (str): comma separated list of fields for searching.
465
+ skip_geometry (bool): Whether to exclude geometry data. default is False.
466
+ return_count (bool): Whether to return total count. default is False.
467
+ feature_ids (List[int]): comma separated list of feature ids which should be filtered.
468
+ select_fields (str): comma separated field names which should be included to the result. default is "[ALL]".
469
+ skip_fields (str): comma separated field names which should be excluded from the result.
470
+ out_srid (int): srid (epsg code) of result features. e.g. 4326. default is 3857
471
+ order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, length D. NOTE: "A" denotes ascending order and "D" denotes descending order.
472
+ q (str): query filter based on OGC CQL standard. e.g. Name LIKE '%GIS%' AND INTERSECTS(geometry, 'SRID=3857;POLYGON((4901948 2885079, 7049893 2885079, 7049893 4833901, 4901948 4833901, 4901948 2885079))').
473
+ bbox (str): Bounding box to filter features by. e.g. [50.275, 35.1195, 51.4459, 36.0416].
474
+ bbox_srid (int): srid (epsg code) of bbox. e.g. 4326. default is 3857.
475
+
476
+ Returns:
477
+ List[AsyncFeature] | int: A list of Feature instances or the features count if return_count is True.
478
+
479
+
480
+ Example:
481
+ >>> from geobox.aio import AsyncGeoboxClient
482
+ >>> from geobox.aio.view import AsyncVectorLayerView
483
+ >>> async with AsyncGeoboxClient() as client:
484
+ >>> layer = await AsyncVectorLayerView(api=client, name="my_layer", layer_type=LayerType.Point)
485
+ >>> features = await layer.get_features(quant_factor=1000000,
486
+ ... skip=0,
487
+ ... limit=100,
488
+ ... skip_geometry=False,
489
+ ... return_count=False,
490
+ ... select_fields="fclass, osm_id",
491
+ ... out_srid=4326,
492
+ ... bbox_srid=4326)
493
+ """
494
+ return await super().get_features(**kwargs)
495
+
496
+
497
+ async def get_feature(self, feature_id: int, out_srid: int = AsyncFeature.BASE_SRID) -> 'AsyncFeature':
498
+ """
499
+ [async] Get a specific feature by its ID.
500
+
501
+ Args:
502
+ feature_id (int): The ID of the feature to retrieve.
503
+ out_srid (int, optional): Output spatial reference ID
504
+
505
+ Returns:
506
+ AsyncFeature: The requested feature instance.
507
+
508
+ Raises:
509
+ NotFoundError: If the feature with the specified ID is not found.
510
+
511
+ Example:
512
+ >>> from geobox.aio import AsyncGeoboxClient
513
+ >>> from geobox.aio.view import AsyncVectorLayerView
514
+ >>> async with AsyncGeoboxClient() as client:
515
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
516
+ >>> feature = await view.get_feature(id=1)
517
+ """
518
+ return await super().get_feature(feature_id, out_srid)
519
+
520
+
521
+ async def create_feature(self, geojson: Dict) -> 'AsyncFeature':
522
+ """
523
+ [async] Create a new feature in the layer.
524
+
525
+ Args:
526
+ geojson (dict): The feature data including properties and geometry.
527
+
528
+ Returns:
529
+ AsyncFeature: The newly created feature instance.
530
+
531
+ Raises:
532
+ ValidationError: If the feature data is invalid.
533
+
534
+ Example:
535
+ >>> from geobox.aio import AsyncGeoboxClient
536
+ >>> from geobox.aio.view import AsyncVectorLayerView
537
+ >>> async with AsyncGeoboxClient() as client:
538
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
539
+ >>> feature = await view.create_feature(geojson=geojson)
540
+ """
541
+ return await super().create_feature(geojson)
542
+
543
+
544
+ async def delete_features(self,
545
+ q: str = None,
546
+ bbox: List[float] = None,
547
+ bbox_srid: int = None,
548
+ feature_ids: List[int] = None,
549
+ run_async: bool = True,
550
+ user_id: int = None) -> Union['AsyncTask', Dict]:
551
+ """
552
+ [async] Delete features from the layer based on specified criteria.
553
+
554
+ Args:
555
+ q (Optional[str]): Query to filter features to delete.
556
+ bbox (Optional[List[float]]): Bounding box to filter features.
557
+ bbox_srid (Optional[int]): Spatial reference ID for the bounding box.
558
+ feature_ids (Optional[List[int]]): List of specific feature IDs to delete.
559
+ run_async (Optional[bool]): Whether to run the deletion asynchronously.
560
+ user_id (Optional[int]): ID of the user performing the deletion.
561
+
562
+ Returns:
563
+ AsyncTask | Dict: The task instance of the deletion operation or the api response if run_async=False.
564
+
565
+ Raises:
566
+ ValidationError: If the deletion parameters are invalid.
567
+
568
+ Example:
569
+ >>> from geobox.aio import AsyncGeoboxClient
570
+ >>> from geobox.aio.view import AsyncVectorLayerView
571
+ >>> async with AsyncGeoboxClient() as client:
572
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
573
+ >>> await view.delete_features(q="name like 'my_layer'",
574
+ ... bbox=[10, 20, 30, 40],
575
+ ... bbox_srid=3857,
576
+ ... feature_ids=[1, 2, 3],
577
+ ... run_async=True)
578
+ """
579
+ return await super().delete_features(q, bbox, bbox_srid, feature_ids, run_async, user_id)
580
+
581
+
582
+ async def import_features(self,
583
+ file: 'AsyncFile',
584
+ input_geom_type: 'InputGeomType' = None,
585
+ input_layer_name: str = None,
586
+ input_dataset: str = None,
587
+ user_id: int = None,
588
+ input_srid: int = None,
589
+ file_encoding: str = "utf-8",
590
+ replace_domain_codes_by_values: bool = False,
591
+ report_errors: bool = True) -> 'AsyncTask':
592
+ """
593
+ [async] Import features from a file into the layer.
594
+
595
+ Args:
596
+ file (File): file object to import.
597
+ input_geom_type (InputGeomType, optional): Type of geometry in the input file.
598
+ input_layer_name (str, optional): Name of the layer in the input file.
599
+ input_dataset (str, optional): Name of the dataset in the input file.
600
+ user_id (int, optional): Specific user.privileges requied.
601
+ input_srid (int, optional): Spatial reference ID of the input data.
602
+ file_encoding (str, optional): Character encoding of the input file.
603
+ replace_domain_codes_by_values (bool, optional): Whether to replace domain codes with values.
604
+ report_errors (bool, optional): Whether to report import errors.
605
+
606
+ Returns:
607
+ Task: The task instance of the import operation.
608
+
609
+ Raises:
610
+ ValidationError: If the import parameters are invalid.
611
+
612
+ Example:
613
+ >>> from geobox.aio import AsyncGeoboxClient
614
+ >>> from geobox.aio.view import AsyncVectorLayerView
615
+ >>> async with AsyncGeoboxClient() as client:
616
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
617
+ >>> file = await client.get_file(uuid="12345678-1234-5678-1234-567812345678")
618
+ >>> task = await view.import_features(file=file,
619
+ ... input_geom_type=InputGeomType.POINT,
620
+ ... input_layer="my_layer",
621
+ ... input_dataset="my_dataset",
622
+ ... input_srid=3857,
623
+ ... file_encoding="utf-8",
624
+ ... replace_domain_codes_by_values=False,
625
+ ... report_errors=True)
626
+ """
627
+ return await super().import_features(file,
628
+ input_geom_type,
629
+ input_layer_name,
630
+ input_dataset,
631
+ user_id,
632
+ input_srid,
633
+ file_encoding,
634
+ replace_domain_codes_by_values,
635
+ report_errors)
636
+
637
+
638
+ async def export_features(self,
639
+ out_filename: str,
640
+ out_format: 'FileOutputFormat',
641
+ replace_domain_codes_by_values: bool = False,
642
+ run_async: bool = True,
643
+ bbox: List[float] = None,
644
+ out_srid: int = None,
645
+ zipped: bool = True,
646
+ feature_ids: List[int] = None,
647
+ bbox_srid: int = None,
648
+ q: str = None,
649
+ fields: List[str] = None) -> Union['AsyncTask', Dict]:
650
+ """
651
+ [async] Export features from the layer to a file.
652
+
653
+ Args:
654
+ out_filename (str): Name of the output file.
655
+ out_format (FileOutputFormat): Format of the output file (e.g., 'Shapefile', 'GPKG', 'GeoJSON', 'CSV', 'KML', 'DXF').
656
+ replace_domain_codes_by_values (bool, optional): Whether to replace domain codes with values.
657
+ run_async (bool, optional): Whether to run the export asynchronously.
658
+ bbox (List[float], optional): Bounding box to filter features.
659
+ out_srid (int, optional): Spatial reference ID for the output.
660
+ zipped (bool, optional): Whether to compress the output file.
661
+ feature_ids (List[int], optional): List of specific feature IDs to export.
662
+ bbox_srid (int, optional): Spatial reference ID for the bounding box.
663
+ q (str, optional): Query to filter features.
664
+ fields (List[str], optional): List of fields to include in the export.
665
+
666
+ Returns:
667
+ AsyncTask | Dict: The task instance of the export operation or the api response if run_async=False.
668
+
669
+ Raises:
670
+ ValidationError: If the export parameters are invalid.
671
+ ApiRequestError: If the API request fails.
672
+
673
+ Example:
674
+ >>> from geobox.aio import AsyncGeoboxClient
675
+ >>> from geobox.aio.view import AsyncVectorLayerView
676
+ >>> async with AsyncGeoboxClient() as client:
677
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
678
+ >>> task = await view.export_features(out_filename="output.shp",
679
+ ... out_format="shp",
680
+ ... replace_domain_codes_by_values=False,
681
+ ... run_async=True,
682
+ ... bbox=[10, 20, 30, 40],
683
+ ... out_srid=3857,
684
+ ... zipped=True,
685
+ ... feature_ids=[1, 2, 3])
686
+ """
687
+ return await super().export_features(out_filename,
688
+ out_format,
689
+ replace_domain_codes_by_values,
690
+ run_async,
691
+ bbox,
692
+ out_srid,
693
+ zipped,
694
+ feature_ids,
695
+ bbox_srid,
696
+ q,
697
+ fields)
698
+
699
+
700
+ def get_tile_pbf_url(self, x: int = '{x}', y: int = '{y}', z: int = '{z}') -> str:
701
+ """
702
+ Get a vector tile pbf url for the view.
703
+
704
+ Args:
705
+ x (int): X coordinate of the tile.
706
+ y (int): Y coordinate of the tile.
707
+ z (int): Zoom level of the tile.
708
+
709
+ Returns:
710
+ str: the vector tile url.
711
+
712
+ Example:
713
+ >>> from geobox.aio import AsyncGeoboxClient
714
+ >>> from geobox.aio.view import AsyncVectorLayerView
715
+ >>> async with AsyncGeoboxClient() as client:
716
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
717
+ >>> tile = view.get_tile(x=10, y=20, z=1)
718
+ """
719
+ return super().get_tile_pbf_url(x, y, z)
720
+
721
+
722
+ async def get_tile_json(self) -> Dict:
723
+ """
724
+ [async] Get the vector tile JSON configuration for the layer.
725
+
726
+ Returns:
727
+ Dict: The vector tile JSON configuration.
728
+
729
+ Example:
730
+ >>> from geobox.aio import AsyncGeoboxClient
731
+ >>> from geobox.aio.view import AsyncVectorLayerView
732
+ >>> async with AsyncGeoboxClient() as client:
733
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
734
+ >>> tile_json = await view.get_tile_json()
735
+ """
736
+ return await super().get_tile_json()
737
+
738
+
739
+ @property
740
+ async def settings(self) -> Dict:
741
+ """
742
+ [async] Get the layer's settings.
743
+
744
+ Returns:
745
+ Dict: The layer settings.
746
+
747
+ Example:
748
+ >>> from geobox.aio import AsyncGeoboxClient
749
+ >>> from geobox.aio.view import AsyncVectorLayerView
750
+ >>> async with AsyncGeoboxClient() as client:
751
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
752
+ >>> setting = await view.settings
753
+ """
754
+ return await super().settings
755
+
756
+
757
+ async def update_settings(self, settings: Dict) -> Dict:
758
+ """
759
+ [async] Update the settings
760
+
761
+ settings (Dict): settings dictionary
762
+
763
+ Returns:
764
+ Dict: updated settings
765
+
766
+ Example:
767
+ >>> from geobox.aio import AsyncGeoboxClient
768
+ >>> async with AsyncGeoboxClient() as client:
769
+ >>> view1 = await client.get_view(uuid="12345678-1234-5678-1234-567812345678")
770
+ >>> view2 = await client.get_view(uuid="12345678-1234-5678-1234-567812345678")
771
+ >>> await view1.update_settings(view2.settings)
772
+ """
773
+ return await super().update_settings(settings)
774
+
775
+
776
+ async def set_settings(self, **kwargs) -> Dict:
777
+ """
778
+ [async] Set the settings of the Vector Layer.
779
+
780
+ Keyword Args:
781
+ title_field (str): The field to use as the title.
782
+ domain_display_type (str): The type of domain display.
783
+ allow_export (bool): Whether to allow export.
784
+ editable (bool): Whether to allow editing.
785
+ edit_geometry (bool): Whether to allow editing the geometry.
786
+ editable_attributes (str): The attributes to allow editing.
787
+ allow_insert (bool): Whether to allow inserting.
788
+ allow_delete (bool): Whether to allow deleting.
789
+ min_zoom (int): The minimum zoom level.
790
+ max_zoom (int): The maximum zoom level.
791
+ max_features (int): The maximum number of features.
792
+ filter_features (bool): Whether to filter features.
793
+ fields (List[str]): The fields to include in the layer.
794
+ use_cache (bool): Whether to use caching.
795
+ cache_until_zoom (int): The zoom level to cache until.
796
+
797
+ Returns:
798
+ Dict: The updated settings.
799
+
800
+ Raises:
801
+ ValidationError: If the settings data is invalid.
802
+
803
+ Example:
804
+ >>> from geobox.aio import AsyncGeoboxClient
805
+ >>> from geobox.aio.view import AsyncVectorLayerView
806
+ >>> async with AsyncGeoboxClient() as client:
807
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
808
+ >>> await view.set_setting(title_field="name",
809
+ ... domain_display_type="Value",
810
+ ... allow_export=True,
811
+ ... editable=True,
812
+ ... edit_geometry=True,
813
+ ... editable_attributes="[ALL]",
814
+ ... allow_insert=True,
815
+ ... allow_delete=True,
816
+ ... min_zoom=0,
817
+ ... max_zoom=24,
818
+ ... max_features=65536,
819
+ ... filter_features=True,
820
+ ... fields=["id"],
821
+ ... use_cache=True,
822
+ ... cache_until_zoom=17)
823
+ """
824
+ return await super().set_settings(**kwargs)
825
+
826
+
827
+ async def seed_cache(self, from_zoom: int = None, to_zoom: int = None, ignore_cache: bool = False, workers: int = 1, user_id: int = None) -> List['AsyncTask']:
828
+ """
829
+ [async] Seed the cache for the view.
830
+
831
+ Args:
832
+ from_zoom (int, optional): The zoom level to start caching from.
833
+ to_zoom (int, optional): The zoom level to stop caching at.
834
+ ignore_cache (bool, optional): Whether to ignore the cache. default is False.
835
+ workers (int, optional): The number of workers to use. default is 1.
836
+ user_id (int, optional): specified user. privileges required.
837
+
838
+ Returns:
839
+ List[Task]: The task instance of the cache seeding operation.
840
+
841
+ Example:
842
+ >>> from geobox.aio import AsyncGeoboxClient
843
+ >>> from geobox.aio.view import AsyncVectorLayerView
844
+ >>> async with AsyncGeoboxClient() as client:
845
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
846
+ >>> task = await view.cache_seed(from_zoom=0, to_zoom=10, ignore_cache=False, workers=1)
847
+ """
848
+ return await super().seed_cache(from_zoom, to_zoom, ignore_cache, workers, user_id)
849
+
850
+
851
+ async def clear_cache(self) -> None:
852
+ """
853
+ [async] Clear the view's cache.
854
+
855
+ Returns:
856
+ None
857
+
858
+ Example:
859
+ >>> from geobox.aio import AsyncGeoboxClient
860
+ >>> from geobox.aio.view import AsyncVectorLayerView
861
+ >>> async with AsyncGeoboxClient() as client:
862
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
863
+ >>> await view.clear_cache()
864
+ """
865
+ return await super().clear_cache()
866
+
867
+
868
+ @property
869
+ async def cache_size(self) -> int:
870
+ """
871
+ [async] Get the size of the view's cache.
872
+
873
+ Returns:
874
+ int: The size of the view's cache.
875
+
876
+ Example:
877
+ >>> from geobox.aio import AsyncGeoboxClient
878
+ >>> from geobox.aio.view import AsyncVectorLayerView
879
+ >>> async with AsyncGeoboxClient() as client:
880
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
881
+ >>> await view.cache_size
882
+ """
883
+ return await super().cache_size
884
+
885
+
886
+ async def update_stats(self) -> None:
887
+ """
888
+ [async] Update the view's statistics.
889
+
890
+ Returns:
891
+ None
892
+
893
+ Example:
894
+ >>> from geobox.aio import AsyncGeoboxClient
895
+ >>> from geobox.aio.view import AsyncVectorLayerView
896
+ >>> async with AsyncGeoboxClient() as client:
897
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
898
+ >>> await view.update_stats()
899
+ """
900
+ return await super().update_stats()
901
+
902
+
903
+ async def prune_edited_areas(self) -> None:
904
+ """
905
+ [async] Prune edited areas. This method eliminates edited areas when there are too many of them. Cache builder uses this edited areas for partial cache generating.
906
+
907
+ Returns:
908
+ None
909
+
910
+ Example:
911
+ >>> from geobox.aio import AsyncGeoboxClient
912
+ >>> from geobox.aio.view import AsyncVectorLayerView
913
+ >>> async with AsyncGeoboxClient() as client:
914
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
915
+ >>> await view.prune_edited_areas()
916
+ """
917
+ return await super().prune_edited_areas()
918
+
919
+
920
+ async def get_attachments(self, **kwargs) -> List['AsyncAttachment']:
921
+ """
922
+ [async] Get the resouces attachments
923
+
924
+ Keyword Args:
925
+ element_id (str): the id of the element with attachment.
926
+ search (str): search term for keyword-based searching among all textual fields.
927
+ 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.
928
+ skip (int): Number of items to skip. default is 0.
929
+ limit (int): Number of items to return. default is 10.
930
+ return_count (bool): Whether to return total count. default is False.
931
+
932
+ Returns:
933
+ List[AsyncAttachment] | int: A list of attachments instances or the total number of attachments.
934
+
935
+ Raises:
936
+ TypeError: if the resource type is not supported
937
+
938
+ Example:
939
+ >>> from geobox.aio import AsyncGeoboxClient
940
+ >>> from geobox.aio.view import AsyncVectorLayerView
941
+ >>> async with AsyncGeoboxClient() as client:
942
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
943
+ >>> await view.get_attachments()
944
+ """
945
+ from .attachment import AsyncAttachment
946
+
947
+ return await AsyncAttachment.get_attachments(self.api, resource=self, **kwargs)
948
+
949
+
950
+ async def create_attachment(self,
951
+ name: str,
952
+ loc_x: int,
953
+ loc_y: int,
954
+ file: 'AsyncFile',
955
+ feature: 'AsyncFeature' = None,
956
+ display_name: str = None,
957
+ description: str = None) -> 'Attachment':
958
+ """
959
+ [async] Create a new Attachment.
960
+
961
+ Args:
962
+ name (str): The name of the scene.
963
+ loc_x (int): x parameter of the attachment location.
964
+ loc_y (int): y parameter of the attachment location.
965
+ file (AsyncFile): the file object.
966
+ feature (AsyncFeature, optional): the feature object.
967
+ display_name (str, optional): The display name of the scene.
968
+ description (str, optional): The description of the scene.
969
+
970
+ Returns:
971
+ Attachment: The newly created Attachment instance.
972
+
973
+ Raises:
974
+ ValidationError: If the Attachment data is invalid.
975
+
976
+ Example:
977
+ >>> from geobox.aio import AsyncGeoboxClient
978
+ >>> from geobox.aio.view import AsyncVectorLayerView
979
+ >>> async with AsyncGeoboxClient() as client:
980
+ >>> view = await AsyncVectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
981
+ >>> files = await client.get_files()
982
+ >>> file = file[0]
983
+ >>> await view.create_attachment(name='test', loc_x=10, loc_y=10, file=file)
984
+ """
985
+ from .attachment import AsyncAttachment
986
+
987
+ return await AsyncAttachment.create_attachment(self.api,
988
+ name=name,
989
+ loc_x=loc_x,
990
+ loc_y=loc_y,
991
+ resource=self,
992
+ file=file,
993
+ feature=feature,
994
+ display_name=display_name,
995
+ description=description)
996
+
997
+
998
+ def to_sync(self, sync_client: 'GeoboxClient') -> 'VectorLayerView':
999
+ """
1000
+ Switch to sync version of the view instance to have access to the sync methods
1001
+
1002
+ Args:
1003
+ sync_client (GeoboxClient): The sync version of the GeoboxClient instance for making requests.
1004
+
1005
+ Returns:
1006
+ VectorLayerView: the sync instance of the view.
1007
+
1008
+ Example:
1009
+ >>> from geobox import Geoboxclient
1010
+ >>> from geobox.aio import AsyncGeoboxClient
1011
+ >>> from geobox.aio.view import AsyncVectorLayerView
1012
+ >>> client = GeoboxClient()
1013
+ >>> async with AsyncGeoboxClient() as async_client:
1014
+ >>> view = await AsyncVectorLayerView.get_view(async_client, uuid="12345678-1234-5678-1234-567812345678")
1015
+ >>> sync_view = view.to_sync(client)
1016
+ """
1017
+ from ..view import VectorLayerView
1018
+
1019
+ return VectorLayerView(api=sync_client, uuid=self.uuid, layer_type=self.layer_type, data=self.data)