QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsinternalgeometryengine.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsinternalgeometryengine.h - QgsInternalGeometryEngine
3 
4  ---------------------
5  begin : 13.1.2016
6  copyright : (C) 2016 by Matthias Kuhn
7  email : [email protected]
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSINTERNALGEOMETRYENGINE_H
17 #define QGSINTERNALGEOMETRYENGINE_H
18 
19 #define SIP_NO_FILE
20 
21 #include <functional>
22 
23 #include "qgspointxy.h"
24 
25 class QgsGeometry;
27 class QgsLineString;
28 class QgsLineSegment2D;
29 class QgsFeedback;
30 
42 {
43  public:
44 
50  explicit QgsInternalGeometryEngine( const QgsGeometry &geometry );
51 
57  QString lastError() const;
58 
72  bool isAxisParallelRectangle( double maximumDeviation, bool simpleRectanglesOnly = false ) const;
73 
82  QgsGeometry extrude( double x, double y ) const;
83 
93  QgsGeometry poleOfInaccessibility( double precision, double *distanceFromBoundary = nullptr ) const;
94 
103  QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
104 
113  QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
114 
128  QgsGeometry densifyByDistance( double distance ) const;
129 
144  QgsGeometry variableWidthBuffer( int segments, const std::function< std::unique_ptr< double[] >( const QgsLineString *line ) > &widthFunction ) const;
145 
160  QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
161 
172  QgsGeometry variableWidthBufferByM( int segments ) const;
173 
194  static QVector< QgsPointXY > randomPointsInPolygon( const QgsGeometry &polygon, int count,
195  const std::function< bool( const QgsPointXY & ) > &acceptPoint, unsigned long seed = 0, QgsFeedback *feedback = nullptr, int maxTriesPerPoint = 0 );
196 
212  QgsGeometry convertToCurves( double distanceTolerance, double angleTolerance ) const;
213 
225  QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;
226 
239  QgsGeometry triangularWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
240 
259  QgsGeometry triangularWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
260 
273  QgsGeometry squareWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
274 
293  QgsGeometry squareWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
294 
295 
308  QgsGeometry roundWaves( double wavelength, double amplitude, bool strictWavelength = false ) const;
309 
328  QgsGeometry roundWavesRandomized( double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed = 0 ) const;
329 
343  QgsGeometry applyDashPattern( const QVector< double > &pattern,
347  double patternOffset = 0 ) const;
348 
349  private:
350  const QgsAbstractGeometry *mGeometry = nullptr;
351 
352  mutable QString mLastError;
353 };
354 
361 class CORE_EXPORT QgsRay2D
362 {
363  public:
364 
369  QgsRay2D( const QgsPointXY &origin, QgsVector direction )
370  : origin( origin )
371  , direction( direction )
372  {}
373 
381  bool intersects( const QgsLineSegment2D &segment, QgsPointXY &intersectPoint ) const;
382 
383  private:
384 
385  QgsPointXY origin;
386  QgsVector direction;
387 };
388 
390 
391 // adapted for QGIS geometry classes from original work at https://github.com/trylock/visibility by trylock
392 
402 class CORE_EXPORT QgsLineSegmentDistanceComparer
403 {
404  public:
405 
410  explicit QgsLineSegmentDistanceComparer( const QgsPointXY &origin )
411  : mOrigin( origin )
412  {}
413 
421  bool operator()( QgsLineSegment2D ab, QgsLineSegment2D cd ) const;
422 
423  private:
424 
425  QgsPointXY mOrigin;
426 
427 };
428 
429 
430 // adapted for QGIS geometry classes from original work at https://github.com/trylock/visibility by trylock
431 
438 class CORE_EXPORT QgsClockwiseAngleComparer
439 {
440  public:
441  explicit QgsClockwiseAngleComparer( const QgsPointXY &origin )
442  : mVertex( origin )
443  {}
444 
445  bool operator()( const QgsPointXY &a, const QgsPointXY &b ) const;
446 
447  private:
448 
449  QgsPointXY mVertex;
450 
451 };
452 
454 
455 #endif // QGSINTERNALGEOMETRYENGINE_H
QgsInternalGeometryEngine::orthogonalize
QgsGeometry orthogonalize(double tolerance=1.0E-8, int maxIterations=1000, double angleThreshold=15.0) const
Attempts to orthogonalize a line or polygon geometry by shifting vertices to make the geometries angl...
Definition: qgsinternalgeometryengine.cpp:641
QgsInternalGeometryEngine::extrude
QgsGeometry extrude(double x, double y) const
Will extrude a line or (segmentized) curve by a given offset and return a polygon representation of i...
Definition: qgsinternalgeometryengine.cpp:189
QgsInternalGeometryEngine::densifyByCount
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Densifies the geometry by adding the specified number of extra nodes within each segment of the geome...
Definition: qgsinternalgeometryengine.cpp:799
Qgis::DashPatternLineEndingRule::NoRule
@ NoRule
No special rule.
QgsInternalGeometryEngine::applyDashPattern
QgsGeometry applyDashPattern(const QVector< double > &pattern, Qgis::DashPatternLineEndingRule startRule=Qgis::DashPatternLineEndingRule::NoRule, Qgis::DashPatternLineEndingRule endRule=Qgis::DashPatternLineEndingRule::NoRule, Qgis::DashPatternSizeAdjustment adjustment=Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap, double patternOffset=0) const
Applies a dash pattern to a geometry, returning a MultiLineString geometry which is the input geometr...
Definition: qgsinternalgeometryengine.cpp:2966
QgsInternalGeometryEngine::isAxisParallelRectangle
bool isAxisParallelRectangle(double maximumDeviation, bool simpleRectanglesOnly=false) const
Returns true if the geometry is a polygon that is almost an axis-parallel rectangle.
Definition: qgsinternalgeometryengine.cpp:161
QgsLineSegment2D
Represents a single 2D line segment, consisting of a 2D start and end vertex only.
Definition: qgslinesegment.h:31
QgsInternalGeometryEngine::variableWidthBufferByM
QgsGeometry variableWidthBufferByM(int segments) const
Calculates a variable width buffer using the m-values from a (multi)line geometry.
Definition: qgsinternalgeometryengine.cpp:1184
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsInternalGeometryEngine::variableWidthBuffer
QgsGeometry variableWidthBuffer(int segments, const std::function< std::unique_ptr< double[] >(const QgsLineString *line) > &widthFunction) const
Calculates a variable width buffer for a (multi)curve geometry.
Definition: qgsinternalgeometryengine.cpp:1042
QgsInternalGeometryEngine::poleOfInaccessibility
QgsGeometry poleOfInaccessibility(double precision, double *distanceFromBoundary=nullptr) const
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal ...
Definition: qgsinternalgeometryengine.cpp:380
QgsInternalGeometryEngine::randomPointsInPolygon
static QVector< QgsPointXY > randomPointsInPolygon(const QgsGeometry &polygon, int count, const std::function< bool(const QgsPointXY &) > &acceptPoint, unsigned long seed=0, QgsFeedback *feedback=nullptr, int maxTriesPerPoint=0)
Returns a list of count random points generated inside a polygon geometry (if acceptPoint is specifie...
Definition: qgsinternalgeometryengine.cpp:1200
QgsInternalGeometryEngine::lastError
QString lastError() const
Returns an error string referring to the last error encountered.
Definition: qgsinternalgeometryengine.cpp:45
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsInternalGeometryEngine::roundWaves
QgsGeometry roundWaves(double wavelength, double amplitude, bool strictWavelength=false) const
Constructs rounded (sine-like) waves along the boundary of the geometry, with the specified wavelengt...
Definition: qgsinternalgeometryengine.cpp:2611
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
precision
int precision
Definition: qgswfsgetfeature.cpp:103
QgsInternalGeometryEngine::roundWavesRandomized
QgsGeometry roundWavesRandomized(double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed=0) const
Constructs randomized rounded (sine-like) waves along the boundary of the geometry,...
Definition: qgsinternalgeometryengine.cpp:2650
QgsRay2D::QgsRay2D
QgsRay2D(const QgsPointXY &origin, QgsVector direction)
Constructor for a ray starting at the given origin and extending an infinite distance in the specifie...
Definition: qgsinternalgeometryengine.h:369
QgsInternalGeometryEngine::convertToCurves
QgsGeometry convertToCurves(double distanceTolerance, double angleTolerance) const
Attempts to convert a non-curved geometry into a curved geometry type (e.g.
Definition: qgsinternalgeometryengine.cpp:1598
QgsInternalGeometryEngine
This class offers geometry processing methods.
Definition: qgsinternalgeometryengine.h:41
Qgis::DashPatternSizeAdjustment
DashPatternSizeAdjustment
Dash pattern size adjustment options.
Definition: qgis.h:1546
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsInternalGeometryEngine::squareWavesRandomized
QgsGeometry squareWavesRandomized(double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed=0) const
Constructs randomized square waves along the boundary of the geometry, with the specified wavelength ...
Definition: qgsinternalgeometryengine.cpp:2234
QgsInternalGeometryEngine::orientedMinimumBoundingBox
QgsGeometry orientedMinimumBoundingBox(double &area, double &angle, double &width, double &height) const
Returns the oriented minimum bounding box for the geometry, which is the smallest (by area) rotated r...
Definition: qgsinternalgeometryengine.cpp:1634
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:79
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsInternalGeometryEngine::densifyByDistance
QgsGeometry densifyByDistance(double distance) const
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum...
Definition: qgsinternalgeometryengine.cpp:835
Qgis::DashPatternLineEndingRule
DashPatternLineEndingRule
Dash pattern line ending rules.
Definition: qgis.h:1531
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsVector
A class to represent a vector. Currently no Z axis / 2.5D support is implemented.
Definition: qgsvector.h:29
QgsInternalGeometryEngine::squareWaves
QgsGeometry squareWaves(double wavelength, double amplitude, bool strictWavelength=false) const
Constructs square waves along the boundary of the geometry, with the specified wavelength and amplitu...
Definition: qgsinternalgeometryengine.cpp:2195
segment
QLineF segment(int index, QRectF rect, double radius)
Definition: qgsshapegenerator.cpp:25
QgsRay2D
A 2D ray which extends from an origin point to an infinite distance in a given direction.
Definition: qgsinternalgeometryengine.h:361
MathUtils::angle
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
QgsInternalGeometryEngine::triangularWaves
QgsGeometry triangularWaves(double wavelength, double amplitude, bool strictWavelength=false) const
Constructs triangular waves along the boundary of the geometry, with the specified wavelength and amp...
Definition: qgsinternalgeometryengine.cpp:1899
QgsInternalGeometryEngine::QgsInternalGeometryEngine
QgsInternalGeometryEngine(const QgsGeometry &geometry)
The caller is responsible that the geometry is available and unchanged for the whole lifetime of this...
Definition: qgsinternalgeometryengine.cpp:39
QgsInternalGeometryEngine::triangularWavesRandomized
QgsGeometry triangularWavesRandomized(double minimumWavelength, double maximumWavelength, double minimumAmplitude, double maximumAmplitude, unsigned long seed=0) const
Constructs randomized triangular waves along the boundary of the geometry, with the specified wavelen...
Definition: qgsinternalgeometryengine.cpp:1938
qgspointxy.h
QgsInternalGeometryEngine::taperedBuffer
QgsGeometry taperedBuffer(double startWidth, double endWidth, int segments) const
Calculates a tapered width buffer for a (multi)curve geometry.
Definition: qgsinternalgeometryengine.cpp:1151
Qgis::DashPatternSizeAdjustment::ScaleBothDashAndGap
@ ScaleBothDashAndGap
Both the dash and gap lengths are adjusted equally.