pygeobox 1.0.1__py3-none-any.whl → 1.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pygeobox/view.py CHANGED
@@ -1,859 +1,859 @@
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 GeoboxClient
8
- from .field import Field
9
- from .user import User
10
- from .enums import InputGeomType, FieldType
11
- from .task import Task
12
-
13
-
14
- class VectorLayerView(VectorLayer):
15
- """
16
- A class representing a vector layer view in Geobox.
17
-
18
- This class provides functionality to create, manage, and manipulate vector layer views.
19
- It supports various operations including CRUD operations on views, as well as advanced operations like getting fields, features, and sharing views.
20
- It also provides properties to access the view data, and a method to update the view.
21
- """
22
- BASE_ENDPOINT = 'vectorLayerViews/'
23
-
24
- def __init__(self,
25
- api: 'GeoboxClient',
26
- uuid: str,
27
- layer_type: 'LayerType',
28
- data: Optional[Dict] = {}) -> None:
29
- """
30
- Initialize a VectorLayerView instance.
31
-
32
- Args:
33
- api (GeoboxClient): The GeoboxClient instance for making requests.
34
- uuid (str): The UUID of the vector layer view.
35
- layer_type (LayerType): The type of the vector layer view.
36
- data (Dict, optional): The data of the vector layer view.
37
- """
38
- super().__init__(api, uuid, layer_type, data)
39
-
40
-
41
- def __repr__(self) -> str:
42
- """
43
- Return a string representation of the VectorLayerView instance.
44
-
45
- Returns:
46
- str: A string representation of the VectorLayerView instance.
47
- """
48
- return f"VectorLayerView(name={self.name}, layer_type={self.layer_type})"
49
-
50
-
51
- @property
52
- def vector_layer(self) -> 'VectorLayer':
53
- """
54
- Get the vector layer.
55
-
56
- Returns:
57
- VectorLayer: The vector layer.
58
-
59
- Example:
60
- >>> from geobox import GeoboxClient
61
- >>> from geobox.view import VectorLayerView
62
- >>> client = GeoboxClient()
63
- >>> view = VectorLayerView.get_view(client, uuid='e21e085a-8d30-407d-a740-ca9be9122c42')
64
- >>> view.vector_layer
65
- """
66
- return VectorLayer(self.api, self.data['vector_layer']['uuid'], LayerType(self.data['vector_layer']['layer_type']), self.data['vector_layer'])
67
-
68
-
69
- @classmethod
70
- def get_views(cls, api: 'GeoboxClient', **kwargs) -> Union[List['VectorLayerView'], int]:
71
- """
72
- Get vector layer views.
73
-
74
- Args:
75
- api (GeoboxClient): The GeoboxClient instance for making requests.
76
-
77
- Keyword Args:
78
- layer_id(int): The id of the layer.
79
- include_settings(bool): Whether to include the settings of the layer. default is False.
80
- q(str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
81
- 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.
82
- search_fields(str): Comma separated list of fields for searching.
83
- 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.
84
- return_count(bool): Whether to return the count of the layer views. default is False.
85
- skip(int): The number of layer views to skip. minimum is 0.
86
- limit(int): The maximum number of layer views to return. minimum is 1. default is 10.
87
- user_id(int): Specific user. privileges required.
88
- shared(bool): Whether to return shared views. default is False.
89
-
90
- Returns:
91
- list[VectorLayerView] | int: A list of VectorLayerView instances or the layer views count if return_count is True.
92
-
93
- Example:
94
- >>> from geobox import GeoboxClient
95
- >>> from geobox.view import VectorLayerView
96
- >>> client = GeoboxClient()
97
- >>> views = VectorLayerView.get_views(client,
98
- layer_id=1,
99
- include_settings=True,
100
- search="test",
101
- search_fields="name",
102
- order_by="name A",
103
- return_count=False,
104
- skip=0,
105
- limit=10,
106
- shared=True)
107
- or
108
- >>> views = client.get_views(layer_id=1,
109
- include_settings=True,
110
- search="test",
111
- search_fields="name",
112
- order_by="name A",
113
- return_count=False,
114
- skip=0,
115
- limit=10,
116
- shared=True)
117
- """
118
- params = {
119
- 'f': 'json',
120
- 'include_settings': kwargs.get('include_settings', False),
121
- 'temporary': kwargs.get('temporary', False),
122
- 'q': kwargs.get('q', None),
123
- 'search': kwargs.get('search', None),
124
- 'search_fields': kwargs.get('search_fields', None),
125
- 'order_by': kwargs.get('order_by', None),
126
- 'return_count': kwargs.get('return_count', False),
127
- 'skip': kwargs.get('skip', 0),
128
- 'limit': kwargs.get('limit', 10),
129
- 'user_id': kwargs.get('user_id', None),
130
- 'shared': kwargs.get('shared', False)
131
- }
132
- return super()._get_list(api=api,
133
- endpoint=cls.BASE_ENDPOINT,
134
- params=params,
135
- factory_func=lambda api, item: VectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
136
-
137
-
138
- @classmethod
139
- def get_views_by_ids(cls, api: 'GeoboxClient', ids: List[int], user_id: int = None, include_settings: bool = False) -> List['VectorLayerView']:
140
- """
141
- Get vector layer views by their IDs.
142
-
143
- Args:
144
- api (GeoboxClient): The GeoboxClient instance for making requests.
145
- ids (List[int]): list of comma separated layer ids to be returned. e.g. 1, 2, 3
146
- user_id (int, optional): specific user. privileges required.
147
- include_settings (bool, optional): Whether to include the settings of the vector layer views. default is False.
148
-
149
- Returns:
150
- List[VectorLayerView]: A list of VectorLayerView instances.
151
-
152
- Example:
153
- >>> from geobox import GeoboxClient
154
- >>> from geobox.view import VectorLayerView
155
- >>> client = GeoboxClient()
156
- >>> views = VectorLayerView.get_views_by_ids(client, ids=[1,2,3])
157
- or
158
- >>> views = client.get_views_by_ids(ids=[1,2,3])
159
- """
160
- params = {
161
- 'ids': ids,
162
- 'user_id': user_id,
163
- 'include_settings': include_settings
164
- }
165
- return super()._get_list_by_ids(api=api,
166
- endpoint=f'{cls.BASE_ENDPOINT}get-views/',
167
- params=params,
168
- factory_func=lambda api, item: VectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
169
-
170
-
171
- @classmethod
172
- def get_view(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'VectorLayerView':
173
- """
174
- Get a specific vector layer view by its UUID.
175
-
176
- Args:
177
- api (GeoboxClient): The GeoboxClient instance for making requests.
178
- uuid (str): The UUID of the vector layer view.
179
- user_id (int, optional): Specific user. privileges required.
180
-
181
- Returns:
182
- VectorLayerView: A VectorLayerView instance.
183
-
184
- Example:
185
- >>> from geobox import GeoboxClient
186
- >>> from geobox.view import VectorLayerView
187
- >>> client = GeoboxClient()
188
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
189
- or
190
- >>> view = client.get_view(uuid="12345678-1234-5678-1234-567812345678")
191
- """
192
- params = {
193
- 'f': 'json',
194
- 'user_id': user_id
195
- }
196
- return super()._get_detail(api=api,
197
- endpoint=cls.BASE_ENDPOINT,
198
- uuid=uuid,
199
- params=params,
200
- factory_func=lambda api, item: VectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
201
-
202
-
203
- @classmethod
204
- def get_view_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['View', None]:
205
- """
206
- Get a view by name
207
-
208
- Args:
209
- api (GeoboxClient): The GeoboxClient instance for making requests.
210
- name (str): the name of the view to get
211
- user_id (int, optional): specific user. privileges required.
212
-
213
- Returns:
214
- View | None: returns the view if a view matches the given name, else None
215
-
216
- Example:
217
- >>> from geobox import GeoboxClient
218
- >>> from geobox.view import VectorLayerView
219
- >>> client = GeoboxClient()
220
- >>> view = VectorLayerView.get_view_by_name(client, name='test')
221
- or
222
- >>> view = client.get_view_by_name(name='test')
223
- """
224
- views = cls.get_views(api, q=f"name = '{name}'", user_id=user_id)
225
- if views and views[0].name == name:
226
- return views[0]
227
- else:
228
- return None
229
-
230
-
231
- def update(self, **kwargs) -> Dict:
232
- """
233
- Update the vector layer view.
234
-
235
- Keyword Args:
236
- name (str): The name of the vector layer view.
237
- display_name (str): The display name of the vector layer view.
238
- description (str): The description of the vector layer view.
239
-
240
- Returns:
241
- Dict: The updated vector layer view.
242
-
243
- Raises:
244
- ValidationError: If the update data is invalid.
245
-
246
- Example:
247
- >>> from geobox import GeoboxClient
248
- >>> from geobox.view import VectorLayerView
249
- >>> client = GeoboxClient()
250
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
251
- >>> view.update_view(name="new_name")
252
- >>> view.update_view(display_name="new_display_name")
253
- >>> view.update_view(description="new_description")
254
- """
255
- return super().update(name=kwargs.get('name'), display_name=kwargs.get('display_name'), description=kwargs.get('description'))
256
-
257
-
258
- def delete(self) -> None:
259
- """
260
- Delete the vector layer view.
261
-
262
- Returns:
263
- None
264
-
265
- Example:
266
- >>> from geobox import GeoboxClient
267
- >>> from geobox.view import VectorLayerView
268
- >>> client = GeoboxClient()
269
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
270
- >>> view.delete()
271
- """
272
- return super().delete()
273
-
274
-
275
- def share(self, users: List['User']) -> None:
276
- """
277
- Shares the view with specified users.
278
-
279
- Args:
280
- users (List[User]): The list of user IDs to share the view with.
281
-
282
- Returns:
283
- None
284
-
285
- Example:
286
- >>> from geobox import GeoboxClient
287
- >>> from geobox.view import VectorLayerView
288
- >>> client = GeoboxClient()
289
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
290
- >>> users = client.search_users(search='John')
291
- >>> view.share(users=users)
292
- """
293
- super()._share(self.endpoint, users)
294
-
295
-
296
- def unshare(self, users: List['User']) -> None:
297
- """
298
- Unshares the view with specified users.
299
-
300
- Args:
301
- users (List[User]): The list of user IDs to unshare the view with.
302
-
303
- Returns:
304
- None
305
-
306
- Example:
307
- >>> from geobox import GeoboxClient
308
- >>> from geobox.view import VectorLayerView
309
- >>> client = GeoboxClient()
310
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
311
- >>> users = client.search_users(search='John')
312
- >>> view.unshare(users=users)
313
- """
314
- super()._unshare(self.endpoint, users)
315
-
316
-
317
- def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
318
- """
319
- Retrieves the list of users the view is shared with.
320
-
321
- Args:
322
- search (str, optional): The search query.
323
- skip (int, optional): The number of users to skip.
324
- limit (int, optional): The maximum number of users to retrieve.
325
-
326
- Returns:
327
- List[User]: The list of shared users.
328
-
329
- Example:
330
- >>> from geobox import GeoboxClient
331
- >>> from geobox.view import VectorLayerView
332
- >>> client = GeoboxClient()
333
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
334
- >>> view.get_shared_users(search='John', skip=0, limit=10)
335
- """
336
- params = {
337
- 'search': search,
338
- 'skip': skip,
339
- 'limit': limit
340
- }
341
- return super()._get_shared_users(self.endpoint, params)
342
-
343
-
344
- def get_fields(self) -> List['Field']:
345
- """
346
- Get all fields in the vector layer view.
347
-
348
- Returns:
349
- List[Field]: A list of Field instances representing the vector layer view's fields.
350
-
351
- Raises:
352
- ApiRequestError: If the API request fails.
353
-
354
- Example:
355
- >>> from geobox import GeoboxClient
356
- >>> from geobox.view import VectorLayerView
357
- >>> client = GeoboxClient()
358
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
359
- >>> fields = view.get_fields()
360
- """
361
- return super().get_fields()
362
-
363
-
364
- def get_field(self, field_id: str = None, name: str = None) -> 'Field':
365
- """
366
- Get a specific field by its ID or name.
367
-
368
- Args:
369
- field_id (str): The ID of the field to retrieve.
370
- name (str): The name of the field to retrieve.
371
-
372
- Returns:
373
- Field: The requested field instance.
374
-
375
- Raises:
376
- NotFoundError: If the field with the specified ID is not found.
377
- ApiRequestError: If the API request fails.
378
-
379
- Example:
380
- >>> from geobox import GeoboxClient
381
- >>> from geobox.view import VectorLayerView
382
- >>> client = GeoboxClient()
383
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
384
- >>> field = view.get_field(id="1")
385
- """
386
- return super().get_field(field_id, name)
387
-
388
-
389
- def add_field(self, name: str, data_type: 'FieldType', data: Dict = {}) -> 'Field':
390
- """
391
- Add a new field to the vector layer view.
392
-
393
- Args:
394
- name (str): The name of the new field.
395
- data_type (FieldType): The data type of the new field.
396
- data (Dict): Additional field properties (display_name, description, etc.).
397
-
398
- Returns:
399
- Field: The newly created field instance.
400
-
401
- Raises:
402
- ValidationError: If the field data is invalid.
403
- ApiRequestError: If the API request fails.
404
-
405
- Example:
406
- >>> from geobox import GeoboxClient
407
- >>> from geobox.view import VectorLayerView
408
- >>> client = GeoboxClient()
409
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
410
- >>> field = view.add_field(name="new_field", data_type=FieldType.String)
411
- """
412
- return super().add_field(name, data_type, data)
413
-
414
-
415
- def calculate_field(self, target_field: str, expression: str, q: str = None, bbox: List[float] = None,
416
- bbox_srid: int = None, feature_ids: List = None, run_async: bool = True,
417
- user_id: int = None) -> 'Task':
418
- """
419
- 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
- Task: The task instance of the calculation operation.
433
-
434
- Raises:
435
- ValidationError: If the calculation parameters are invalid.
436
- ApiRequestError: If the API request fails.
437
-
438
- Example:
439
- >>> from geobox import GeoboxClient
440
- >>> from geobox.view import VectorLayerView
441
- >>> client = GeoboxClient()
442
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
443
- >>> task = 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 super().calculate_field(target_field, expression, q, bbox, bbox_srid, feature_ids, run_async, user_id)
452
-
453
-
454
- def get_features(self, **kwargs) -> Union[List['Feature'], int]:
455
- """
456
- 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[Feature] | int: A list of Feature instances or the features count if return_count is True.
478
-
479
-
480
- Example:
481
- >>> from geobox import GeoboxClient
482
- >>> from geobox.view import VectorLayerView
483
- >>> client = GeoboxClient()
484
- >>> layer = VectorLayerView(api=client, name="my_layer", layer_type=LayerType.Point)
485
- >>> features = 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 super().get_features(**kwargs)
495
-
496
-
497
- def get_feature(self, feature_id: int, out_srid: int = Feature.BASE_SRID) -> 'Feature':
498
- """
499
- 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
- Feature: 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 import GeoboxClient, VectorLayerView
513
- >>> client = GeoboxClient()
514
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
515
- >>> feature = view.get_feature(id=1)
516
- """
517
- return super().get_feature(feature_id, out_srid)
518
-
519
-
520
- def create_feature(self, geojson: Dict) -> 'Feature':
521
- """
522
- Create a new feature in the layer.
523
-
524
- Args:
525
- geojson (dict): The feature data including properties and geometry.
526
-
527
- Returns:
528
- Feature: The newly created feature instance.
529
-
530
- Raises:
531
- ValidationError: If the feature data is invalid.
532
-
533
- Example:
534
- >>> from geobox import GeoboxClient
535
- >>> from geobox.view import VectorLayerView
536
- >>> client = GeoboxClient()
537
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
538
- >>> feature = view.create_feature(geojson=geojson)
539
- """
540
- return super().create_feature(geojson)
541
-
542
-
543
- def delete_features(self, q: str = None, bbox: List[float] = None, bbox_srid: int = None, feature_ids: List[int] = None,
544
- run_async: bool = True, user_id: int = None) -> 'Task':
545
- """
546
- Delete features from the layer based on specified criteria.
547
-
548
- Args:
549
- q (Optional[str]): Query to filter features to delete.
550
- bbox (Optional[List[float]]): Bounding box to filter features.
551
- bbox_srid (Optional[int]): Spatial reference ID for the bounding box.
552
- feature_ids (Optional[List[int]]): List of specific feature IDs to delete.
553
- run_async (Optional[bool]): Whether to run the deletion asynchronously.
554
- user_id (Optional[int]): ID of the user performing the deletion.
555
-
556
- Returns:
557
- Task: The task instance of the deletion operation.
558
-
559
- Raises:
560
- ValidationError: If the deletion parameters are invalid.
561
-
562
- Example:
563
- >>> from geobox import GeoboxClient
564
- >>> from geobox.view import VectorLayerView
565
- >>> client = GeoboxClient()
566
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
567
- >>> view.delete_features(q="name like 'my_layer'",
568
- ... bbox=[10, 20, 30, 40],
569
- ... bbox_srid=3857,
570
- ... feature_ids=[1, 2, 3],
571
- ... run_async=True)
572
- """
573
- return super().delete_features(q, bbox, bbox_srid, feature_ids, run_async, user_id)
574
-
575
-
576
- def import_features(self, file_uuid: str, input_geom_type: 'InputGeomType', input_layer_name: str = None, input_dataset: str = None,
577
- user_id: int = None, input_srid: int = None, file_encoding: str = "utf-8",
578
- replace_domain_codes_by_values: bool = False, report_errors: bool = True) -> 'Task':
579
- """
580
- Import features from a file into the layer.
581
-
582
- Args:
583
- file_uuid (str): UUID of the uploaded file to import.
584
- input_geom_type (InputGeomType): Type of geometry in the input file.
585
- input_layer_name (str, optional): Name of the layer in the input file.
586
- input_dataset (str, optional): Name of the dataset in the input file.
587
- user_id (int, optional): Specific user.privileges requied.
588
- input_srid (int, optional): Spatial reference ID of the input data.
589
- file_encoding (str, optional): Character encoding of the input file.
590
- replace_domain_codes_by_values (bool, optional): Whether to replace domain codes with values.
591
- report_errors (bool, optional): Whether to report import errors.
592
-
593
- Returns:
594
- Task: The task instance of the import operation.
595
-
596
- Raises:
597
- ValidationError: If the import parameters are invalid.
598
-
599
- Example:
600
- >>> from geobox import GeoboxClient
601
- >>> from geobox.view import VectorLayerView
602
- >>> client = GeoboxClient()
603
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
604
- >>> task = view.import_features(file_uuid="12345678-1234-5678-1234-567812345678",
605
- ... input_geom_type=InputGeomType.POINT,
606
- ... input_layer="my_layer",
607
- ... input_dataset="my_dataset",
608
- ... input_srid=3857,
609
- ... file_encoding="utf-8",
610
- ... replace_domain_codes_by_values=False,
611
- ... report_errors=True)
612
- """
613
- return super().import_features(file_uuid, input_geom_type, input_layer_name, input_dataset, user_id,
614
- input_srid, file_encoding, replace_domain_codes_by_values, report_errors)
615
-
616
-
617
- def export_features(self, out_filename: str, out_format: 'FileOutputFormat', replace_domain_codes_by_values: bool = False,
618
- run_async: bool = True, bbox: List[float] = None, out_srid: int = None, zipped: bool = True,
619
- feature_ids: List[int] = None, bbox_srid: int = None, q: str = None, fields: List[str] = None) -> 'Task':
620
- """
621
- Export features from the layer to a file.
622
-
623
- Args:
624
- out_filename (str): Name of the output file.
625
- out_format (FileOutputFormat): Format of the output file (e.g., 'Shapefile', 'GPKG', 'GeoJSON', 'CSV', 'KML', 'DXF').
626
- replace_domain_codes_by_values (bool, optional): Whether to replace domain codes with values.
627
- run_async (bool, optional): Whether to run the export asynchronously.
628
- bbox (List[float], optional): Bounding box to filter features.
629
- out_srid (int, optional): Spatial reference ID for the output.
630
- zipped (bool, optional): Whether to compress the output file.
631
- feature_ids (List[int], optional): List of specific feature IDs to export.
632
- bbox_srid (int, optional): Spatial reference ID for the bounding box.
633
- q (str, optional): Query to filter features.
634
- fields (List[str], optional): List of fields to include in the export.
635
-
636
- Returns:
637
- Task: The task instance of the export operation.
638
-
639
- Raises:
640
- ValidationError: If the export parameters are invalid.
641
- ApiRequestError: If the API request fails.
642
-
643
- Example:
644
- >>> from geobox import GeoboxClient
645
- >>> from geobox.view import VectorLayerView
646
- >>> client = GeoboxClient()
647
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
648
- >>> task = view.export_features(out_filename="output.shp",
649
- ... out_format="shp",
650
- ... replace_domain_codes_by_values=False,
651
- ... run_async=True,
652
- ... bbox=[10, 20, 30, 40],
653
- ... out_srid=3857,
654
- ... zipped=True,
655
- ... feature_ids=[1, 2, 3])
656
- """
657
- return super().export_features(out_filename, out_format, replace_domain_codes_by_values, run_async,
658
- bbox, out_srid, zipped, feature_ids, bbox_srid, q, fields)
659
-
660
-
661
- def get_tile(self, x: int, y: int, z: int) -> Dict:
662
- """
663
- Get a vector tile for the layer.
664
-
665
- Args:
666
- x (int): X coordinate of the tile.
667
- y (int): Y coordinate of the tile.
668
- z (int): Zoom level of the tile.
669
-
670
- Returns:
671
- Dict: The vector tile data.
672
-
673
- Example:
674
- >>> from geobox import GeoboxClient
675
- >>> from geobox.view import VectorLayerView
676
- >>> client = GeoboxClient()
677
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
678
- >>> tile = view.get_tile(x=10, y=20, z=1)
679
- """
680
- return super().get_tile(x, y, z)
681
-
682
-
683
- def get_tile_json(self) -> Dict:
684
- """
685
- Get the vector tile JSON configuration for the layer.
686
-
687
- Returns:
688
- Dict: The vector tile JSON configuration.
689
-
690
- Example:
691
- >>> from geobox import GeoboxClient
692
- >>> from geobox.view import VectorLayerView
693
- >>> client = GeoboxClient()
694
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
695
- >>> tile_json = view.get_tile_json()
696
- """
697
- return super().get_tile_json()
698
-
699
-
700
- @property
701
- def settings(self) -> Dict:
702
- """
703
- Get the layer's settings.
704
-
705
- Returns:
706
- Dict: The layer settings.
707
-
708
- Example:
709
- >>> from geobox import GeoboxClient
710
- >>> from geobox.view import VectorLayerView
711
- >>> client = GeoboxClient()
712
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
713
- >>> setting = view.settings
714
- """
715
- return super().settings
716
-
717
-
718
- def set_settings(self, **kwargs) -> Dict:
719
- """
720
- Set the settings of the Vector Layer.
721
-
722
- Keyword Args:
723
- title_field (str): The field to use as the title.
724
- domain_display_type (str): The type of domain display.
725
- allow_export (bool): Whether to allow export.
726
- editable (bool): Whether to allow editing.
727
- edit_geometry (bool): Whether to allow editing the geometry.
728
- editable_attributes (str): The attributes to allow editing.
729
- allow_insert (bool): Whether to allow inserting.
730
- allow_delete (bool): Whether to allow deleting.
731
- min_zoom (int): The minimum zoom level.
732
- max_zoom (int): The maximum zoom level.
733
- max_features (int): The maximum number of features.
734
- filter_features (bool): Whether to filter features.
735
- fields (List[str]): The fields to include in the layer.
736
- use_cache (bool): Whether to use caching.
737
- cache_until_zoom (int): The zoom level to cache until.
738
-
739
- Returns:
740
- Dict: The updated settings.
741
-
742
- Raises:
743
- ValidationError: If the settings data is invalid.
744
-
745
- Example:
746
- >>> from geobox import GeoboxClient
747
- >>> from geobox.view import VectorLayerView
748
- >>> client = GeoboxClient()
749
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
750
- >>> view.set_setting(title_field="name",
751
- ... domain_display_type="Value",
752
- ... allow_export=True,
753
- ... editable=True,
754
- ... edit_geometry=True,
755
- ... editable_attributes="[ALL]",
756
- ... allow_insert=True,
757
- ... allow_delete=True,
758
- ... min_zoom=0,
759
- ... max_zoom=24,
760
- ... max_features=65536,
761
- ... filter_features=True,
762
- ... fields=["id"],
763
- ... use_cache=True,
764
- ... cache_until_zoom=17)
765
- """
766
- return super().set_settings(**kwargs)
767
-
768
-
769
- 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']:
770
- """
771
- Seed the cache for the view.
772
-
773
- Args:
774
- from_zoom (int, optional): The zoom level to start caching from.
775
- to_zoom (int, optional): The zoom level to stop caching at.
776
- ignore_cache (bool, optional): Whether to ignore the cache. default is False.
777
- workers (int, optional): The number of workers to use. default is 1.
778
- user_id (int, optional): specified user. privileges required.
779
-
780
- Returns:
781
- List[Task]: The task instance of the cache seeding operation.
782
-
783
- Example:
784
- >>> from geobox import GeoboxClient
785
- >>> from geobox.view import VectorLayerView
786
- >>> client = GeoboxClient()
787
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
788
- >>> task = view.cache_seed(from_zoom=0, to_zoom=10, ignore_cache=False, workers=1)
789
- """
790
- return super().seed_cache(from_zoom, to_zoom, ignore_cache, workers, user_id)
791
-
792
-
793
- def clear_cache(self) -> None:
794
- """
795
- Clear the view's cache.
796
-
797
- Returns:
798
- None
799
-
800
- Example:
801
- >>> from geobox import GeoboxClient
802
- >>> from geobox.view import VectorLayerView
803
- >>> client = GeoboxClient()
804
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
805
- >>> view.clear_cache()
806
- """
807
- return super().clear_cache()
808
-
809
-
810
- @property
811
- def cache_size(self) -> int:
812
- """
813
- Get the size of the view's cache.
814
-
815
- Returns:
816
- int: The size of the view's cache.
817
-
818
- Example:
819
- >>> from geobox import GeoboxClient
820
- >>> from geobox.view import VectorLayerView
821
- >>> client = GeoboxClient()
822
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
823
- >>> view.cache_size
824
- """
825
- return super().cache_size
826
-
827
-
828
- def update_stats(self) -> None:
829
- """
830
- Update the view's statistics.
831
-
832
- Returns:
833
- None
834
-
835
- Example:
836
- >>> from geobox import GeoboxClient
837
- >>> from geobox.view import VectorLayerView
838
- >>> client = GeoboxClient()
839
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
840
- >>> view.update_stats()
841
- """
842
- return super().update_stats()
843
-
844
-
845
- def prune_edited_areas(self) -> None:
846
- """
847
- 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.
848
-
849
- Returns:
850
- None
851
-
852
- Example:
853
- >>> from geobox import GeoboxClient
854
- >>> from geobox.view import VectorLayerView
855
- >>> client = GeoboxClient()
856
- >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
857
- >>> view.prune_edited_areas()
858
- """
859
- return super().prune_edited_areas()
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 GeoboxClient
8
+ from .field import Field
9
+ from .user import User
10
+ from .enums import InputGeomType, FieldType
11
+ from .task import Task
12
+
13
+
14
+ class VectorLayerView(VectorLayer):
15
+ """
16
+ A class representing a vector layer view in Geobox.
17
+
18
+ This class provides functionality to create, manage, and manipulate vector layer views.
19
+ It supports various operations including CRUD operations on views, as well as advanced operations like getting fields, features, and sharing views.
20
+ It also provides properties to access the view data, and a method to update the view.
21
+ """
22
+ BASE_ENDPOINT = 'vectorLayerViews/'
23
+
24
+ def __init__(self,
25
+ api: 'GeoboxClient',
26
+ uuid: str,
27
+ layer_type: 'LayerType',
28
+ data: Optional[Dict] = {}) -> None:
29
+ """
30
+ Initialize a VectorLayerView instance.
31
+
32
+ Args:
33
+ api (GeoboxClient): The GeoboxClient instance for making requests.
34
+ uuid (str): The UUID of the vector layer view.
35
+ layer_type (LayerType): The type of the vector layer view.
36
+ data (Dict, optional): The data of the vector layer view.
37
+ """
38
+ super().__init__(api, uuid, layer_type, data)
39
+
40
+
41
+ def __repr__(self) -> str:
42
+ """
43
+ Return a string representation of the VectorLayerView instance.
44
+
45
+ Returns:
46
+ str: A string representation of the VectorLayerView instance.
47
+ """
48
+ return f"VectorLayerView(name={self.name}, layer_type={self.layer_type})"
49
+
50
+
51
+ @property
52
+ def vector_layer(self) -> 'VectorLayer':
53
+ """
54
+ Get the vector layer.
55
+
56
+ Returns:
57
+ VectorLayer: The vector layer.
58
+
59
+ Example:
60
+ >>> from geobox import GeoboxClient
61
+ >>> from geobox.view import VectorLayerView
62
+ >>> client = GeoboxClient()
63
+ >>> view = VectorLayerView.get_view(client, uuid='e21e085a-8d30-407d-a740-ca9be9122c42')
64
+ >>> view.vector_layer
65
+ """
66
+ return VectorLayer(self.api, self.data['vector_layer']['uuid'], LayerType(self.data['vector_layer']['layer_type']), self.data['vector_layer'])
67
+
68
+
69
+ @classmethod
70
+ def get_views(cls, api: 'GeoboxClient', **kwargs) -> Union[List['VectorLayerView'], int]:
71
+ """
72
+ Get vector layer views.
73
+
74
+ Args:
75
+ api (GeoboxClient): The GeoboxClient instance for making requests.
76
+
77
+ Keyword Args:
78
+ layer_id(int): The id of the layer.
79
+ include_settings(bool): Whether to include the settings of the layer. default is False.
80
+ q(str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
81
+ 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.
82
+ search_fields(str): Comma separated list of fields for searching.
83
+ 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.
84
+ return_count(bool): Whether to return the count of the layer views. default is False.
85
+ skip(int): The number of layer views to skip. minimum is 0.
86
+ limit(int): The maximum number of layer views to return. minimum is 1. default is 10.
87
+ user_id(int): Specific user. privileges required.
88
+ shared(bool): Whether to return shared views. default is False.
89
+
90
+ Returns:
91
+ list[VectorLayerView] | int: A list of VectorLayerView instances or the layer views count if return_count is True.
92
+
93
+ Example:
94
+ >>> from geobox import GeoboxClient
95
+ >>> from geobox.view import VectorLayerView
96
+ >>> client = GeoboxClient()
97
+ >>> views = VectorLayerView.get_views(client,
98
+ layer_id=1,
99
+ include_settings=True,
100
+ search="test",
101
+ search_fields="name",
102
+ order_by="name A",
103
+ return_count=False,
104
+ skip=0,
105
+ limit=10,
106
+ shared=True)
107
+ or
108
+ >>> views = client.get_views(layer_id=1,
109
+ include_settings=True,
110
+ search="test",
111
+ search_fields="name",
112
+ order_by="name A",
113
+ return_count=False,
114
+ skip=0,
115
+ limit=10,
116
+ shared=True)
117
+ """
118
+ params = {
119
+ 'f': 'json',
120
+ 'include_settings': kwargs.get('include_settings', False),
121
+ 'temporary': kwargs.get('temporary', False),
122
+ 'q': kwargs.get('q', None),
123
+ 'search': kwargs.get('search', None),
124
+ 'search_fields': kwargs.get('search_fields', None),
125
+ 'order_by': kwargs.get('order_by', None),
126
+ 'return_count': kwargs.get('return_count', False),
127
+ 'skip': kwargs.get('skip', 0),
128
+ 'limit': kwargs.get('limit', 10),
129
+ 'user_id': kwargs.get('user_id', None),
130
+ 'shared': kwargs.get('shared', False)
131
+ }
132
+ return super()._get_list(api=api,
133
+ endpoint=cls.BASE_ENDPOINT,
134
+ params=params,
135
+ factory_func=lambda api, item: VectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
136
+
137
+
138
+ @classmethod
139
+ def get_views_by_ids(cls, api: 'GeoboxClient', ids: List[int], user_id: int = None, include_settings: bool = False) -> List['VectorLayerView']:
140
+ """
141
+ Get vector layer views by their IDs.
142
+
143
+ Args:
144
+ api (GeoboxClient): The GeoboxClient instance for making requests.
145
+ ids (List[int]): list of comma separated layer ids to be returned. e.g. 1, 2, 3
146
+ user_id (int, optional): specific user. privileges required.
147
+ include_settings (bool, optional): Whether to include the settings of the vector layer views. default is False.
148
+
149
+ Returns:
150
+ List[VectorLayerView]: A list of VectorLayerView instances.
151
+
152
+ Example:
153
+ >>> from geobox import GeoboxClient
154
+ >>> from geobox.view import VectorLayerView
155
+ >>> client = GeoboxClient()
156
+ >>> views = VectorLayerView.get_views_by_ids(client, ids=[1,2,3])
157
+ or
158
+ >>> views = client.get_views_by_ids(ids=[1,2,3])
159
+ """
160
+ params = {
161
+ 'ids': ids,
162
+ 'user_id': user_id,
163
+ 'include_settings': include_settings
164
+ }
165
+ return super()._get_list_by_ids(api=api,
166
+ endpoint=f'{cls.BASE_ENDPOINT}get-views/',
167
+ params=params,
168
+ factory_func=lambda api, item: VectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
169
+
170
+
171
+ @classmethod
172
+ def get_view(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'VectorLayerView':
173
+ """
174
+ Get a specific vector layer view by its UUID.
175
+
176
+ Args:
177
+ api (GeoboxClient): The GeoboxClient instance for making requests.
178
+ uuid (str): The UUID of the vector layer view.
179
+ user_id (int, optional): Specific user. privileges required.
180
+
181
+ Returns:
182
+ VectorLayerView: A VectorLayerView instance.
183
+
184
+ Example:
185
+ >>> from geobox import GeoboxClient
186
+ >>> from geobox.view import VectorLayerView
187
+ >>> client = GeoboxClient()
188
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
189
+ or
190
+ >>> view = client.get_view(uuid="12345678-1234-5678-1234-567812345678")
191
+ """
192
+ params = {
193
+ 'f': 'json',
194
+ 'user_id': user_id
195
+ }
196
+ return super()._get_detail(api=api,
197
+ endpoint=cls.BASE_ENDPOINT,
198
+ uuid=uuid,
199
+ params=params,
200
+ factory_func=lambda api, item: VectorLayerView(api, item['uuid'], LayerType(item['layer_type']), item))
201
+
202
+
203
+ @classmethod
204
+ def get_view_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['View', None]:
205
+ """
206
+ Get a view by name
207
+
208
+ Args:
209
+ api (GeoboxClient): The GeoboxClient instance for making requests.
210
+ name (str): the name of the view to get
211
+ user_id (int, optional): specific user. privileges required.
212
+
213
+ Returns:
214
+ View | None: returns the view if a view matches the given name, else None
215
+
216
+ Example:
217
+ >>> from geobox import GeoboxClient
218
+ >>> from geobox.view import VectorLayerView
219
+ >>> client = GeoboxClient()
220
+ >>> view = VectorLayerView.get_view_by_name(client, name='test')
221
+ or
222
+ >>> view = client.get_view_by_name(name='test')
223
+ """
224
+ views = cls.get_views(api, q=f"name = '{name}'", user_id=user_id)
225
+ if views and views[0].name == name:
226
+ return views[0]
227
+ else:
228
+ return None
229
+
230
+
231
+ def update(self, **kwargs) -> Dict:
232
+ """
233
+ Update the vector layer view.
234
+
235
+ Keyword Args:
236
+ name (str): The name of the vector layer view.
237
+ display_name (str): The display name of the vector layer view.
238
+ description (str): The description of the vector layer view.
239
+
240
+ Returns:
241
+ Dict: The updated vector layer view.
242
+
243
+ Raises:
244
+ ValidationError: If the update data is invalid.
245
+
246
+ Example:
247
+ >>> from geobox import GeoboxClient
248
+ >>> from geobox.view import VectorLayerView
249
+ >>> client = GeoboxClient()
250
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
251
+ >>> view.update_view(name="new_name")
252
+ >>> view.update_view(display_name="new_display_name")
253
+ >>> view.update_view(description="new_description")
254
+ """
255
+ return super().update(name=kwargs.get('name'), display_name=kwargs.get('display_name'), description=kwargs.get('description'))
256
+
257
+
258
+ def delete(self) -> None:
259
+ """
260
+ Delete the vector layer view.
261
+
262
+ Returns:
263
+ None
264
+
265
+ Example:
266
+ >>> from geobox import GeoboxClient
267
+ >>> from geobox.view import VectorLayerView
268
+ >>> client = GeoboxClient()
269
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
270
+ >>> view.delete()
271
+ """
272
+ return super().delete()
273
+
274
+
275
+ def share(self, users: List['User']) -> None:
276
+ """
277
+ Shares the view with specified users.
278
+
279
+ Args:
280
+ users (List[User]): The list of user IDs to share the view with.
281
+
282
+ Returns:
283
+ None
284
+
285
+ Example:
286
+ >>> from geobox import GeoboxClient
287
+ >>> from geobox.view import VectorLayerView
288
+ >>> client = GeoboxClient()
289
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
290
+ >>> users = client.search_users(search='John')
291
+ >>> view.share(users=users)
292
+ """
293
+ super()._share(self.endpoint, users)
294
+
295
+
296
+ def unshare(self, users: List['User']) -> None:
297
+ """
298
+ Unshares the view with specified users.
299
+
300
+ Args:
301
+ users (List[User]): The list of user IDs to unshare the view with.
302
+
303
+ Returns:
304
+ None
305
+
306
+ Example:
307
+ >>> from geobox import GeoboxClient
308
+ >>> from geobox.view import VectorLayerView
309
+ >>> client = GeoboxClient()
310
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
311
+ >>> users = client.search_users(search='John')
312
+ >>> view.unshare(users=users)
313
+ """
314
+ super()._unshare(self.endpoint, users)
315
+
316
+
317
+ def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
318
+ """
319
+ Retrieves the list of users the view is shared with.
320
+
321
+ Args:
322
+ search (str, optional): The search query.
323
+ skip (int, optional): The number of users to skip.
324
+ limit (int, optional): The maximum number of users to retrieve.
325
+
326
+ Returns:
327
+ List[User]: The list of shared users.
328
+
329
+ Example:
330
+ >>> from geobox import GeoboxClient
331
+ >>> from geobox.view import VectorLayerView
332
+ >>> client = GeoboxClient()
333
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
334
+ >>> view.get_shared_users(search='John', skip=0, limit=10)
335
+ """
336
+ params = {
337
+ 'search': search,
338
+ 'skip': skip,
339
+ 'limit': limit
340
+ }
341
+ return super()._get_shared_users(self.endpoint, params)
342
+
343
+
344
+ def get_fields(self) -> List['Field']:
345
+ """
346
+ Get all fields in the vector layer view.
347
+
348
+ Returns:
349
+ List[Field]: A list of Field instances representing the vector layer view's fields.
350
+
351
+ Raises:
352
+ ApiRequestError: If the API request fails.
353
+
354
+ Example:
355
+ >>> from geobox import GeoboxClient
356
+ >>> from geobox.view import VectorLayerView
357
+ >>> client = GeoboxClient()
358
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
359
+ >>> fields = view.get_fields()
360
+ """
361
+ return super().get_fields()
362
+
363
+
364
+ def get_field(self, field_id: str = None, name: str = None) -> 'Field':
365
+ """
366
+ Get a specific field by its ID or name.
367
+
368
+ Args:
369
+ field_id (str): The ID of the field to retrieve.
370
+ name (str): The name of the field to retrieve.
371
+
372
+ Returns:
373
+ Field: The requested field instance.
374
+
375
+ Raises:
376
+ NotFoundError: If the field with the specified ID is not found.
377
+ ApiRequestError: If the API request fails.
378
+
379
+ Example:
380
+ >>> from geobox import GeoboxClient
381
+ >>> from geobox.view import VectorLayerView
382
+ >>> client = GeoboxClient()
383
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
384
+ >>> field = view.get_field(id="1")
385
+ """
386
+ return super().get_field(field_id, name)
387
+
388
+
389
+ def add_field(self, name: str, data_type: 'FieldType', data: Dict = {}) -> 'Field':
390
+ """
391
+ Add a new field to the vector layer view.
392
+
393
+ Args:
394
+ name (str): The name of the new field.
395
+ data_type (FieldType): The data type of the new field.
396
+ data (Dict): Additional field properties (display_name, description, etc.).
397
+
398
+ Returns:
399
+ Field: The newly created field instance.
400
+
401
+ Raises:
402
+ ValidationError: If the field data is invalid.
403
+ ApiRequestError: If the API request fails.
404
+
405
+ Example:
406
+ >>> from geobox import GeoboxClient
407
+ >>> from geobox.view import VectorLayerView
408
+ >>> client = GeoboxClient()
409
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
410
+ >>> field = view.add_field(name="new_field", data_type=FieldType.String)
411
+ """
412
+ return super().add_field(name, data_type, data)
413
+
414
+
415
+ def calculate_field(self, target_field: str, expression: str, q: str = None, bbox: List[float] = None,
416
+ bbox_srid: int = None, feature_ids: List = None, run_async: bool = True,
417
+ user_id: int = None) -> 'Task':
418
+ """
419
+ 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
+ Task: The task instance of the calculation operation.
433
+
434
+ Raises:
435
+ ValidationError: If the calculation parameters are invalid.
436
+ ApiRequestError: If the API request fails.
437
+
438
+ Example:
439
+ >>> from geobox import GeoboxClient
440
+ >>> from geobox.view import VectorLayerView
441
+ >>> client = GeoboxClient()
442
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
443
+ >>> task = 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 super().calculate_field(target_field, expression, q, bbox, bbox_srid, feature_ids, run_async, user_id)
452
+
453
+
454
+ def get_features(self, **kwargs) -> Union[List['Feature'], int]:
455
+ """
456
+ 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[Feature] | int: A list of Feature instances or the features count if return_count is True.
478
+
479
+
480
+ Example:
481
+ >>> from geobox import GeoboxClient
482
+ >>> from geobox.view import VectorLayerView
483
+ >>> client = GeoboxClient()
484
+ >>> layer = VectorLayerView(api=client, name="my_layer", layer_type=LayerType.Point)
485
+ >>> features = 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 super().get_features(**kwargs)
495
+
496
+
497
+ def get_feature(self, feature_id: int, out_srid: int = Feature.BASE_SRID) -> 'Feature':
498
+ """
499
+ 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
+ Feature: 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 import GeoboxClient, VectorLayerView
513
+ >>> client = GeoboxClient()
514
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
515
+ >>> feature = view.get_feature(id=1)
516
+ """
517
+ return super().get_feature(feature_id, out_srid)
518
+
519
+
520
+ def create_feature(self, geojson: Dict) -> 'Feature':
521
+ """
522
+ Create a new feature in the layer.
523
+
524
+ Args:
525
+ geojson (dict): The feature data including properties and geometry.
526
+
527
+ Returns:
528
+ Feature: The newly created feature instance.
529
+
530
+ Raises:
531
+ ValidationError: If the feature data is invalid.
532
+
533
+ Example:
534
+ >>> from geobox import GeoboxClient
535
+ >>> from geobox.view import VectorLayerView
536
+ >>> client = GeoboxClient()
537
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
538
+ >>> feature = view.create_feature(geojson=geojson)
539
+ """
540
+ return super().create_feature(geojson)
541
+
542
+
543
+ def delete_features(self, q: str = None, bbox: List[float] = None, bbox_srid: int = None, feature_ids: List[int] = None,
544
+ run_async: bool = True, user_id: int = None) -> 'Task':
545
+ """
546
+ Delete features from the layer based on specified criteria.
547
+
548
+ Args:
549
+ q (Optional[str]): Query to filter features to delete.
550
+ bbox (Optional[List[float]]): Bounding box to filter features.
551
+ bbox_srid (Optional[int]): Spatial reference ID for the bounding box.
552
+ feature_ids (Optional[List[int]]): List of specific feature IDs to delete.
553
+ run_async (Optional[bool]): Whether to run the deletion asynchronously.
554
+ user_id (Optional[int]): ID of the user performing the deletion.
555
+
556
+ Returns:
557
+ Task: The task instance of the deletion operation.
558
+
559
+ Raises:
560
+ ValidationError: If the deletion parameters are invalid.
561
+
562
+ Example:
563
+ >>> from geobox import GeoboxClient
564
+ >>> from geobox.view import VectorLayerView
565
+ >>> client = GeoboxClient()
566
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
567
+ >>> view.delete_features(q="name like 'my_layer'",
568
+ ... bbox=[10, 20, 30, 40],
569
+ ... bbox_srid=3857,
570
+ ... feature_ids=[1, 2, 3],
571
+ ... run_async=True)
572
+ """
573
+ return super().delete_features(q, bbox, bbox_srid, feature_ids, run_async, user_id)
574
+
575
+
576
+ def import_features(self, file_uuid: str, input_geom_type: 'InputGeomType', input_layer_name: str = None, input_dataset: str = None,
577
+ user_id: int = None, input_srid: int = None, file_encoding: str = "utf-8",
578
+ replace_domain_codes_by_values: bool = False, report_errors: bool = True) -> 'Task':
579
+ """
580
+ Import features from a file into the layer.
581
+
582
+ Args:
583
+ file_uuid (str): UUID of the uploaded file to import.
584
+ input_geom_type (InputGeomType): Type of geometry in the input file.
585
+ input_layer_name (str, optional): Name of the layer in the input file.
586
+ input_dataset (str, optional): Name of the dataset in the input file.
587
+ user_id (int, optional): Specific user.privileges requied.
588
+ input_srid (int, optional): Spatial reference ID of the input data.
589
+ file_encoding (str, optional): Character encoding of the input file.
590
+ replace_domain_codes_by_values (bool, optional): Whether to replace domain codes with values.
591
+ report_errors (bool, optional): Whether to report import errors.
592
+
593
+ Returns:
594
+ Task: The task instance of the import operation.
595
+
596
+ Raises:
597
+ ValidationError: If the import parameters are invalid.
598
+
599
+ Example:
600
+ >>> from geobox import GeoboxClient
601
+ >>> from geobox.view import VectorLayerView
602
+ >>> client = GeoboxClient()
603
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
604
+ >>> task = view.import_features(file_uuid="12345678-1234-5678-1234-567812345678",
605
+ ... input_geom_type=InputGeomType.POINT,
606
+ ... input_layer="my_layer",
607
+ ... input_dataset="my_dataset",
608
+ ... input_srid=3857,
609
+ ... file_encoding="utf-8",
610
+ ... replace_domain_codes_by_values=False,
611
+ ... report_errors=True)
612
+ """
613
+ return super().import_features(file_uuid, input_geom_type, input_layer_name, input_dataset, user_id,
614
+ input_srid, file_encoding, replace_domain_codes_by_values, report_errors)
615
+
616
+
617
+ def export_features(self, out_filename: str, out_format: 'FileOutputFormat', replace_domain_codes_by_values: bool = False,
618
+ run_async: bool = True, bbox: List[float] = None, out_srid: int = None, zipped: bool = True,
619
+ feature_ids: List[int] = None, bbox_srid: int = None, q: str = None, fields: List[str] = None) -> 'Task':
620
+ """
621
+ Export features from the layer to a file.
622
+
623
+ Args:
624
+ out_filename (str): Name of the output file.
625
+ out_format (FileOutputFormat): Format of the output file (e.g., 'Shapefile', 'GPKG', 'GeoJSON', 'CSV', 'KML', 'DXF').
626
+ replace_domain_codes_by_values (bool, optional): Whether to replace domain codes with values.
627
+ run_async (bool, optional): Whether to run the export asynchronously.
628
+ bbox (List[float], optional): Bounding box to filter features.
629
+ out_srid (int, optional): Spatial reference ID for the output.
630
+ zipped (bool, optional): Whether to compress the output file.
631
+ feature_ids (List[int], optional): List of specific feature IDs to export.
632
+ bbox_srid (int, optional): Spatial reference ID for the bounding box.
633
+ q (str, optional): Query to filter features.
634
+ fields (List[str], optional): List of fields to include in the export.
635
+
636
+ Returns:
637
+ Task: The task instance of the export operation.
638
+
639
+ Raises:
640
+ ValidationError: If the export parameters are invalid.
641
+ ApiRequestError: If the API request fails.
642
+
643
+ Example:
644
+ >>> from geobox import GeoboxClient
645
+ >>> from geobox.view import VectorLayerView
646
+ >>> client = GeoboxClient()
647
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
648
+ >>> task = view.export_features(out_filename="output.shp",
649
+ ... out_format="shp",
650
+ ... replace_domain_codes_by_values=False,
651
+ ... run_async=True,
652
+ ... bbox=[10, 20, 30, 40],
653
+ ... out_srid=3857,
654
+ ... zipped=True,
655
+ ... feature_ids=[1, 2, 3])
656
+ """
657
+ return super().export_features(out_filename, out_format, replace_domain_codes_by_values, run_async,
658
+ bbox, out_srid, zipped, feature_ids, bbox_srid, q, fields)
659
+
660
+
661
+ def get_tile(self, x: int, y: int, z: int) -> Dict:
662
+ """
663
+ Get a vector tile for the layer.
664
+
665
+ Args:
666
+ x (int): X coordinate of the tile.
667
+ y (int): Y coordinate of the tile.
668
+ z (int): Zoom level of the tile.
669
+
670
+ Returns:
671
+ Dict: The vector tile data.
672
+
673
+ Example:
674
+ >>> from geobox import GeoboxClient
675
+ >>> from geobox.view import VectorLayerView
676
+ >>> client = GeoboxClient()
677
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
678
+ >>> tile = view.get_tile(x=10, y=20, z=1)
679
+ """
680
+ return super().get_tile(x, y, z)
681
+
682
+
683
+ def get_tile_json(self) -> Dict:
684
+ """
685
+ Get the vector tile JSON configuration for the layer.
686
+
687
+ Returns:
688
+ Dict: The vector tile JSON configuration.
689
+
690
+ Example:
691
+ >>> from geobox import GeoboxClient
692
+ >>> from geobox.view import VectorLayerView
693
+ >>> client = GeoboxClient()
694
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
695
+ >>> tile_json = view.get_tile_json()
696
+ """
697
+ return super().get_tile_json()
698
+
699
+
700
+ @property
701
+ def settings(self) -> Dict:
702
+ """
703
+ Get the layer's settings.
704
+
705
+ Returns:
706
+ Dict: The layer settings.
707
+
708
+ Example:
709
+ >>> from geobox import GeoboxClient
710
+ >>> from geobox.view import VectorLayerView
711
+ >>> client = GeoboxClient()
712
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
713
+ >>> setting = view.settings
714
+ """
715
+ return super().settings
716
+
717
+
718
+ def set_settings(self, **kwargs) -> Dict:
719
+ """
720
+ Set the settings of the Vector Layer.
721
+
722
+ Keyword Args:
723
+ title_field (str): The field to use as the title.
724
+ domain_display_type (str): The type of domain display.
725
+ allow_export (bool): Whether to allow export.
726
+ editable (bool): Whether to allow editing.
727
+ edit_geometry (bool): Whether to allow editing the geometry.
728
+ editable_attributes (str): The attributes to allow editing.
729
+ allow_insert (bool): Whether to allow inserting.
730
+ allow_delete (bool): Whether to allow deleting.
731
+ min_zoom (int): The minimum zoom level.
732
+ max_zoom (int): The maximum zoom level.
733
+ max_features (int): The maximum number of features.
734
+ filter_features (bool): Whether to filter features.
735
+ fields (List[str]): The fields to include in the layer.
736
+ use_cache (bool): Whether to use caching.
737
+ cache_until_zoom (int): The zoom level to cache until.
738
+
739
+ Returns:
740
+ Dict: The updated settings.
741
+
742
+ Raises:
743
+ ValidationError: If the settings data is invalid.
744
+
745
+ Example:
746
+ >>> from geobox import GeoboxClient
747
+ >>> from geobox.view import VectorLayerView
748
+ >>> client = GeoboxClient()
749
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
750
+ >>> view.set_setting(title_field="name",
751
+ ... domain_display_type="Value",
752
+ ... allow_export=True,
753
+ ... editable=True,
754
+ ... edit_geometry=True,
755
+ ... editable_attributes="[ALL]",
756
+ ... allow_insert=True,
757
+ ... allow_delete=True,
758
+ ... min_zoom=0,
759
+ ... max_zoom=24,
760
+ ... max_features=65536,
761
+ ... filter_features=True,
762
+ ... fields=["id"],
763
+ ... use_cache=True,
764
+ ... cache_until_zoom=17)
765
+ """
766
+ return super().set_settings(**kwargs)
767
+
768
+
769
+ 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']:
770
+ """
771
+ Seed the cache for the view.
772
+
773
+ Args:
774
+ from_zoom (int, optional): The zoom level to start caching from.
775
+ to_zoom (int, optional): The zoom level to stop caching at.
776
+ ignore_cache (bool, optional): Whether to ignore the cache. default is False.
777
+ workers (int, optional): The number of workers to use. default is 1.
778
+ user_id (int, optional): specified user. privileges required.
779
+
780
+ Returns:
781
+ List[Task]: The task instance of the cache seeding operation.
782
+
783
+ Example:
784
+ >>> from geobox import GeoboxClient
785
+ >>> from geobox.view import VectorLayerView
786
+ >>> client = GeoboxClient()
787
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
788
+ >>> task = view.cache_seed(from_zoom=0, to_zoom=10, ignore_cache=False, workers=1)
789
+ """
790
+ return super().seed_cache(from_zoom, to_zoom, ignore_cache, workers, user_id)
791
+
792
+
793
+ def clear_cache(self) -> None:
794
+ """
795
+ Clear the view's cache.
796
+
797
+ Returns:
798
+ None
799
+
800
+ Example:
801
+ >>> from geobox import GeoboxClient
802
+ >>> from geobox.view import VectorLayerView
803
+ >>> client = GeoboxClient()
804
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
805
+ >>> view.clear_cache()
806
+ """
807
+ return super().clear_cache()
808
+
809
+
810
+ @property
811
+ def cache_size(self) -> int:
812
+ """
813
+ Get the size of the view's cache.
814
+
815
+ Returns:
816
+ int: The size of the view's cache.
817
+
818
+ Example:
819
+ >>> from geobox import GeoboxClient
820
+ >>> from geobox.view import VectorLayerView
821
+ >>> client = GeoboxClient()
822
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
823
+ >>> view.cache_size
824
+ """
825
+ return super().cache_size
826
+
827
+
828
+ def update_stats(self) -> None:
829
+ """
830
+ Update the view's statistics.
831
+
832
+ Returns:
833
+ None
834
+
835
+ Example:
836
+ >>> from geobox import GeoboxClient
837
+ >>> from geobox.view import VectorLayerView
838
+ >>> client = GeoboxClient()
839
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
840
+ >>> view.update_stats()
841
+ """
842
+ return super().update_stats()
843
+
844
+
845
+ def prune_edited_areas(self) -> None:
846
+ """
847
+ 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.
848
+
849
+ Returns:
850
+ None
851
+
852
+ Example:
853
+ >>> from geobox import GeoboxClient
854
+ >>> from geobox.view import VectorLayerView
855
+ >>> client = GeoboxClient()
856
+ >>> view = VectorLayerView.get_view(client, uuid="12345678-1234-5678-1234-567812345678")
857
+ >>> view.prune_edited_areas()
858
+ """
859
+ return super().prune_edited_areas()