cartagen.square_polygon_naive

cartagen.square_polygon_naive#

square_polygon_naive(polygon, orientation='primary', angle_tolerance=8.0, correct_tolerance=0.6, remove_flat=True)#

Squares a polygon according to its orientation, vertex by vertex.

This method, described in Touya, [1] first calculates the orientation of the polygon. Sides are then corrected depending on the angles formed at the vertexes and on their alignment regarding the calculated orientation.

Parameters:
  • polygon (Polygon) – The polygon to square.

  • orientation (str, optional) –

    The method to calculate the orientation. Be aware that the orientation of the polygon defines how the sides are corrected.

    • ’primary’ calculates the orientation of the longest side of the provided polygon.

    • ’mbr’ calculates the orientation of the long side of the minimum rotated bounding rectangle.

    • ’mbtr’ calculates the orientation of the long side of the minimum rotated bounding touching rectangle. It is the same as the mbr but the rectangle and the polygon must have at least one side in common.

    • ’swo’ or statistical weighted orientation described in Duchêne, [2] calculates the orientation of a polygon using the statistical weighted orientation. This method relies on the length and orientation of the longest and second longest segment between two vertexes of the polygon.

  • angle_tolerance (float, optional) – Tolerance in degrees to square the considered angle.

  • correct_tolerance (float, optional) – Tolerance in degrees to consider the angle to be already flat or right.

  • remove_flat (bool, optional) – If set to True, vertexes with an angle detected or corrected as flat are removed. Thus, the resulting polygon can have less vertexes than the provided one.

Returns:

Polygon

See also

square_polygon_orthogonal

Squares a building by forcing it into an orthogonal coordinate system.

square_polygon_ls

Squares a polygon using the method of least squares.

polygon_orientation

Calculate the orientation of a polygon.

Notes

By default, this algorithm is not very destructive, if you want to force edges onto an orthogonal coordinate system, you should use square_polygon_orthogonal.

References

Examples

>>> polygon = Polygon([(0, 0), (0, 1), (1.1, 1), (1, 0)])
>>> square_polygon_naive(polygon)
<POLYGON ((0 0, 0 1, 1.1 1, 1.1 -0.005, 0 0))>

(Source code)

../_images/square_polygon_naive.png