QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
|
This class offers geometry processing methods. More...
#include <qgsinternalgeometryengine.h>
Public Member Functions | |
QgsInternalGeometryEngine (const QgsGeometry &geometry) | |
The caller is responsible that the geometry is available and unchanged for the whole lifetime of this object. More... | |
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 geometry stroked along each line/ring with the specified pattern. More... | |
QgsGeometry | convertToCurves (double distanceTolerance, double angleTolerance) const |
Attempts to convert a non-curved geometry into a curved geometry type (e.g. More... | |
QgsGeometry | densifyByCount (int extraNodesPerSegment) const |
Densifies the geometry by adding the specified number of extra nodes within each segment of the geometry. More... | |
QgsGeometry | densifyByDistance (double distance) const |
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum distance between any two nodes does not exceed the specified distance. More... | |
QgsGeometry | extrude (double x, double y) const |
Will extrude a line or (segmentized) curve by a given offset and return a polygon representation of it. More... | |
bool | isAxisParallelRectangle (double maximumDeviation, bool simpleRectanglesOnly=false) const |
Returns true if the geometry is a polygon that is almost an axis-parallel rectangle. More... | |
QString | lastError () const |
Returns an error string referring to the last error encountered. More... | |
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 rectangle which fully encompasses the geometry. More... | |
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 angles either right angles or flat lines. More... | |
QgsGeometry | poleOfInaccessibility (double precision, double *distanceFromBoundary=nullptr) const |
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal point from the boundary of the surface. More... | |
QgsGeometry | roundWaves (double wavelength, double amplitude, bool strictWavelength=false) const |
Constructs rounded (sine-like) waves along the boundary of the geometry, with the specified wavelength and amplitude. More... | |
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, with the specified wavelength and amplitude ranges. More... | |
QgsGeometry | squareWaves (double wavelength, double amplitude, bool strictWavelength=false) const |
Constructs square waves along the boundary of the geometry, with the specified wavelength and amplitude. More... | |
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 and amplitude ranges. More... | |
QgsGeometry | taperedBuffer (double startWidth, double endWidth, int segments) const |
Calculates a tapered width buffer for a (multi)curve geometry. More... | |
QgsGeometry | triangularWaves (double wavelength, double amplitude, bool strictWavelength=false) const |
Constructs triangular waves along the boundary of the geometry, with the specified wavelength and amplitude. More... | |
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 wavelength and amplitude ranges. More... | |
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. More... | |
QgsGeometry | variableWidthBufferByM (int segments) const |
Calculates a variable width buffer using the m-values from a (multi)line geometry. More... | |
Static Public Member Functions | |
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 specified, and restrictive, the number of points returned may be less than count). More... | |
This class offers geometry processing methods.
The methods are available via QgsGeometry::[geometryfunction] and therefore this does not need to be accessed directly.
Definition at line 41 of file qgsinternalgeometryengine.h.
|
explicit |
The caller is responsible that the geometry is available and unchanged for the whole lifetime of this object.
geometry |
Definition at line 39 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::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 geometry stroked along each line/ring with the specified pattern.
The startRule and endRule options can be set to control how the dash pattern is adjusted at line endings. If a startRule or endRule is set, the adjustment option defines whether both dash and gaps, or only dash or gap sizes are adjusted to apply the rules.
The patternOffset option specifies how far along the pattern the result should start at. The offset is applied AFTER any start/end rules are applied.
Definition at line 2966 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::convertToCurves | ( | double | distanceTolerance, |
double | angleTolerance | ||
) | const |
Attempts to convert a non-curved geometry into a curved geometry type (e.g.
LineString to CompoundCurve, Polygon to CurvePolygon).
The distanceTolerance specifies the maximum deviation allowed between the original location of vertices and where they would fall on the candidate curved geometry.
This method only consider a segments as suitable for replacing with an arc if the points are all regularly spaced on the candidate arc. The pointSpacingAngleTolerance parameter specifies the maximum angular deviation (in radians) allowed when testing for regular point spacing.
Definition at line 1598 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::densifyByCount | ( | int | extraNodesPerSegment | ) | const |
Densifies the geometry by adding the specified number of extra nodes within each segment of the geometry.
If the geometry has z or m values present then these will be linearly interpolated at the added nodes. Curved geometry types are automatically segmentized by this routine.
Definition at line 799 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::densifyByDistance | ( | double | distance | ) | const |
Densifies the geometry by adding regularly placed extra nodes inside each segment so that the maximum distance between any two nodes does not exceed the specified distance.
E.g. specifying a distance 3 would cause the segment [0 0] -> [10 0] to be converted to [0 0] -> [2.5 0] -> [5 0] -> [7.5 0] -> [10 0], since 3 extra nodes are required on the segment and spacing these at 2.5 increments allows them to be evenly spaced over the segment. If the geometry has z or m values present then these will be linearly interpolated at the added nodes. Curved geometry types are automatically segmentized by this routine.
Definition at line 835 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::extrude | ( | double | x, |
double | y | ||
) | const |
Will extrude a line or (segmentized) curve by a given offset and return a polygon representation of it.
x | offset in x direction |
y | offset in y direction |
Definition at line 189 of file qgsinternalgeometryengine.cpp.
bool QgsInternalGeometryEngine::isAxisParallelRectangle | ( | double | maximumDeviation, |
bool | simpleRectanglesOnly = false |
||
) | const |
Returns true
if the geometry is a polygon that is almost an axis-parallel rectangle.
The maximumDeviation argument specifes the maximum angle (in degrees) that the polygon edges are allowed to deviate from axis parallel lines.
By default the check will permit polygons with more than 4 edges, so long as the overall shape of the polygon is an axis-parallel rectangle (i.e. it is tolerant to rectangles with additional vertices added along the rectangle sides). If simpleRectanglesOnly is set to true
then the method will only return true
if the geometry is a simple rectangle consisting of 4 edges.
Definition at line 161 of file qgsinternalgeometryengine.cpp.
QString QgsInternalGeometryEngine::lastError | ( | ) | const |
Returns an error string referring to the last error encountered.
Definition at line 45 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::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 rectangle which fully encompasses the geometry.
The area, angle of the long axis (clockwise in degrees from North), width and height of the rotated bounding box will also be returned.
If an error was encountered while creating the result, more information can be retrieved by calling lastError().
Definition at line 1634 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::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 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.
Definition at line 641 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::poleOfInaccessibility | ( | double | precision, |
double * | distanceFromBoundary = nullptr |
||
) | const |
Calculates the approximate pole of inaccessibility for a surface, which is the most distant internal point from the boundary of the surface.
This function uses the 'polylabel' algorithm (Vladimir Agafonkin, 2016), which is an iterative approach guaranteed to find the true pole of inaccessibility within a specified tolerance. More precise tolerances require more iterations and will take longer to calculate. Optionally, the distance to the polygon boundary from the pole can be stored.
Definition at line 380 of file qgsinternalgeometryengine.cpp.
|
static |
Returns a list of count random points generated inside a polygon geometry (if acceptPoint is specified, and restrictive, the number of points returned may be less than count).
Optionally, a specific random seed can be used when generating points. If seed is 0, then a completely random sequence of points will be generated.
The acceptPoint function is used to filter result candidates. If the function returns false
, then the point will not be accepted and another candidate generated.
The optional feedback argument can be used to provide cancellation support during the point generation.
When acceptPoint is specified, maxTriesPerPoint defines how many attempts to perform before giving up generating a point.
Definition at line 1200 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::roundWaves | ( | double | wavelength, |
double | amplitude, | ||
bool | strictWavelength = false |
||
) | const |
Constructs rounded (sine-like) waves along the boundary of the geometry, with the specified wavelength and amplitude.
By default the wavelength argument is treated as a "maximum wavelength", where the actual wavelength will be dynamically adjusted so that an exact number of waves are created along the boundaries of the geometry. If strictWavelength is set to true
then the wavelength will be used exactly and an incomplete pattern may be used for the final waveform.
Definition at line 2611 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::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, with the specified wavelength and amplitude ranges.
The minimumWavelength and maximumWavelength arguments set the range for the randomized wavelength. This is evaluated for each individual waveform created along the geometry boundaries, so the resultant geometry will consist of many different wavelengths.
Similarly, the minimumAmplitude and maximumAmplitude arguments define the range for the randomized amplitude of the square components. Randomized amplitude values will be calculated individually for waves placed on each either side of the input geometry boundaries.
Optionally, a specific random seed can be used when generating points. If seed is 0, then a completely random sequence of points will be generated.
Definition at line 2650 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::squareWaves | ( | double | wavelength, |
double | amplitude, | ||
bool | strictWavelength = false |
||
) | const |
Constructs square waves along the boundary of the geometry, with the specified wavelength and amplitude.
By default the wavelength argument is treated as a "maximum wavelength", where the actual wavelength will be dynamically adjusted so that an exact number of square waves are created along the boundaries of the geometry. If strictWavelength is set to true
then the wavelength will be used exactly and an incomplete pattern may be used for the final waveform.
Definition at line 2195 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::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 and amplitude ranges.
The minimumWavelength and maximumWavelength arguments set the range for the randomized wavelength. This is evaluated for each individual square waveform created along the geometry boundaries, so the resultant geometry will consist of many different wavelengths.
Similarly, the minimumAmplitude and maximumAmplitude arguments define the range for the randomized amplitude of the square components. Randomized amplitude values will be calculated individiually for squares placed on each either side of the input geometry boundaries.
Optionally, a specific random seed can be used when generating points. If seed is 0, then a completely random sequence of points will be generated.
Definition at line 2234 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::taperedBuffer | ( | double | startWidth, |
double | endWidth, | ||
int | segments | ||
) | const |
Calculates a tapered width buffer for a (multi)curve geometry.
The buffer begins at a width of startWidth at the start of each curve, and ends at a width of endWidth. Note that unlike QgsGeometry::buffer() methods, startWidth and endWidth are the diameter of the buffer at these points, not the radius.
The segments argument specifies the number of segments to approximate quarter-circle curves in the buffer.
Non (multi)curve input geometries will return a null output geometry.
Definition at line 1151 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::triangularWaves | ( | double | wavelength, |
double | amplitude, | ||
bool | strictWavelength = false |
||
) | const |
Constructs triangular waves along the boundary of the geometry, with the specified wavelength and amplitude.
By default the wavelength argument is treated as a "maximum wavelength", where the actual wavelength will be dynamically adjusted so that an exact number of triangular waves are created along the boundaries of the geometry. If strictWavelength is set to true
then the wavelength will be used exactly and an incomplete pattern may be used for the final waveform.
Definition at line 1899 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::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 wavelength and amplitude ranges.
The minimumWavelength and maximumWavelength arguments set the range for the randomized wavelength. This is evaluated for each individual triangular waveform created along the geometry boundaries, so the resultant geometry will consist of many different wavelengths.
Similarly, the minimumAmplitude and maximumAmplitude arguments define the range for the randomized amplitude of the triangular components. Randomized amplitude values will be calculated individiually for triangles placed on each either side of the input geometry boundaries.
Optionally, a specific random seed can be used when generating points. If seed is 0, then a completely random sequence of points will be generated.
Definition at line 1938 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::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.
The width of the buffer at each node in the input linestrings is calculated by calling the specified widthFunction, which must return an array of the buffer widths for every node in the line.
The segments argument specifies the number of segments to approximate quarter-circle curves in the buffer.
Non (multi)curve input geometries will return a null output geometry.
Definition at line 1042 of file qgsinternalgeometryengine.cpp.
QgsGeometry QgsInternalGeometryEngine::variableWidthBufferByM | ( | int | segments | ) | const |
Calculates a variable width buffer using the m-values from a (multi)line geometry.
The segments argument specifies the number of segments to approximate quarter-circle curves in the buffer.
Non (multi)line input geometries will return a null output geometry.
Definition at line 1184 of file qgsinternalgeometryengine.cpp.