cartagen.square_polygon_ls

cartagen.square_polygon_ls#

square_polygon_ls(polygon, max_iteration=1000, norm_tolerance=0.05, right_tolerance=10.0, flat_tolerance=10.0, fixed_weight=5, right_weight=100, flat_weight=50)#

Squares a polygon using the method of least squares.

The least squares based polygon squaring algorithm was proposed by Touya and Lokhat [1] and is particularly useful to square buildings.

In practice, this function iteratively tries to resolve matrices equations until a threshold norm is reached and the provided constraint are satisfied.

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

  • max_iteration (float, 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 point matrix is acceptable enough to break the iteration loop.

  • right_tolerance (float, optional) – Tolerance in degrees to consider an angle to be right.

  • flat_tolerance (float, optional) – Tolerance in degrees to consider an angle to be flat.

  • fixed_weight (int, optional) – The weight of the angle constraint concerning an angle neither right nor flat. A high value means those angles will be more likely to keep their value in the resulting polygon.

  • right_weight (int, optional) – The weight of the angle constraint concerning right angles. A high value means those angles will be more likely to keep their value in the resulting polygon.

  • flat_weight (int, optional) – The weight of the angle constraint concerning flat angles. A high value means those angles will be more likely to keep their value in the resulting polygon.

Returns:

Polygon

See also

square_polygon_orthogonal

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

square_polygon_naive

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

Notes

The method of least squares is a parameter estimation method in regression analysis based on minimizing the sum of the squares of the residuals (a residual being the difference between an observed value and the fitted value provided by a model) made in the results of each individual equation.

References

Examples

>>> polygon = Polygon([(0, 0), (0, 1), (1.1, 1), (1, 0)])
>>> square_polygon_ls(polygon)
<POLYGON ((-0.008 0.015, 0.012 1.011, 1.061 0.989, 1.035 -0.015, -0.008 0.015))>

(Source code)

../_images/square_polygon_ls.png