Skip to main content

Feature

This class that wraps an OGR Feature, needs to be instantiated from a Layer object.

Attributes

AttributeTypeDescription
destructorcallable = capi.destroy_featureThe C API function used to clean up and release the OGR Feature resources.
encodingstringThe character encoding used by the parent data source for string conversion.
fidintegerReturn the feature identifier.
layer_namestringReturn the name of the layer for the feature.
num_fieldsintegerReturn the number of fields in the Feature.
fieldslistReturn 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

NameTypeDescription
featpointerThe 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

TypeDescription
strThe string encoding name (e.g., 'utf-8')

fid()

@classmethod
def fid() - > int

Return the feature identifier.

Returns

TypeDescription
intThe 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

TypeDescription
strThe 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

TypeDescription
intThe count of attribute fields defined for this feature

fields()

@classmethod
def fields() - > List[str]

Return a list of fields in the Feature.

Returns

TypeDescription
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

TypeDescription
[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

TypeDescription
[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

NameTypeDescription
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

TypeDescription
AnyThe 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

NameTypeDescription
field_namestrThe string name of the field to locate

Returns

TypeDescription
intThe zero-based integer index of the field