QGIS API Documentation  3.14.0-Pi (9f7028fd23)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 : matthias@opengis.ch
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 
60  QgsGeometry extrude( double x, double y ) const;
61 
71  QgsGeometry poleOfInaccessibility( double precision, double *distanceFromBoundary = nullptr ) const;
72 
81  QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
82 
91  QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
92 
106  QgsGeometry densifyByDistance( double distance ) const;
107 
122  QgsGeometry variableWidthBuffer( int segments, const std::function< std::unique_ptr< double[] >( const QgsLineString *line ) > &widthFunction ) const;
123 
138  QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
139 
150  QgsGeometry variableWidthBufferByM( int segments ) const;
151 
166  static QVector< QgsPointXY > randomPointsInPolygon( const QgsGeometry &polygon, int count,
167  const std::function< bool( const QgsPointXY & ) > &acceptPoint, unsigned long seed = 0, QgsFeedback *feedback = nullptr );
168 
184  QgsGeometry convertToCurves( double distanceTolerance, double angleTolerance ) const;
185 
186  private:
187  const QgsAbstractGeometry *mGeometry = nullptr;
188 };
189 
196 class CORE_EXPORT QgsRay2D
197 {
198  public:
199 
204  QgsRay2D( const QgsPointXY &origin, QgsVector direction )
205  : origin( origin )
206  , direction( direction )
207  {}
208 
216  bool intersects( const QgsLineSegment2D &segment, QgsPointXY &intersectPoint ) const;
217 
218  private:
219 
220  QgsPointXY origin;
221  QgsVector direction;
222 };
223 
225 
226 // adapted for QGIS geometry classes from original work at https://github.com/trylock/visibility by trylock
227 
236 class CORE_EXPORT QgsLineSegmentDistanceComparer
237 {
238  public:
239 
244  explicit QgsLineSegmentDistanceComparer( const QgsPointXY &origin )
245  : mOrigin( origin )
246  {}
247 
255  bool operator()( QgsLineSegment2D ab, QgsLineSegment2D cd ) const;
256 
257  private:
258 
259  QgsPointXY mOrigin;
260 
261 };
262 
263 
264 // adapted for QGIS geometry classes from original work at https://github.com/trylock/visibility by trylock
265 
271 class CORE_EXPORT QgsClockwiseAngleComparer
272 {
273  public:
274  explicit QgsClockwiseAngleComparer( const QgsPointXY &origin )
275  : mVertex( origin )
276  {}
277 
278  bool operator()( const QgsPointXY &a, const QgsPointXY &b ) const;
279 
280  private:
281 
282  QgsPointXY mVertex;
283 
284 };
285 
287 
288 #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:494
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:49
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:651
QgsLineSegment2D
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:1029
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:892
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:239
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:43
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
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)
Returns a list of count random points generated inside a polygon geometry.
Definition: qgsinternalgeometryengine.cpp:1044
precision
int precision
Definition: qgswfsgetfeature.cpp:103
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:204
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:1383
QgsInternalGeometryEngine
Definition: qgsinternalgeometryengine.h:41
QgsFeedback
Definition: qgsfeedback.h:43
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:71
QgsPointXY
Definition: qgspointxy.h:43
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:686
QgsGeometry
Definition: qgsgeometry.h:122
QgsVector
Definition: qgsvector.h:29
QgsRay2D
A 2D ray which extends from an origin point to an infinite distance in a given direction.
Definition: qgsinternalgeometryengine.h:196
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:37
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:997