Skip to content
Permalink
Browse files

Fix spelling of orthoganilize

  • Loading branch information
nyalldawson committed Dec 12, 2016
1 parent 5228cc5 commit caa0d500af273216b58fc271f6be230eda094194
@@ -421,14 +421,14 @@ class QgsGeometry
QgsGeometry orientedMinimumBoundingBox( double& area /Out/, double &angle /Out/, double& width /Out/, double& height /Out/ ) const;

/**
* Attempts to orthagonalize a line or polygon geometry by shifting vertices to make the geometries
* Attempts to orthogonalize a line or polygon geometry by shifting vertices to make the geometries
* angles either right angles or flat lines. This is an iterative algorithm which will loop until
* either the vertices are within a specified tolerance of right angles or a set number of maximum
* iterations is reached. The angle threshold parameter specifies how close to a right angle or
* straight line an angle must be before it is attempted to be straightened.
* @note added in QGIS 3.0
*/
QgsGeometry orthagonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;

/** Test for intersection with a rectangle (uses GEOS) */
bool intersects( const QgsRectangle& r ) const;
@@ -320,12 +320,12 @@ qgis:orientedminimumboundingbox: >

As an alternative, the output layer can contain not just a single rectangle, but one for each input feature, representing the minimum rectangle that covers each of them.

qgis:orthagonalize: >
This algorithm takes a line or polygon layer and attempts to orthagonalize all the geometries in the layer. This process shifts the nodes in the geometries to try to make every angle in the geometry either a right angle or a straight line.
qgis:orthogonalize: >
This algorithm takes a line or polygon layer and attempts to orthogonalize all the geometries in the layer. This process shifts the nodes in the geometries to try to make every angle in the geometry either a right angle or a straight line.

The angle tolerance parameter is used to specify the maximum deviation from a right angle or straight line a node can have for it to be adjusted. Smaller tolerances mean that only nodes which are already closer to right angles will be adjusted, and larger tolerances mean that nodes which deviate further from right angles will also be adjusted.

The algorithm is iterative. Setting a larger number for the maximum iterations will result in a more orthagonal geometry at the cost of extra processing time.
The algorithm is iterative. Setting a larger number for the maximum iterations will result in a more orthogonal geometry at the cost of extra processing time.

qgis:pointsalonglines: >
Creates points at regular intervals along line or polygon geometries. Created points will have new attributes added for the distance along the geometry and the angle of the line at the point.
@@ -2,7 +2,7 @@

