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