cartagen.LeastSquaresMethod#

class LeastSquaresMethod(max_iteration=1000, norm_tolerance=0.05, intra_conflicts=True, crossing_node_threshold=7)#

Generalise cartographic features using the method of least squares.

This method was proposed by [1] and uses the method of least squares to move the vertexes of every features (points, lines and polygons) keeping the provided constraints as satisfied as possible.

Parameters:
  • max_iteration (int, optional) – This is the maximum number of iteration before breaking the loop. If constraints and weights are correctly set, the norm tolerance threshold should be reached before the maximum number of iteration.

  • norm_tolerance (float, optional) – The threshold below which the norm of the resulting matrix is acceptable enough to break the iteration loop.

  • intra_conflicts (bool, optional) – If set to True, the features of the same GeoDataFrame can be spatially conflicting.

  • crossing_node_threshold (int, optional) – When two vertexes from different line intersects, define the number of vertexes connected on both sides from the intersection on wich spatial conflicts between those two lines doesn’t apply. Setting this value to 0 will not preserve line intersections.

References

Notes

A more in-depth overview of this method of generalisation is available inside the user manual of the documentation.

add(*objects, **weights)#

Add features before generalisation. This method adds one or multiple objects to the generalisation along with their associated weights. If multiple objects are provided, they must have the same geometry type.

Parameters:
  • object (GeoDataFrame) – One or multiple GeoDataFrame of geographic objects, can be Point, LineString or Polygon (if MultiGeometry are provided, they will be exploded). If multiple objects are provided, they must be the same geometry type because the same constraints will be applied.

  • weights (int, optional) –

    Specify a constraint with its weight. Possible weights:

    • movement : Specify the weight of the movement constraint.

    • stiffness : Specify the weight of the stiffness constraint.

    • curvature : Specify the weight of the curvature constraint.

    Constraint

    Geometry type

    Impact

    movement

    Point, LineString, Polygon

    The object should move as little as possible

    stiffness

    LineString, Polygon

    The internal geometry should be invariant, i.e. the vertexes movement within the same object will try not to move closer or away from each other.

    curvature

    LineString, Polygon

    The curvature of a line or a polygon border should not change, i.e. the angle formed by two connected segments will try not to change.

add_spatial_conflicts(distances, spatial_weights)#

Defines spatial conflict between pairs of geographic objects.

Once geographic objects has been added, this method is used to set up spatial conflicts between each of them.

Parameters:
  • distances (ndarray) –

    A numpy ndarray of dimension (n, n) where n is the number of objects added to the constraint method in the same order they has been added. For example, if 3 objects are provided, a numpy ndarray of a (3, 3) shape must be provided, such as:

    [[25. 28. 30.]
     [28. 15. 20.]
     [30. 20. 18.]]
    

  • spatial_weights (ndarray) – Same as the distances matrix but the values represent the weight of the spatial conflict of the two objects.

generalize(*network_partitioning)#

Launch the constraint generalisation on the objects.

Parameters:

network_partitioning (GeoDataFrame of LineString) – One or multiple line that represents the network used to partition the data.

Returns:

generalized (list of GeoDataFrame) – A list containing the generalized objects. This list contains the same number of provided objects in order.

Returns all the vertex to links conflicts as a LineString between the vertex and the projection of this vertex on the conflicting segment.

Returns:

GeoDataFrame of LineString

get_objects_number()#

Returns the number of objects added to the generalisation algorithm.

Returns:

int

get_vertexes()#

Returns the full list of vertexes.

Returns:

GeoDataFrame of Point

get_vertexes_conflicts()#

Returns all the vertex to vertex conflicts as a LineString between the two nodes.

Returns:

GeoDataFrame of LineString