safe.gis.qgis_vector_tools module

Utilities around QgsVectorLayer

safe.gis.qgis_vector_tools.clip_by_polygon(vector, polygon)[source]

Clip vector layer using polygon.

Return part of the objects that lie within the polygon.

Parameters:
  • vector (QgsVectorLayer) – Vector layer
  • polygon (QgsGeometry) – Clipping polygon
Returns:

Vector layer with split geometry

Return type:

QgsVectorLayer

safe.gis.qgis_vector_tools.create_layer(vector)[source]

Create empty layer.

The CRS and Geometry Type of new layer are the same as of vector layer. Attributes of the layer are copied from vector.

Parameters:vector (QgsVectorLayer) – Vector layer
Returns:Empty vector layer (stored in memory)
Return type:QgsVectorLayer
safe.gis.qgis_vector_tools.extent_to_geo_array(extent, source_crs, dest_crs=None)[source]

Convert the supplied extent to geographic and return as an array.

Parameters:
  • extent (QgsRectangle) – Rectangle defining a spatial extent in any CRS.
  • source_crs (QgsCoordinateReferenceSystem) – Coordinate system used for extent.
Returns:

a list in the form [xmin, ymin, xmax, ymax] where all coordinates provided are in Geographic / EPSG:4326.

Return type:

list

safe.gis.qgis_vector_tools.points_to_rectangles(points, dx, dy)[source]

Create polygon layer around points. The polygons are dx to dy. Attributes of the points are copied. A point position is upper-left corner of the created rectangle.

Parameters:
  • points (QgsVectorLayer) – Point layer.
  • dx (float) – Length of the horizontal sides
  • dy (float) – Length of the vertical sides
Returns:

Polygon layer

Return type:

QgsVectorLayer

safe.gis.qgis_vector_tools.reproject_vector_layer(layer, crs)[source]

Reproject a vector layer to given CRS

Parameters:
  • layer (QgsVectorLayer) – Vector layer
  • crs (QgsCoordinateReferenceSystem) – Coordinate system for reprojection.
Returns:

a vector layer with the specified projection

Return type:

QgsVectorLayer

safe.gis.qgis_vector_tools.split_by_polygon(vector, polygon, request=<qgis._core.QgsFeatureRequest object at 0x2af2d26f1938>, mark_value=None)[source]

Split objects from vector layer by polygon.

If request is specified, filter the objects before splitting.

If part of vector object lies in the polygon, mark it by mark_value ( optional).

Parameters:
  • vector (QgsVectorLayer) – Vector layer
  • polygon (QgsGeometry) – Splitting polygon
  • request (QgsFeatureRequest) – Filter for vector objects
  • mark_value ((field_name, field_value).or None) – Field value to mark the objects.
Returns:

Vector layer with split geometry

Return type:

QgsVectorLayer

safe.gis.qgis_vector_tools.union_geometry(vector, request=<qgis._core.QgsFeatureRequest object at 0x2af2d26f1c30>)[source]

Return union of the vector geometries regardless of the attributes. (If request is specified, filter the objects before union). If all geometries in the vector are invalid, return None.

The boundaries will be dissolved during the operation.

Parameters:
  • vector (QgsVectorLayer) – Vector layer
  • request (QgsFeatureRequest) – Filter for vector objects
Returns:

Union of the geometry

Return type:

QgsGeometry or None