A class that wraps an OGR Layer, needs to be instantiated from a DataSource object.
Attributes
| Attribute | Type | Description |
|---|
| spatial_filter | `OGRGeometry | tuple |
Constructor
Signature
def Layer(
layer_ptr: pointer,
ds: [DataSource](../datasource/datasource.md?sid=django_contrib_gis_gdal_datasource_datasource)
)
Parameters
| Name | Type | Description |
|---|
| layer_ptr | pointer | An 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
| Type | Description |
|---|
[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
| Type | Description |
|---|
string | The 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
| Name | Type | Description |
|---|
| force | int = 1 | A flag indicating whether to force the calculation of the feature count, which may be expensive for some drivers. |
Returns
| Type | Description |
|---|
int | The count of features in the layer. |
num_fields()
@classmethod
def num_fields() - > int
Return the number of fields in the Layer.
Returns
| Type | Description |
|---|
int | The 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
| Type | Description |
|---|
[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
| Type | Description |
|---|
| `SpatialReference | null` |
fields()
@classmethod
def fields() - > list[str]
Return a list of string names corresponding to each of the Fields available in this Layer.
Returns
| Type | Description |
|---|
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
| Type | Description |
|---|
list | A 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
| Type | Description |
|---|
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
| Type | Description |
|---|
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
| Name | Type | Description |
|---|
| field_name | string | The name of the attribute field to retrieve values for. |
Returns
| Type | Description |
|---|
list | A 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
| Name | Type | Description |
|---|
| geos | boolean = False | If True, returns Django GEOSGeometry objects; otherwise returns OGRGeometry objects. |
Returns
| Type | Description |
|---|
list | A 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
| Name | Type | Description |
|---|
| capability | string | The name of the OGR layer capability to check. |
Returns
| Type | Description |
|---|
boolean | True if the layer supports the specified capability, False otherwise. |