QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 
57  QString lastError() const;
58 
67  QgsGeometry extrude( double x, double y ) const;
68 
78  QgsGeometry poleOfInaccessibility( double precision, double *distanceFromBoundary = nullptr ) const;
79 
88  QgsGeometry orthogonalize( double tolerance = 1.0E-8, int maxIterations = 1000, double angleThreshold = 15.0 ) const;
89 
98  QgsGeometry densifyByCount( int extraNodesPerSegment ) const;
99 
113  QgsGeometry densifyByDistance( double distance ) const;
114 
129  QgsGeometry variableWidthBuffer( int segments, const std::function< std::unique_ptr< double[] >( const QgsLineString *line ) > &widthFunction ) const;
130 
145  QgsGeometry taperedBuffer( double startWidth, double endWidth, int segments ) const;
146 
157  QgsGeometry variableWidthBufferByM( int segments ) const;
158 
179  static QVector< QgsPointXY > randomPointsInPolygon( const QgsGeometry &polygon, int count,
180  const std::function< bool( const QgsPointXY & ) > &acceptPoint, unsigned long seed = 0, QgsFeedback *feedback = nullptr, int maxTriesPerPoint = 0 );
181 
197  QgsGeometry convertToCurves( double distanceTolerance, double angleTolerance ) const;
198 
209  QgsGeometry orientedMinimumBoundingBox( double &area SIP_OUT, double &angle SIP_OUT, double &width SIP_OUT, double &height SIP_OUT ) const;
210 
211  private:
212  const QgsAbstractGeometry *mGeometry = nullptr;
213 
214  mutable QString mLastError;
215 };
216 
223 class CORE_EXPORT QgsRay2D
224 {
225  public:
226 
231  QgsRay2D( const QgsPointXY &origin, QgsVector direction )
232  : origin( origin )
233  , direction( direction )
234  {}
235 
243  bool intersects( const QgsLineSegment2D &segment, QgsPointXY &intersectPoint ) const;
244 
245  private:
246 
247  QgsPointXY origin;
248  QgsVector direction;
249 };
250 
252 
253 // adapted for QGIS geometry classes from original work at https://github.com/trylock/visibility by trylock
254 
264 class CORE_EXPORT QgsLineSegmentDistanceComparer
265 {
266  public:
267 
272  explicit QgsLineSegmentDistanceComparer( const QgsPointXY &origin )
273  : mOrigin( origin )
274  {}
275 
283  bool operator()( QgsLineSegment2D ab, QgsLineSegment2D cd ) const;
284 
285  private:
286 
287  QgsPointXY mOrigin;
288 
289 };
290 
291 
292 // adapted for QGIS geometry classes from original work at https://github.com/trylock/visibility by trylock
293 
300 class CORE_EXPORT QgsClockwiseAngleComparer
301 {
302  public:
303  explicit QgsClockwiseAngleComparer( const QgsPointXY &origin )
304  : mVertex( origin )
305  {}
306 
307  bool operator()( const QgsPointXY &a, const QgsPointXY &b ) const;
308 
309  private:
310 
311  QgsPointXY mVertex;
312 
313 };
314 
316 
317 #endif // QGSINTERNALGEOMETRYENGINE_H
Abstract base class for all geometries.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
This class offers geometry processing methods.
QgsInternalGeometryEngine(const QgsGeometry &geometry)
The caller is responsible that the geometry is available and unchanged for the whole lifetime of this...
QgsGeometry poleOfInaccessibility(double precision, double *distanceFromBoundary=nullptr) const
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal ...
QgsGeometry variableWidthBufferByM(int segments) const
Calculates a variable width buffer using the m-values from a (multi)line geometry.
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...
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...
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.
QString lastError() const
Returns an error string referring to the last error encountered.
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...
QgsGeometry densifyByDistance(double distance) const
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum...
QgsGeometry taperedBuffer(double startWidth, double endWidth, int segments) const
Calculates a tapered width buffer for a (multi)curve geometry.
QgsGeometry densifyByCount(int extraNodesPerSegment) const
Densifies the geometry by adding the specified number of extra nodes within each segment of the geome...
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...
QgsGeometry convertToCurves(double distanceTolerance, double angleTolerance) const
Attempts to convert a non-curved geometry into a curved geometry type (e.g.
Represents a single 2D line segment, consisting of a 2D start and end vertex only.
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
A class to represent a 2D point.
Definition: qgspointxy.h:44
A 2D ray which extends from an origin point to an infinite distance in a given direction.
QgsRay2D(const QgsPointXY &origin, QgsVector direction)
Constructor for a ray starting at the given origin and extending an infinite distance in the specifie...
A class to represent a vector.
Definition: qgsvector.h:30
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
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#define SIP_OUT
Definition: qgis_sip.h:58
int precision