LayersSet

class LayersSet

LayersSet is the basis class for all layers subclasses (read, update, and write).

Many methods in LayersSet apply to a specific layer number, which is defined by the parameter layer_number. The default layer number is always zero, i.e., the first layer is used whenever layer_number is unset.

LayersSet has an attribute dataset, which is an instance of OGRDataSource.

A data source consists of one more layers (OGRLayer). If a layer instance is retrieved from LayersSet and the LayersSet instance is destroyed, an error will occur. The same applies to the features of a layer. Do not destroy or lose the scope of LayersSet before the layer instance or its features was used.

See also

  • LayersReader
  • LayersEditor
  • LayersUpdate
  • LayersWriter

Construction

__init__() Initialize the abstract class by setting self.dataset = None

Description

get_source() Return the dataset source
get_description([layer_number]) Return the layer description for the given layer number
show([layer_number, width, max_rows]) Show the layer as pandas DataFrame

Construction, copy, and join

copy([target]) Return a copy of the layers
join(this_fieldname, other, other_fieldname) Return a LayerWriter with joined features
data_frame([layer_number]) Return a layer as pandas DataFrame

Layers

get_layer_count() Return the number of layers
get_layer_name([layer_number]) Return the layer name for the given layer number
get_layer([layer_number]) Return the OGRLayer instance for the given layer number
layers() Iterator over all layers :return:

Layers definitions

get_layer_definition([layer_number]) Return the OGRLayerDefn instance for the given layer number
layers_definitions() Iterator over layer definitions, one definition for each layer

Features

get_features_count([layer_number]) Return the number of features for the given layer number
create_feature(**kwargs) Create a feature and insert it into the layer

Fields

get_field_count([layer_number]) Return number of fields for the given layer number.
get_field_names([layer_number]) Return the field names for the given layer number
get_field_numbers([field_names, layer_number]) Return the field numbers for the given field names.
get_field_definition(field_name[, layer_number]) Return the FieldDefinition for this field name
get_field_definitions([field_names, …]) Returns a list of field definitions
get_field_values([field_names, layer_number]) Return field values
get_geometries_and_field_values([…]) Return geometries and field values for the given layer number
has_field_names(field_names[, layer_number]) Return a list of bool values with True for existing fields
generate_field_name(field_name[, layer_number]) Returns field_name if it does not exist, else append a digit from 0 to n to field_name and return it
rename_fields([target]) Rename fields in a new LayersWriter
fields([layer_number]) Returns a list of lists containing field name, type code, type name, width, and precision

Geometry

get_geometry_type([layer_number]) Return the geometry type for the given layer number
get_geometries_count([layer_number]) Return the number of geometries for each record
get_geometries_names([layer_number]) Return the geometries names for each record
get_geometries([layer_number, fmt]) Return the geometries
get_geometries_point_count([layer_number]) Return zeros if geometries are not points, else the number of points in each geometry
get_geometry_union_as_wkb([layer_number]) Return the geometry union
is_geometry_point([layer_number]) Check whether the layer has a point geometry
is_geometry_polygon([layer_number]) Check whether the layer has a polygon geometry

Coordinate system

get_coordinate_system([fmt, layer_number]) Return the coordinate system
get_extent([layer_number, scale]) Return the layer extension (bounding box)
transform([other]) Transform to another coordinate system :param other: another object returning srs as wkt from ‘get_coordinate-system()’ :param kwargs:

Spatial filters

set_attribute_filter(filter_string[, …]) Set an attribute filter
set_spatial_filter(lrs[, layer_number]) Set a spatial filter
spatial_filter(lrs[, layer_number, method]) Yield features according to a spatial filter
spatial_filter_to_layer(lrs[, layer_number, …]) Copy the result of the spatial filter to a layer

Geoprocessing

buffer(buffer_dist[, target, layer_number]) Return buffer
centroid([target, drivername]) Return a new LayersWriter with centroids
convex_hull([target]) Return the convex hull
get_convex_hull_as_wkb([layer_number]) Return the convex hull as well known binary format
dissolve(**kwargs) Dissolve to a new LayersWriter