"""
***************************************************************************
Orthagonalize.py
Orthogonalize.py
----------------
Date : December 2016
Copyright : (C) 2016 by Nyall Dawson
@@ -33,7 +33,7 @@
from processing.tools import dataobjects, vector


class Orthagonalize(GeoAlgorithm):
class Orthogonalize(GeoAlgorithm):

INPUT_LAYER = 'INPUT_LAYER'
OUTPUT_LAYER = 'OUTPUT_LAYER'
@@ -42,7 +42,7 @@ class Orthagonalize(GeoAlgorithm):
ANGLE_TOLERANCE = 'ANGLE_TOLERANCE'

def defineCharacteristics(self):
self.name, self.i18n_name = self.trAlgorithm('Orthagonalize')
self.name, self.i18n_name = self.trAlgorithm('Orthogonalize')
self.group, self.i18n_group = self.trAlgorithm('Vector geometry tools')
self.tags = self.tr('rectangle,perpendicular,right,angles,square,quadrilateralise')

@@ -59,7 +59,7 @@ def defineCharacteristics(self):
max_iterations.isAdvanced = True
self.addParameter(max_iterations)

self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Orthagonalized')))
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Orthogonalized')))

def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(
@@ -79,10 +79,10 @@ def processAlgorithm(self, progress):
output_feature = input_feature
input_geometry = input_feature.geometry()
if input_geometry:
output_geometry = input_geometry.orthagonalize(1.0e-8, max_iterations, angle_tolerance)
output_geometry = input_geometry.orthogonalize(1.0e-8, max_iterations, angle_tolerance)
if not output_geometry:
raise GeoAlgorithmExecutionException(
self.tr('Error orthagonalizing geometry'))
self.tr('Error orthogonalizing geometry'))

output_feature.setGeometry(output_geometry)

@@ -183,7 +183,7 @@
from .DropGeometry import DropGeometry
from .BasicStatistics import BasicStatisticsForField
from .Heatmap import Heatmap
from .Orthagonalize import Orthagonalize
from .Orthogonalize import Orthogonalize

pluginPath = os.path.normpath(os.path.join(
os.path.split(os.path.dirname(__file__))[0], os.pardir))
@@ -249,7 +249,7 @@ def __init__(self):
ExtractSpecificNodes(), GeometryByExpression(), SnapGeometriesToLayer(),
PoleOfInaccessibility(), CreateAttributeIndex(), DropGeometry(),
BasicStatisticsForField(), RasterCalculator(), Heatmap(),
Orthagonalize()
Orthogonalize()
]

if hasMatplotlib:
@@ -1879,8 +1879,8 @@ tests:
geometry:
precision: 7

- algorithm: qgis:orthagonalize
name: Orthagonalize polys
- algorithm: qgis:orthogonalize
name: Orthogonalize polys
params:
INPUT_LAYER:
name: custom/polys_to_orth.gml
@@ -1894,8 +1894,8 @@ tests:
precision: 7


- algorithm: qgis:orthagonalize
name: Orthagonalize lines
- algorithm: qgis:orthogonalize
name: Orthogonalize lines
params:
INPUT_LAYER:
name: custom/lines_to_orth.gml
@@ -1906,4 +1906,5 @@ tests:
type: vector
compare:
geometry:
precision: 7
precision: 7

@@ -919,11 +919,11 @@ QgsGeometry QgsGeometry::orientedMinimumBoundingBox( double& area, double &angle
return minBounds;
}

QgsGeometry QgsGeometry::orthagonalize( double tolerance, int maxIterations, double angleThreshold ) const
QgsGeometry QgsGeometry::orthogonalize( double tolerance, int maxIterations, double angleThreshold ) const
{
QgsInternalGeometryEngine engine( *this );

return engine.orthagonalize( tolerance, maxIterations, angleThreshold );
return engine.orthogonalize( tolerance, maxIterations, angleThreshold );
}

bool QgsGeometry::intersects( const QgsRectangle& r ) const
@@ -474,14 +474,14 @@ class CORE_EXPORT QgsGeometry
QgsGeometry orientedMinimumBoundingBox( double& area, double &angle, double& width, double& height ) const;

/**
* Attempts to orthagonalize a line or polygon geometry by shifting vertices to make the geometries
* Attempts to orthogonalize a line or polygon geometry by shifting vertices to make the geometries
* angles either right angles or flat lines. This is an iterative algorithm which will loop until
* either the vertices are within a specified tolerance of right angles or a set number of maximum
* iterations is reached. The angle threshold parameter specifies how close to a right angle or
* straight line an angle must be before it is attempted to be straightened.
* @note added in QGIS 3.0
*/
QgsGeometry orthagonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;

//! Test for intersection with a rectangle (uses GEOS)
bool intersects( const QgsRectangle& r ) const;
@@ -244,7 +244,7 @@ QgsGeometry QgsInternalGeometryEngine::poleOfInaccessibility( double precision ,
}


// helpers for orthagonalize
// helpers for orthogonalize
// adapted from original code in potlach/id osm editor

bool dotProductWithinAngleTolerance( double dotProduct, double lowerThreshold, double upperThreshold )
@@ -340,7 +340,7 @@ QgsVector calcMotion( const QgsPointV2& a, const QgsPointV2& b, const QgsPointV2
return new_v.normalized() * ( 0.1 * dotProduct * scale );
}

QgsLineString* doOrthagonalize( QgsLineString* ring, int iterations, double tolerance, double lowerThreshold, double upperThreshold )
QgsLineString* doOrthogonalize( QgsLineString* ring, int iterations, double tolerance, double lowerThreshold, double upperThreshold )
{
double minScore = DBL_MAX;

@@ -410,7 +410,7 @@ QgsLineString* doOrthagonalize( QgsLineString* ring, int iterations, double tole
}


QgsAbstractGeometry* orthagonalizeGeom( const QgsAbstractGeometry* geom, int maxIterations, double tolerance, double lowerThreshold, double upperThreshold )
QgsAbstractGeometry* orthogonalizeGeom( const QgsAbstractGeometry* geom, int maxIterations, double tolerance, double lowerThreshold, double upperThreshold )
{
QScopedPointer< QgsAbstractGeometry > segmentizedCopy;
if ( QgsWkbTypes::isCurvedType( geom->wkbType() ) )
@@ -421,7 +421,7 @@ QgsAbstractGeometry* orthagonalizeGeom( const QgsAbstractGeometry* geom, int max

if ( QgsWkbTypes::geometryType( geom->wkbType() ) == QgsWkbTypes::LineGeometry )
{
return doOrthagonalize( static_cast< QgsLineString* >( geom->clone() ),
return doOrthogonalize( static_cast< QgsLineString* >( geom->clone() ),
maxIterations, tolerance, lowerThreshold, upperThreshold );
}
else
@@ -430,19 +430,19 @@ QgsAbstractGeometry* orthagonalizeGeom( const QgsAbstractGeometry* geom, int max
const QgsPolygonV2* polygon = static_cast< const QgsPolygonV2* >( geom );
QgsPolygonV2* result = new QgsPolygonV2();

result->setExteriorRing( doOrthagonalize( static_cast< QgsLineString* >( polygon->exteriorRing()->clone() ),
result->setExteriorRing( doOrthogonalize( static_cast< QgsLineString* >( polygon->exteriorRing()->clone() ),
maxIterations, tolerance, lowerThreshold, upperThreshold ) );
for ( int i = 0; i < polygon->numInteriorRings(); ++i )
{
result->addInteriorRing( doOrthagonalize( static_cast< QgsLineString* >( polygon->interiorRing( i )->clone() ),
result->addInteriorRing( doOrthogonalize( static_cast< QgsLineString* >( polygon->interiorRing( i )->clone() ),
maxIterations, tolerance, lowerThreshold, upperThreshold ) );
}

return result;
}
}

QgsGeometry QgsInternalGeometryEngine::orthagonalize( double tolerance, int maxIterations, double angleThreshold ) const
QgsGeometry QgsInternalGeometryEngine::orthogonalize( double tolerance, int maxIterations, double angleThreshold ) const
{
if ( !mGeometry || ( QgsWkbTypes::geometryType( mGeometry->wkbType() ) != QgsWkbTypes::LineGeometry
&& QgsWkbTypes::geometryType( mGeometry->wkbType() ) != QgsWkbTypes::PolygonGeometry ) )
@@ -460,7 +460,7 @@ QgsGeometry QgsInternalGeometryEngine::orthagonalize( double tolerance, int maxI
geometryList.reserve( numGeom );
for ( int i = 0; i < numGeom; ++i )
{
geometryList << orthagonalizeGeom( gc->geometryN( i ), maxIterations, tolerance, lowerThreshold, upperThreshold );
geometryList << orthogonalizeGeom( gc->geometryN( i ), maxIterations, tolerance, lowerThreshold, upperThreshold );
}

QgsGeometry first = QgsGeometry( geometryList.takeAt( 0 ) );
@@ -472,6 +472,6 @@ QgsGeometry QgsInternalGeometryEngine::orthagonalize( double tolerance, int maxI
}
else
{
return QgsGeometry( orthagonalizeGeom( mGeometry, maxIterations, tolerance, lowerThreshold, upperThreshold ) );
return QgsGeometry( orthogonalizeGeom( mGeometry, maxIterations, tolerance, lowerThreshold, upperThreshold ) );
}
}
@@ -62,14 +62,14 @@ class QgsInternalGeometryEngine
QgsGeometry poleOfInaccessibility( double precision, double* distanceFromBoundary = nullptr ) const;

/**
* Attempts to orthagonalize a line or polygon geometry by shifting vertices to make the geometries
* Attempts to orthogonalize a line or polygon geometry by shifting vertices to make the geometries
* angles either right angles or flat lines. This is an iterative algorithm which will loop until
* either the vertices are within a specified tolerance of right angles or a set number of maximum
* iterations is reached. The angle threshold parameter specifies how close to a right angle or
* straight line an angle must be before it is attempted to be straightened.
* @note added in QGIS 3.0
*/
QgsGeometry orthagonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;

private:
const QgsAbstractGeometry* mGeometry;
@@ -3668,49 +3668,49 @@ def testMinimumOrientedBoundingBox(self):
self.assertAlmostEqual(width, 4.4884, places=3)
self.assertAlmostEqual(height, 6.4420, places=3)

def testOrthagonalize(self):
def testOrthogonalize(self):
empty = QgsGeometry()
o = empty.orthagonalize()
o = empty.orthogonalize()
self.assertFalse(o)

# not a useful geometry
point = QgsGeometry.fromWkt('Point(1 2)')
o = point.orthagonalize()
o = point.orthogonalize()
self.assertFalse(o)

# polygon
polygon = QgsGeometry.fromWkt('Polygon((-0.699 0.892, -0.703 0.405, -0.022 0.361, 0.014 0.851, -0.699 0.892))')
o = polygon.orthagonalize()
o = polygon.orthogonalize()
exp = 'Polygon ((-0.69899999999999995 0.89200000000000002, -0.72568713635737736 0.38414056283699533, -0.00900222326098143 0.34648000752227009, 0.01768491457044956 0.85433944198378253, -0.69899999999999995 0.89200000000000002))'
result = o.exportToWkt()
self.assertTrue(compareWkt(result, exp, 0.00001),
"orthagonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))
"orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))

# polygon with ring
polygon = QgsGeometry.fromWkt('Polygon ((-0.698 0.892, -0.702 0.405, -0.022 0.360, 0.014 0.850, -0.698 0.892),(-0.619 0.777, -0.619 0.574, -0.515 0.567, -0.517 0.516, -0.411 0.499, -0.379 0.767, -0.619 0.777),(-0.322 0.506, -0.185 0.735, -0.046 0.428, -0.322 0.506))')
o = polygon.orthagonalize()
o = polygon.orthogonalize()
exp = 'Polygon ((-0.69799999999999995 0.89200000000000002, -0.72515703079591087 0.38373993222914216, -0.00901577368860811 0.34547552423418099, 0.01814125858957143 0.85373558928902782, -0.69799999999999995 0.89200000000000002),(-0.61899999999999999 0.77700000000000002, -0.63403125159063511 0.56020458713735533, -0.53071476068518508 0.55304126003523246, -0.5343108192220235 0.5011754225601015, -0.40493624158682306 0.49220537936424585, -0.3863089084840608 0.76086661681561074, -0.61899999999999999 0.77700000000000002),(-0.32200000000000001 0.50600000000000001, -0.185 0.73499999999999999, -0.046 0.42799999999999999, -0.32200000000000001 0.50600000000000001))'
result = o.exportToWkt()
self.assertTrue(compareWkt(result, exp, 0.00001),
"orthagonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))
"orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))

# multipolygon

polygon = QgsGeometry.fromWkt('MultiPolygon(((-0.550 -1.553, -0.182 -0.954, -0.182 -0.954, 0.186 -1.538, -0.550 -1.553)),'
'((0.506 -1.376, 0.433 -1.081, 0.765 -0.900, 0.923 -1.132, 0.923 -1.391, 0.506 -1.376)))')
o = polygon.orthagonalize()
o = polygon.orthogonalize()
exp = 'MultiPolygon (((-0.55000000000000004 -1.55299999999999994, -0.182 -0.95399999999999996, -0.182 -0.95399999999999996, 0.186 -1.53800000000000003, -0.55000000000000004 -1.55299999999999994)),((0.50600000000000001 -1.37599999999999989, 0.34888970623957499 -1.04704644438350125, 0.78332709454235683 -0.83955640656085295, 0.92300000000000004 -1.1319999999999999, 0.91737248858460974 -1.38514497083566535, 0.50600000000000001 -1.37599999999999989)))'
result = o.exportToWkt()
self.assertTrue(compareWkt(result, exp, 0.00001),
"orthagonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))
"orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))

#line
line = QgsGeometry.fromWkt('LineString (-1.07445631048298162 -0.91619958829825165, 0.04022568180912156 -0.95572731852137571, 0.04741254184968957 -0.61794489661467789, 0.68704308546024517 -0.66106605685808595)')
o = line.orthagonalize()
o = line.orthogonalize()
exp = 'LineString (-1.07445631048298162 -0.91619958829825165, 0.04812855116470245 -0.96433184892270418, 0.06228000950284909 -0.63427853851139493, 0.68704308546024517 -0.66106605685808595)'
result = o.exportToWkt()
self.assertTrue(compareWkt(result, exp, 0.00001),
"orthagonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))
"orthogonalize: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))


if __name__ == '__main__':

0 comments on commit caa0d50

Please sign in to comment.
You can’t perform that action at this time.