cartagen.square_polygon_orthogonal#
- square_polygon_orthogonal(polygon, orientation='mbtr', force_all=True, angle_tolerance=8.0, correct_tolerance=0.6, remove_flat=True)#
Squares a building by forcing it into an orthogonal coordinate system.
This algorithm described by Hakim and Tsai [1] is a heuristic approach that leverages the Manhattan World assumption. It identifies the orientation of the building and performs a global rotation to align the footprint with the X/Y grid. Facades are then classified and merged into strictly horizontal or vertical lines. Perfect 90-degree corners are reconstructed via direct line intersections before an inverse rotation is applied to restore the building to its original geospatial location.
- Parameters:
polygon (
Polygon) – The polygon to square.orientation (
str, optional) –The method to calculate the orientation of the polygon. This defines the dominant axis used for the global rotation.
’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.
’swo’ or statistical weighted orientation calculates the orientation using the statistical weighted orientation method.
force_all (
bool, optional) – If set to True (default), every segment is snapped to whichever cardinal direction (H or V) it is closest to, regardless of the deviation. Theangle_toleranceandcorrect_toleranceparameters are ignored in this mode. Set to False to apply tolerance-based squaring: only segments withinangle_toleranceof a cardinal direction are snapped, and vertices already withincorrect_toleranceof right or flat are left alone.angle_tolerance (
float, optional) – Only used whenforce_allis False. Tolerance in degrees within which a segment is snapped to the nearest cardinal direction. Segments whose deviation exceeds this value are left unchanged (‘U’).correct_tolerance (
float, optional) – Only used whenforce_allis False. Tolerance in degrees below which a vertex is considered already correct and skipped.remove_flat (
bool, optional) – If set to True, vertices whose interior angle is flat (close to 180°) after squaring are removed from the result.
- Returns:
See also
square_polygon_naiveSquares a polygon according to its orientation, vertex by vertex.
square_polygon_lsSquares a polygon using the method of least squares.
polygon_orientationCalculate the orientation of a polygon.
References
Examples
>>> polygon = Polygon([(0, 0), (0, 1), (1.1, 1), (1, 0)]) >>> square_polygon_orthogonal(polygon) <POLYGON ((0 1, 1.05 1, 1.05 0, 0 0, 0 1))>