catatom2osm.geo.layer.polygon module

class catatom2osm.geo.layer.polygon.PolygonLayer(path, baseName, providerLib='ogr')[source]

Bases: catatom2osm.geo.layer.base.BaseLayer

Base class for polygon layers.

clean()[source]

Clean geometries.

Delete invalid geometries and close vertices, add topological points and simplify vertices.

delete_invalid_geometries(query_small_area=<function PolygonLayer.<lambda>>)[source]

Delete invalid geometries.

Test if any of it acute angle vertex could be deleted. Also removes zig-zag and spike vertex (see Point.get_spike_context).

delete_small_geometries()[source]
difference(layer)[source]

Calculate the difference of each geometry with those in layer.

explode_multi_parts(request=<qgis._core.QgsFeatureRequest object>)[source]

Split multipolygons.

Creates a new WKBPolygon feature for each part of any WKBMultiPolygon feature in request. This avoid relations with many ‘outer’ members in OSM data set. From this moment, localId will not be a unique identifier for buildings.

get_adjacents_and_geometries(expression='')[source]

Auxiliary indexes for adjacency of geometries.

Returns

(list) groups of adjacent polygons (dict) feature id: geometry

get_area()[source]

Return sum of all features area.

get_contacts_and_geometries(expression='')[source]

Auxiliary indexes for contact of geometries.

Returns

(list) groups of polygons with at least one common node (dict) feature id: geometry

get_parents_per_vertex_and_geometries(expression='')[source]

Auxiliary indexes for vertex of geometries.

Returns

(dict) parent fids for each vertex, (dict) geometry for each fid.

Precondition:

Called before reproject.

is_inside(feature)[source]

Return first feature of this layer that is_inside feature.

is_inside_area(feature)[source]

Return first feature of this layer that is_inside_area feature.

static is_shared_segment(parents_per_vx, va, vb, feature_id)[source]

Return True if a segment is used by another geometry.

Given a dictionary of parents per vertex check if segment va-vb in geometry of feature with id ‘feature_id’ is shared with another geometry.

merge_adjacent_polygons()[source]

Merge adjacent polygons in each feature geometry.

merge_adjacents()[source]

Merge polygons with shared segments.

merge_geometries(groups, geometries, sort=None, reverse=False, split=True)[source]

Merge groups of fids from geometries.

Parameters
  • groups (list) – groups of adjacent polygons

  • geometries (dict) – feature id: geometry

  • sort (lambda or None) – key to sort group

  • reverse (bool) – reverse sort if True

  • split (bool) – split multipart geometries if True

Returns

feature id: geometry changed geometries

Return type

(dict)

simplify()[source]

Reduce the number of vertices in a polygon layer.

  • Delete vertex if the angle with its adjacents is near of the straight angle for less than ‘straight_thr’ degrees in all its parents.

  • Delete vertex if the distance to the segment formed by its parents is less than ‘cath_thr’ meters.

topology(dup_thr=False)[source]

Add to nearest segments each vertex in a polygon layer.