Skip to main content

Field

Wrap an OGR Field. Needs to be instantiated from a Feature object.

Attributes

AttributeTypeDescription
ptrpointerInternal pointer to the OGR Field definition used for interacting with the underlying GDAL C API.
is_setbooleanReturn True if the value of this field isn't null, False otherwise.
namestringReturn the name of this Field.
precisionintegerReturn the precision of this Field.
typeintegerReturn the OGR type of this Field.
type_namestringReturn the OGR field type name for this Field.
valueanyReturn the value of this Field.
widthintegerReturn the width of this Field.

Constructor

Signature

def Field(
feat: [Feature](../feature/feature.md?sid=django_contrib_gis_gdal_feature_feature),
index: int
)

Parameters

NameTypeDescription
feat[Feature](../feature/feature.md?sid=django_contrib_gis_gdal_feature_feature)The feature object containing the field.
indexintThe integer index of the field within the feature.

Signature

def Field(
feat: [Feature](../feature/feature.md?sid=django_contrib_gis_gdal_feature_feature),
index: int
)

Parameters

NameTypeDescription
feat[Feature](../feature/feature.md?sid=django_contrib_gis_gdal_feature_feature)The OGR Feature object that contains this field
indexintThe zero-based integer index of the field within the feature's definition

Methods


as_double()

@classmethod
def as_double() - > float

Retrieve the Field's value as a double (float).

Returns

TypeDescription
floatThe field value as a float, or None if the field is not set

as_int()

@classmethod
def as_int(
is_64: bool = False
) - > int

Retrieve the Field's value as an integer.

Parameters

NameTypeDescription
is_64bool = FalseDetermines whether to retrieve the value as a 64-bit integer

Returns

TypeDescription
intThe field value as an integer, or None if the field is not set

as_string()

@classmethod
def as_string() - > str

Retrieve the Field's value as a string.

Returns

TypeDescription
strThe field value converted to a string using the feature's encoding, or None if not set

as_datetime()

@classmethod
def as_datetime() - > tuple

Retrieve the Field's value as a tuple of date & time components.

Returns

TypeDescription
tupleA tuple containing (year, month, day, hour, minute, second, timezone)

is_set()

@classmethod
def is_set() - > bool

Return True if the value of this field isn't null, False otherwise.

Returns

TypeDescription
boolBoolean indicating if the field contains a non-null value

name()

@classmethod
def name() - > str

Return the name of this Field.

Returns

TypeDescription
strThe name of the field as defined in the OGR layer

precision()

@classmethod
def precision() - > int

Return the precision of this Field.

Returns

TypeDescription
intThe number of digits after the decimal point for the field

type()

@classmethod
def type() - > int

Return the OGR type of this Field.

Returns

TypeDescription
intThe integer constant representing the OGR Field Type (OFT)

type_name()

@classmethod
def type_name() - > str

Return the OGR field type name for this Field.

Returns

TypeDescription
strThe human-readable string name of the OGR field type

value()

@classmethod
def value() - > any

Return the value of this Field.

Returns

TypeDescription
anyThe underlying value of the field, typically returned as a string by default

width()

@classmethod
def width() - > int

Return the width of this Field.

Returns

TypeDescription
intThe maximum width of the field