Field
The Field module provides functionality for working with fields of a vector layer.
- class Field(layer, data_type, field_id=None, data={})[source]
Bases:
Base- Parameters:
layer (VectorLayer)
data_type (FieldType)
field_id (int)
data (Dict | None)
- __init__(layer, data_type, field_id=None, data={})[source]
Constructs all the necessary attributes for the Field object.
- Parameters:
layer (VectorLayer) – The vector layer that the field belongs to.
data_type (FieldType) – type of the field
field_id (int) – the id of the field
data (Dict, optional) – The data of the field.
- __repr__()[source]
Return a string representation of the field.
- Returns:
The string representation of the field.
- Return type:
str
- __getattr__(name)[source]
Get an attribute from the resource.
- Parameters:
name (str) – The name of the attribute
- Return type:
Any
- property domain: Dict
Domain property
- Returns:
domain data
- Return type:
Dict
- classmethod create_field(api, layer, name, data_type, data={})[source]
Create a new field
- Parameters:
api (GeoboxClient) – The GeoboxClient instance for making requests.
layer (VectorLayer) – field’s layer
name (str) – name of the field
data_type (FieldType) – type of the field
data (Dict, optional) – the data of the field
- Returns:
the created field object
- Return type:
Example
>>> from geobox import GeoboxClient >>> from geobox.vectorlayer import VectorLayer >>> from geobox.field import Field >>> client = GeoboxClient() >>> layer = client.get_layer(uuid="12345678-1234-5678-1234-567812345678") >>> field = Field.create_field(client, layer=layer, name='test', data_type=FieldType.Integer)
- save()[source]
Save the field. Creates a new field if field_id is None, updates existing field otherwise.
- Returns:
None
- Return type:
None
Example
>>> from geobox import GeoboxClient >>> from geobox.field import Field >>> client = GeoboxClient() >>> layer = client.get_vector(uuid="12345678-1234-5678-1234-567812345678") >>> field = Field(layer=layer, data_type=FieldType.String) >>> field.save()
- delete()[source]
Delete the field.
- Returns:
None
- Return type:
None
Example
>>> from geobox import GeoboxClient >>> from geobox.field import Field >>> client = GeoboxClient() >>> layer = client.get_vector(uuid="12345678-1234-5678-1234-567812345678") >>> field = layer.get_field(name='test') >>> field.delete()
- update(**kwargs)[source]
Update the field.
- Keyword Arguments:
name (str) – The name of the field.
display_name (str) – The display name of the field.
description (str) – The description of the field.
domain (Dict) – the domain of the field
width (int) – The width of the field.
hyperlink (bool) – the hyperlink field.
- Returns:
The updated data.
- Return type:
Dict
Example
>>> from geobox import GeoboxClient >>> from geobox.field import Field >>> client = GeoboxClient() >>> layer = client.get_vector(uuid="12345678-1234-5678-1234-567812345678") >>> field = layer.get_field(name='test') >>> field.update(name="my_field", display_name="My Field", description="My Field Description")
- get_field_unique_values()[source]
Get the unique values of the field.
- Returns:
The response data.
- Return type:
Dict
Example
>>> from geobox import GeoboxClient >>> from geobox.field import Field >>> client = GeoboxClient() >>> layer = client.get_vector(uuid="12345678-1234-5678-1234-567812345678") >>> field = layer.get_field(name='test') >>> field.get_field_unique_values()
- get_field_unique_values_numbers()[source]
Get the count of unique values of the field.
- Returns:
The count of the field unique values.
- Return type:
int
Example
>>> from geobox import GeoboxClient >>> from geobox.field import Field >>> client = GeoboxClient() >>> layer = client.get_vector(uuid="12345678-1234-5678-1234-567812345678") >>> field = layer.get_field(name='test') >>> field.get_field_unique_values_numbers()
- get_field_statistic(func)[source]
Get the statistic of the field.
- Parameters:
func (str) – The function to apply to the field. values are: min, max, avg
- Returns:
The response data.
- Return type:
Dict
Example
>>> from geobox import GeoboxClient >>> from geobox.field import Field >>> client = GeoboxClient() >>> layer = client.get_vector(uuid="12345678-1234-5678-1234-567812345678") >>> field = layer.get_field(name='test') >>> field.get_field_statistic(func='avg')
- update_domain(range_domain=None, list_domain=None)[source]
Update field domian values
- Parameters:
range_domain (Dict) – a dictionary with min and max keys.
list_domain (Dict) – a dictionary containing the domain codes and values.
- Returns:
the updated field domain
- Return type:
Dict
Example
>>> from geobox import GeoboxClient >>> client = GeoboxClient() >>> field = client.get_vector(uuid="12345678-1234-5678-1234-567812345678").get_fields()[0] >>> range_d = {'min': 1, 'max': 10} >>> field.update_domain(range_domain = range_d) or >>> list_d = {'1': 'value1', '2': 'value2'} >>> field.update_domain(list_domain=list_d)
- add_index()[source]
Add an index to a field for better query performance
- Returns:
updated field data
- Return type:
Dict
Example
>>> from geobox import GeoboxClient >>> client = GeoboxClient() >>> field = client.get_vector(uuid="12345678-1234-5678-1234-567812345678").get_fields()[0] >>> field.add_index()