Feature
This class that wraps an OGR Feature, needs to be instantiated from a Layer object.
Attributes
| Attribute | Type | Description |
|---|---|---|
| destructor | callable = capi.destroy_feature | The C API function used to clean up and release the OGR Feature resources. |
| encoding | string | The character encoding used by the parent data source for string conversion. |
| fid | integer | Return the feature identifier. |
| layer_name | string | Return the name of the layer for the feature. |
| num_fields | integer | Return the number of fields in the Feature. |
| fields | list | Return a list of fields in the Feature. |
| geom | [OGRGeometry](../geometries/ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | Return the OGR Geometry for this Feature. |
| geom_type | [OGRGeomType](../geomtype/ogrgeomtype.md?sid=django_contrib_gis_gdal_geomtype_ogrgeomtype) | Return the OGR Geometry Type for this Feature. |
Constructor
Signature
def Feature(
feat: pointer,
layer: [Layer](../layer/layer.md?sid=django_contrib_gis_gdal_layer_layer)
)
Parameters
| Name | Type | Description |
|---|---|---|
| feat | pointer | The OGR Feature pointer. |
| layer | [Layer](../layer/layer.md?sid=django_contrib_gis_gdal_layer_layer) | The Layer object associated with the feature. |
Methods
encoding()
@classmethod
def encoding() - > str
Retrieves the character encoding used by the parent data source.
Returns
| Type | Description |
|---|---|
str | The string encoding name (e.g., 'utf-8') |
fid()
@classmethod
def fid() - > int
Return the feature identifier.
Returns
| Type | Description |
|---|---|
int | The unique integer ID of the feature within its layer |
layer_name()
@classmethod
def layer_name() - > str
Return the name of the layer for the feature.
Returns
| Type | Description |
|---|---|
str | The name of the OGR Layer to which this feature belongs |
num_fields()
@classmethod
def num_fields() - > int
Return the number of fields in the Feature.
Returns
| Type | Description |
|---|---|
int | The count of attribute fields defined for this feature |
fields()
@classmethod
def fields() - > List[str]
Return a list of fields in the Feature.
Returns
| Type | Description |
|---|---|
List[str] | A list of all field names available in the feature |
geom()
@classmethod
def geom() - > [OGRGeometry](../geometries/ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry)
Return the OGR Geometry for this Feature.
Returns
| Type | Description |
|---|---|
[OGRGeometry](../geometries/ogrgeometry.md?sid=django_contrib_gis_gdal_geometries_ogrgeometry) | A clone of the geometry associated with this feature |
geom_type()
@classmethod
def geom_type() - > [OGRGeomType](../geomtype/ogrgeomtype.md?sid=django_contrib_gis_gdal_geomtype_ogrgeomtype)
Return the OGR Geometry Type for this Feature.
Returns
| Type | Description |
|---|---|
[OGRGeomType](../geomtype/ogrgeomtype.md?sid=django_contrib_gis_gdal_geomtype_ogrgeomtype) | An object representing the type of geometry (e.g., Point, LineString) |
get()
@classmethod
def get(
field: [Union](../../db/models/functions/union.md?sid=django_contrib_gis_db_models_functions_union)[str, [Field](../../../../forms/fields/field.md?sid=django_forms_fields_field)]
) - > Any
Return the value of the field, instead of an instance of the Field object. May take a string of the field name or a Field object as parameters.
Parameters
| Name | Type | Description |
|---|---|---|
| field | [Union](../../db/models/functions/union.md?sid=django_contrib_gis_db_models_functions_union)[str, [Field](../../../../forms/fields/field.md?sid=django_forms_fields_field)] | The name of the field or a Field instance whose value should be retrieved |
Returns
| Type | Description |
|---|---|
Any | The actual data value stored in the field (e.g., int, str, float) |
index()
@classmethod
def index(
field_name: str
) - > int
Return the index of the given field name.
Parameters
| Name | Type | Description |
|---|---|---|
| field_name | str | The string name of the field to locate |
Returns
| Type | Description |
|---|---|
int | The zero-based integer index of the field |