Skip to main content

Layer

A class that wraps an OGR Layer, needs to be instantiated from a DataSource object.

Attributes

AttributeTypeDescription
spatial_filter`OGRGeometrytuple

Constructor

Signature

def Layer(
layer_ptr: pointer,
ds: [DataSource](../datasource/datasource.md?sid=django_contrib_gis_gdal_datasource_datasource)
)

Parameters

NameTypeDescription
layer_ptrpointerAn OGR C pointer to the Layer.
ds[DataSource](../datasource/datasource.md?sid=django_contrib_gis_gdal_datasource_datasource)The DataSource object that owns this layer.

Methods


extent()

@classmethod
def extent() - > [Envelope](../envelope/envelope.md?sid=django_contrib_gis_gdal_envelope_envelope)

Return the extent (an Envelope) of this layer.

Returns

TypeDescription
[Envelope](../envelope/envelope.md?sid=django_contrib_gis_gdal_envelope_envelope)An Envelope object representing the bounding box of all features in the layer.

name()

@classmethod
def name() - > string

Return the name of this layer in the Data Source.

Returns

TypeDescription
stringThe layer name, decoded using the data source's encoding.

num_feat()

@classmethod
def num_feat(
force: int = 1
) - > int

Return the number of features in the Layer.

Parameters

NameTypeDescription
forceint = 1A flag indicating whether to force the calculation of the feature count, which may be expensive for some drivers.

Returns

TypeDescription
intThe count of features in the layer.

num_fields()

@classmethod
def num_fields() - > int

Return the number of fields in the Layer.

Returns

TypeDescription
intThe number of attribute fields defined in the layer's schema.

geom_type()

@classmethod
def geom_type() - > [OGRGeomType](../geomtype/ogrgeomtype.md?sid=django_contrib_gis_gdal_geomtype_ogrgeomtype)

Return the geometry type (OGRGeomType) of the Layer.

Returns

TypeDescription
[OGRGeomType](../geomtype/ogrgeomtype.md?sid=django_contrib_gis_gdal_geomtype_ogrgeomtype)An object representing the type of geometry (e.g., Point, LineString) stored in the layer.

srs()

@classmethod
def srs() - > SpatialReference | null

Return the Spatial Reference used in this Layer.

Returns

TypeDescription
`SpatialReferencenull`

fields()

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

Return a list of string names corresponding to each of the Fields available in this Layer.

Returns

TypeDescription
list[str]A list of all attribute field names available in the layer.

field_types()

@classmethod
def field_types() - > list

Return a list of the types of fields in this Layer. For example, return the list [OFTInteger, OFTReal, OFTString] for an OGR layer that has an integer, a floating-point, and string fields.

Returns

TypeDescription
listA list of OGR field type constants for each field in the layer.

field_widths()

@classmethod
def field_widths() - > list[int]

Return a list of the maximum field widths for the features.

Returns

TypeDescription
list[int]A list of integers representing the maximum width for each field.

field_precisions()

@classmethod
def field_precisions() - > list[int]

Return the field precisions for the features.

Returns

TypeDescription
list[int]A list of integers representing the decimal precision for each field.

get_fields()

@classmethod
def get_fields(
field_name: string
) - > list

Return a list containing the given field name for every Feature in the Layer.

Parameters

NameTypeDescription
field_namestringThe name of the attribute field to retrieve values for.

Returns

TypeDescription
listA list of values for the specified field extracted from every feature in the layer.

get_geoms()

@classmethod
def get_geoms(
geos: boolean = False
) - > list

Return a list containing the OGRGeometry for every Feature in the Layer.

Parameters

NameTypeDescription
geosboolean = FalseIf True, returns Django GEOSGeometry objects; otherwise returns OGRGeometry objects.

Returns

TypeDescription
listA list of geometries for every feature, either as OGRGeometry or GEOSGeometry objects.

test_capability()

@classmethod
def test_capability(
capability: string
) - > boolean

Return a bool indicating whether the this Layer supports the given capability (a string). Valid capability strings include: 'RandomRead', 'SequentialWrite', 'RandomWrite', 'FastSpatialFilter', 'FastFeatureCount', 'FastGetExtent', 'CreateField', 'Transactions', 'DeleteFeature', and 'FastSetNextByIndex'.

Parameters

NameTypeDescription
capabilitystringThe name of the OGR layer capability to check.

Returns

TypeDescription
booleanTrue if the layer supports the specified capability, False otherwise.