geobox 2.0.1__py3-none-any.whl → 2.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- geobox/__init__.py +61 -63
- geobox/aio/__init__.py +61 -63
- geobox/aio/api.py +489 -473
- geobox/aio/apikey.py +263 -263
- geobox/aio/attachment.py +341 -339
- geobox/aio/base.py +261 -262
- geobox/aio/basemap.py +196 -196
- geobox/aio/dashboard.py +340 -342
- geobox/aio/feature.py +23 -33
- geobox/aio/field.py +315 -321
- geobox/aio/file.py +72 -72
- geobox/aio/layout.py +340 -341
- geobox/aio/log.py +23 -23
- geobox/aio/map.py +1033 -1034
- geobox/aio/model3d.py +415 -415
- geobox/aio/mosaic.py +696 -696
- geobox/aio/plan.py +314 -314
- geobox/aio/query.py +693 -693
- geobox/aio/raster.py +907 -869
- geobox/aio/raster_analysis.py +740 -0
- geobox/aio/route.py +4 -4
- geobox/aio/scene.py +340 -342
- geobox/aio/settings.py +18 -18
- geobox/aio/task.py +404 -402
- geobox/aio/tile3d.py +337 -339
- geobox/aio/tileset.py +102 -103
- geobox/aio/usage.py +52 -51
- geobox/aio/user.py +506 -507
- geobox/aio/vector_tool.py +1968 -0
- geobox/aio/vectorlayer.py +315 -306
- geobox/aio/version.py +272 -273
- geobox/aio/view.py +1019 -983
- geobox/aio/workflow.py +340 -341
- geobox/api.py +18 -2
- geobox/apikey.py +262 -262
- geobox/attachment.py +336 -337
- geobox/base.py +384 -384
- geobox/basemap.py +194 -194
- geobox/dashboard.py +339 -341
- geobox/enums.py +432 -348
- geobox/feature.py +5 -5
- geobox/field.py +320 -320
- geobox/file.py +4 -4
- geobox/layout.py +339 -340
- geobox/log.py +4 -4
- geobox/map.py +1031 -1032
- geobox/model3d.py +410 -410
- geobox/mosaic.py +696 -696
- geobox/plan.py +313 -313
- geobox/query.py +691 -691
- geobox/raster.py +907 -863
- geobox/raster_analysis.py +737 -0
- geobox/scene.py +341 -342
- geobox/settings.py +194 -194
- geobox/task.py +399 -400
- geobox/tile3d.py +337 -338
- geobox/tileset.py +4 -4
- geobox/usage.py +3 -3
- geobox/user.py +503 -503
- geobox/vector_tool.py +1968 -0
- geobox/vectorlayer.py +5 -5
- geobox/version.py +272 -272
- geobox/view.py +981 -981
- geobox/workflow.py +338 -339
- {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/METADATA +15 -1
- geobox-2.2.0.dist-info/RECORD +72 -0
- geobox-2.0.1.dist-info/RECORD +0 -68
- {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/WHEEL +0 -0
- {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/licenses/LICENSE +0 -0
- {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/top_level.txt +0 -0
geobox/aio/field.py
CHANGED
|
@@ -1,321 +1,315 @@
|
|
|
1
|
-
from urllib.parse import urljoin
|
|
2
|
-
from typing import Optional, Dict, TYPE_CHECKING, Any
|
|
3
|
-
|
|
4
|
-
from .base import AsyncBase
|
|
5
|
-
from ..utils import clean_data
|
|
6
|
-
from ..enums import FieldType
|
|
7
|
-
|
|
8
|
-
if TYPE_CHECKING:
|
|
9
|
-
from .api import AsyncGeoboxClient
|
|
10
|
-
from .vectorlayer import VectorLayer
|
|
11
|
-
from ..api import GeoboxClient
|
|
12
|
-
from ..field import Field
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class
|
|
16
|
-
|
|
17
|
-
def __init__(self,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"""
|
|
23
|
-
Constructs all the necessary attributes for the Field object.
|
|
24
|
-
|
|
25
|
-
Args:
|
|
26
|
-
layer (VectorLayer): The vector layer that the field belongs to.
|
|
27
|
-
data_type (FieldType): type of the field
|
|
28
|
-
field_id (int): the id of the field
|
|
29
|
-
data (Dict, optional): The data of the field.
|
|
30
|
-
"""
|
|
31
|
-
super().__init__(api=layer.api, data=data)
|
|
32
|
-
self.layer = layer
|
|
33
|
-
self.field_id = field_id
|
|
34
|
-
if not isinstance(data_type, FieldType):
|
|
35
|
-
raise ValueError("data_type must be a FieldType instance")
|
|
36
|
-
self.data_type = data_type
|
|
37
|
-
self.endpoint = urljoin(layer.endpoint, f'fields/{self.id}/') if self.data.get('id') else None
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def __repr__(self) -> str:
|
|
41
|
-
"""
|
|
42
|
-
Return a string representation of the field.
|
|
43
|
-
|
|
44
|
-
Returns:
|
|
45
|
-
str: The string representation of the field.
|
|
46
|
-
"""
|
|
47
|
-
return f"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def __getattr__(self, name: str) -> Any:
|
|
51
|
-
"""
|
|
52
|
-
Get an attribute from the resource.
|
|
53
|
-
|
|
54
|
-
Args:
|
|
55
|
-
name (str): The name of the attribute
|
|
56
|
-
"""
|
|
57
|
-
if name == 'datatype':
|
|
58
|
-
return FieldType(self.data['datatype'])
|
|
59
|
-
return super().__getattr__(name)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
@property
|
|
63
|
-
def domain(self) -> Dict:
|
|
64
|
-
"""
|
|
65
|
-
Domain property
|
|
66
|
-
|
|
67
|
-
Returns:
|
|
68
|
-
Dict: domain data
|
|
69
|
-
"""
|
|
70
|
-
return self.data.get('domain')
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
@domain.setter
|
|
74
|
-
def domain(self, value: Dict) -> None:
|
|
75
|
-
"""
|
|
76
|
-
Domain property setter
|
|
77
|
-
|
|
78
|
-
Returns:
|
|
79
|
-
None
|
|
80
|
-
"""
|
|
81
|
-
self.data['domain'] = value
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
@classmethod
|
|
85
|
-
async def create_field(cls, api: 'AsyncGeoboxClient', layer: 'VectorLayer', name: str, data_type: 'FieldType', data: Dict = {}) -> '
|
|
86
|
-
"""
|
|
87
|
-
[async] Create a new field
|
|
88
|
-
|
|
89
|
-
Args:
|
|
90
|
-
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
91
|
-
layer (VectorLayer): field's layer
|
|
92
|
-
name (str): name of the field
|
|
93
|
-
data_type (FieldType): type of the field
|
|
94
|
-
data (Dict, optional): the data of the field
|
|
95
|
-
|
|
96
|
-
Returns:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Example:
|
|
100
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
101
|
-
>>> from geobox.aio.vectorlayer import VectorLayer
|
|
102
|
-
>>> from geobox.aio.field import
|
|
103
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
104
|
-
>>> layer = await client.get_layer(uuid="12345678-1234-5678-1234-567812345678")
|
|
105
|
-
>>> field = await
|
|
106
|
-
"""
|
|
107
|
-
data.update({
|
|
108
|
-
"name": name,
|
|
109
|
-
"datatype": data_type.value
|
|
110
|
-
})
|
|
111
|
-
endpoint = urljoin(layer.endpoint, 'fields/')
|
|
112
|
-
return await super()._create(api, endpoint, data, factory_func=lambda api, item:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
async def save(self) -> None:
|
|
116
|
-
"""
|
|
117
|
-
[async] Save the field. Creates a new field if field_id is None, updates existing field otherwise.
|
|
118
|
-
|
|
119
|
-
Returns:
|
|
120
|
-
None
|
|
121
|
-
|
|
122
|
-
Example:
|
|
123
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
124
|
-
>>> from geobox.aio.field import
|
|
125
|
-
>>> async with AsyncGeoboxClient() as client:
|
|
126
|
-
>>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
|
127
|
-
>>> field =
|
|
128
|
-
>>> await field.save()
|
|
129
|
-
"""
|
|
130
|
-
data = clean_data({
|
|
131
|
-
"name": self.name,
|
|
132
|
-
"datatype": FieldType(self.data_type).value,
|
|
133
|
-
"display_name": self.data.get("display_name"),
|
|
134
|
-
"description": self.data.get("description"),
|
|
135
|
-
"domain": self.data.get("domain"),
|
|
136
|
-
"width": self.data.get("width"),
|
|
137
|
-
"hyperlink": self.data.get("hyperlink")
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
try:
|
|
141
|
-
if self.id:
|
|
142
|
-
response = await self.layer.api.put(self.endpoint, data)
|
|
143
|
-
except AttributeError:
|
|
144
|
-
endpoint = urljoin(self.layer.endpoint, 'fields/')
|
|
145
|
-
response = await self.layer.api.post(endpoint, data)
|
|
146
|
-
self.id = response['id']
|
|
147
|
-
self.endpoint = urljoin(self.layer.endpoint, f'fields/{self.id}/')
|
|
148
|
-
|
|
149
|
-
self._update_properties(response)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
async def delete(self) -> None:
|
|
153
|
-
"""
|
|
154
|
-
[async] Delete the field.
|
|
155
|
-
|
|
156
|
-
Returns:
|
|
157
|
-
None
|
|
158
|
-
|
|
159
|
-
Example:
|
|
160
|
-
>>> from geobox.aio import AsyncGeoboxClient
|
|
161
|
-
>>>
|
|
162
|
-
>>>
|
|
163
|
-
>>>
|
|
164
|
-
>>>
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
>>>
|
|
188
|
-
>>>
|
|
189
|
-
>>>
|
|
190
|
-
>>>
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
"
|
|
196
|
-
"
|
|
197
|
-
"
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
>>>
|
|
213
|
-
>>>
|
|
214
|
-
>>>
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
>>>
|
|
232
|
-
>>>
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
>>>
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
>>>
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
>>>
|
|
310
|
-
>>>
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
>>> sync_field = field.to_sync(client)
|
|
317
|
-
"""
|
|
318
|
-
from ..field import Field as SyncField
|
|
319
|
-
|
|
320
|
-
sync_layer = self.layer.to_sync(sync_client=sync_client)
|
|
321
|
-
return SyncField(layer=sync_layer, data_type=self.data_type, field_id=self.field_id, data=self.data)
|
|
1
|
+
from urllib.parse import urljoin
|
|
2
|
+
from typing import Optional, Dict, TYPE_CHECKING, Any
|
|
3
|
+
|
|
4
|
+
from .base import AsyncBase
|
|
5
|
+
from ..utils import clean_data
|
|
6
|
+
from ..enums import FieldType
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from .api import AsyncGeoboxClient
|
|
10
|
+
from .vectorlayer import VectorLayer
|
|
11
|
+
from ..api import GeoboxClient
|
|
12
|
+
from ..field import Field
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AsyncField(AsyncBase):
|
|
16
|
+
|
|
17
|
+
def __init__(self,
|
|
18
|
+
layer: 'VectorLayer',
|
|
19
|
+
data_type: 'FieldType',
|
|
20
|
+
field_id: int = None,
|
|
21
|
+
data: Optional[Dict] = {}):
|
|
22
|
+
"""
|
|
23
|
+
Constructs all the necessary attributes for the Field object.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
layer (VectorLayer): The vector layer that the field belongs to.
|
|
27
|
+
data_type (FieldType): type of the field
|
|
28
|
+
field_id (int): the id of the field
|
|
29
|
+
data (Dict, optional): The data of the field.
|
|
30
|
+
"""
|
|
31
|
+
super().__init__(api=layer.api, data=data)
|
|
32
|
+
self.layer = layer
|
|
33
|
+
self.field_id = field_id
|
|
34
|
+
if not isinstance(data_type, FieldType):
|
|
35
|
+
raise ValueError("data_type must be a FieldType instance")
|
|
36
|
+
self.data_type = data_type
|
|
37
|
+
self.endpoint = urljoin(layer.endpoint, f'fields/{self.id}/') if self.data.get('id') else None
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def __repr__(self) -> str:
|
|
41
|
+
"""
|
|
42
|
+
Return a string representation of the field.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
str: The string representation of the field.
|
|
46
|
+
"""
|
|
47
|
+
return f"AsyncField(id={self.id}, name={self.name}, data_type={self.data_type})"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def __getattr__(self, name: str) -> Any:
|
|
51
|
+
"""
|
|
52
|
+
Get an attribute from the resource.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
name (str): The name of the attribute
|
|
56
|
+
"""
|
|
57
|
+
if name == 'datatype':
|
|
58
|
+
return FieldType(self.data['datatype'])
|
|
59
|
+
return super().__getattr__(name)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def domain(self) -> Dict:
|
|
64
|
+
"""
|
|
65
|
+
Domain property
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
Dict: domain data
|
|
69
|
+
"""
|
|
70
|
+
return self.data.get('domain')
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@domain.setter
|
|
74
|
+
def domain(self, value: Dict) -> None:
|
|
75
|
+
"""
|
|
76
|
+
Domain property setter
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
None
|
|
80
|
+
"""
|
|
81
|
+
self.data['domain'] = value
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
async def create_field(cls, api: 'AsyncGeoboxClient', layer: 'VectorLayer', name: str, data_type: 'FieldType', data: Dict = {}) -> 'AsyncField':
|
|
86
|
+
"""
|
|
87
|
+
[async] Create a new field
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
91
|
+
layer (VectorLayer): field's layer
|
|
92
|
+
name (str): name of the field
|
|
93
|
+
data_type (FieldType): type of the field
|
|
94
|
+
data (Dict, optional): the data of the field
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
AsyncField: the created field object
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
101
|
+
>>> from geobox.aio.vectorlayer import VectorLayer
|
|
102
|
+
>>> from geobox.aio.field import AsyncField
|
|
103
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
104
|
+
>>> layer = await client.get_layer(uuid="12345678-1234-5678-1234-567812345678")
|
|
105
|
+
>>> field = await AsyncField.create_field(client, layer=layer, name='test', data_type=FieldType.Integer)
|
|
106
|
+
"""
|
|
107
|
+
data.update({
|
|
108
|
+
"name": name,
|
|
109
|
+
"datatype": data_type.value
|
|
110
|
+
})
|
|
111
|
+
endpoint = urljoin(layer.endpoint, 'fields/')
|
|
112
|
+
return await super()._create(api, endpoint, data, factory_func=lambda api, item: AsyncField(layer, data_type, item['id'], item))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
async def save(self) -> None:
|
|
116
|
+
"""
|
|
117
|
+
[async] Save the field. Creates a new field if field_id is None, updates existing field otherwise.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
None
|
|
121
|
+
|
|
122
|
+
Example:
|
|
123
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
124
|
+
>>> from geobox.aio.field import AsyncField
|
|
125
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
126
|
+
>>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
|
127
|
+
>>> field = AsyncField(layer=layer, data_type=FieldType.String)
|
|
128
|
+
>>> await field.save()
|
|
129
|
+
"""
|
|
130
|
+
data = clean_data({
|
|
131
|
+
"name": self.name,
|
|
132
|
+
"datatype": FieldType(self.data_type).value,
|
|
133
|
+
"display_name": self.data.get("display_name"),
|
|
134
|
+
"description": self.data.get("description"),
|
|
135
|
+
"domain": self.data.get("domain"),
|
|
136
|
+
"width": self.data.get("width"),
|
|
137
|
+
"hyperlink": self.data.get("hyperlink")
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
try:
|
|
141
|
+
if self.id:
|
|
142
|
+
response = await self.layer.api.put(self.endpoint, data)
|
|
143
|
+
except AttributeError:
|
|
144
|
+
endpoint = urljoin(self.layer.endpoint, 'fields/')
|
|
145
|
+
response = await self.layer.api.post(endpoint, data)
|
|
146
|
+
self.id = response['id']
|
|
147
|
+
self.endpoint = urljoin(self.layer.endpoint, f'fields/{self.id}/')
|
|
148
|
+
|
|
149
|
+
self._update_properties(response)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
async def delete(self) -> None:
|
|
153
|
+
"""
|
|
154
|
+
[async] Delete the field.
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
None
|
|
158
|
+
|
|
159
|
+
Example:
|
|
160
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
161
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
162
|
+
>>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
|
163
|
+
>>> field = await layer.get_field(name='test')
|
|
164
|
+
>>> await field.delete()
|
|
165
|
+
"""
|
|
166
|
+
await super()._delete(self.endpoint)
|
|
167
|
+
self.field_id = None
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
async def update(self, **kwargs) -> Dict:
|
|
171
|
+
"""
|
|
172
|
+
[async] Update the field.
|
|
173
|
+
|
|
174
|
+
Keyword Args:
|
|
175
|
+
name (str): The name of the field.
|
|
176
|
+
display_name (str): The display name of the field.
|
|
177
|
+
description (str): The description of the field.
|
|
178
|
+
domain (Dict): the domain of the field
|
|
179
|
+
width (int): The width of the field.
|
|
180
|
+
hyperlink (bool): the hyperlink field.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
Dict: The updated data.
|
|
184
|
+
|
|
185
|
+
Example:
|
|
186
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
187
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
188
|
+
>>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
|
189
|
+
>>> field = await layer.get_field(name='test')
|
|
190
|
+
>>> field.update(name="my_field", display_name="My Field", description="My Field Description")
|
|
191
|
+
"""
|
|
192
|
+
data = {
|
|
193
|
+
"name": kwargs.get('name'),
|
|
194
|
+
"display_name": kwargs.get('display_name'),
|
|
195
|
+
"description": kwargs.get('description'),
|
|
196
|
+
"domain": kwargs.get('domain'),
|
|
197
|
+
"hyperlink": kwargs.get('hyperlink')
|
|
198
|
+
}
|
|
199
|
+
return await super()._update(self.endpoint, data)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
async def get_field_unique_values(self) -> Dict:
|
|
203
|
+
"""
|
|
204
|
+
[async] Get the unique values of the field.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
Dict: The response data.
|
|
208
|
+
|
|
209
|
+
Example:
|
|
210
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
211
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
212
|
+
>>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
|
213
|
+
>>> field = await layer.get_field(name='test')
|
|
214
|
+
>>> await field.get_field_unique_values()
|
|
215
|
+
"""
|
|
216
|
+
endpoint = urljoin(self.endpoint, 'distinct/')
|
|
217
|
+
return await self.layer.api.get(endpoint)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
async def get_field_unique_values_numbers(self) -> int:
|
|
221
|
+
"""
|
|
222
|
+
[async] Get the count of unique values of the field.
|
|
223
|
+
|
|
224
|
+
Returns:
|
|
225
|
+
int: The count of the field unique values.
|
|
226
|
+
|
|
227
|
+
Example:
|
|
228
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
229
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
230
|
+
>>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
|
231
|
+
>>> field = await layer.get_field(name='test')
|
|
232
|
+
>>> await field.get_field_unique_values_numbers()
|
|
233
|
+
"""
|
|
234
|
+
endpoint = urljoin(self.endpoint, 'distinctCount/')
|
|
235
|
+
return await self.layer.api.get(endpoint)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
async def get_field_statistic(self, func: str) -> Dict:
|
|
239
|
+
"""
|
|
240
|
+
[async] Get the statistic of the field.
|
|
241
|
+
|
|
242
|
+
Args:
|
|
243
|
+
func (str): The function to apply to the field. values are: min, max, avg
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
Dict: The response data.
|
|
247
|
+
|
|
248
|
+
Example:
|
|
249
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
250
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
251
|
+
>>> layer = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
|
252
|
+
>>> field = await layer.get_field(name='test')
|
|
253
|
+
>>> await field.get_field_statistic(func='avg')
|
|
254
|
+
"""
|
|
255
|
+
endpoint = urljoin(self.endpoint, f'stats/?func_type={func}')
|
|
256
|
+
return await self.layer.api.get(endpoint)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
async def update_domain(self, range_domain: Dict = None, list_domain: Dict = None) -> Dict:
|
|
260
|
+
"""
|
|
261
|
+
[async] Update field domian values
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
range_domain (Dict): a dictionary with min and max keys.
|
|
265
|
+
list_domain (Dict): a dictionary containing the domain codes and values.
|
|
266
|
+
|
|
267
|
+
Returns:
|
|
268
|
+
Dict: the updated field domain
|
|
269
|
+
|
|
270
|
+
Example:
|
|
271
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
272
|
+
>>> async with AsyncGeoboxClient() as client:
|
|
273
|
+
>>> field = await client.get_vector(uuid="12345678-1234-5678-1234-567812345678").get_fields()[0]
|
|
274
|
+
>>> range_d = {'min': 1, 'max': 10}
|
|
275
|
+
>>> list_d = {'1': 'value1', '2': 'value2'}
|
|
276
|
+
>>> await field.update_domain(range_domain = range_d, list_domain=list_d)
|
|
277
|
+
{'min': 1, 'max': 10, 'items: {'1': 'value1', '2': 'value2'}}
|
|
278
|
+
"""
|
|
279
|
+
if not self.domain:
|
|
280
|
+
self.domain = {'min': None, 'max': None, 'items': {}}
|
|
281
|
+
|
|
282
|
+
if range_domain:
|
|
283
|
+
self.domain['min'] = range_domain['min']
|
|
284
|
+
self.domain['max'] = range_domain['max']
|
|
285
|
+
|
|
286
|
+
if list_domain:
|
|
287
|
+
self.domain['items'] = {**self.domain['items'], **list_domain}
|
|
288
|
+
|
|
289
|
+
await self.save()
|
|
290
|
+
return self.domain
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def to_sync(self, sync_client: 'GeoboxClient') -> 'Field':
|
|
294
|
+
"""
|
|
295
|
+
Switch to sync version of the field instance to have access to the sync methods
|
|
296
|
+
|
|
297
|
+
Args:
|
|
298
|
+
sync_client (GeoboxClient): The sync version of the GeoboxClient instance for making requests.
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
Field: the sync instance of the field.
|
|
302
|
+
|
|
303
|
+
Example:
|
|
304
|
+
>>> from geobox import Geoboxclient
|
|
305
|
+
>>> from geobox.aio import AsyncGeoboxClient
|
|
306
|
+
>>> client = GeoboxClient()
|
|
307
|
+
>>> async with AsyncGeoboxClient() as async_client:
|
|
308
|
+
>>> layer = await async_client.get_vector(uuid="12345678-1234-5678-1234-567812345678")
|
|
309
|
+
>>> field = await layer.get_field(name='test')
|
|
310
|
+
>>> sync_field = field.to_sync(client)
|
|
311
|
+
"""
|
|
312
|
+
from ..field import Field
|
|
313
|
+
|
|
314
|
+
sync_layer = self.layer.to_sync(sync_client=sync_client)
|
|
315
|
+
return Field(layer=sync_layer, data_type=self.data_type, field_id=self.field_id, data=self.data)
|