QGIS API Documentation 3.39.0-Master (d85f3c2a281)
Loading...
Searching...
No Matches
qgspolyhedralsurface.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspolyhedralsurface.h
3 -------------------
4 begin : August 2024
5 copyright : (C) 2024 by Jean Felder
6 email : jean dot felder at oslandia dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSPOLYHEDRALSURFACE_H
19#define QGSPOLYHEDRALSURFACE_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgssurface.h"
24#include "qgspolygon.h"
25#include "qgsmultipolygon.h"
26
27
37class CORE_EXPORT QgsPolyhedralSurface: public QgsSurface
38{
39 public:
42
43
47 QgsPolyhedralSurface( const QgsMultiPolygon *multiPolygon );
48
50
51#ifndef SIP_RUN
52 private:
53 bool fuzzyHelper( const QgsAbstractGeometry &other, double epsilon, bool useDistance ) const
54 {
55 const QgsPolyhedralSurface *otherPolygon = qgsgeometry_cast< const QgsPolyhedralSurface * >( &other );
56 if ( !otherPolygon )
57 return false;
58
59 //run cheap checks first
60 if ( mWkbType != otherPolygon->mWkbType )
61 return false;
62
63 if ( mPatches.count() != otherPolygon->mPatches.count() )
64 return false;
65
66 for ( int i = 0; i < mPatches.count(); ++i )
67 {
68 if ( ( !mPatches.at( i ) && otherPolygon->mPatches.at( i ) ) ||
69 ( mPatches.at( i ) && !otherPolygon->mPatches.at( i ) ) )
70 return false;
71
72 if ( useDistance )
73 {
74 if ( mPatches.at( i ) && otherPolygon->mPatches.at( i ) &&
75 !( *mPatches.at( i ) ).fuzzyDistanceEqual( *otherPolygon->mPatches.at( i ), epsilon ) )
76 return false;
77 }
78 else
79 {
80 if ( mPatches.at( i ) && otherPolygon->mPatches.at( i ) &&
81 !( *mPatches.at( i ) ).fuzzyEqual( *otherPolygon->mPatches.at( i ), epsilon ) )
82 return false;
83 }
84 }
85
86 return true;
87 }
88#endif
89
90 public:
91 bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
92 {
93 return fuzzyHelper( other, epsilon, false );
94 }
95 bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
96 {
97 return fuzzyHelper( other, epsilon, true );
98 }
99
100 bool operator==( const QgsAbstractGeometry &other ) const override
101 {
102 return fuzzyEqual( other, 1e-8 );
103 }
104
105 bool operator!=( const QgsAbstractGeometry &other ) const override
106 {
107 return !operator==( other );
108 }
109
110 ~QgsPolyhedralSurface() override;
111
112 QString geometryType() const override SIP_HOLDGIL;
113 int dimension() const final SIP_HOLDGIL;
114 QgsPolyhedralSurface *clone() const override SIP_FACTORY;
115 void clear() override;
116
117 bool fromWkb( QgsConstWkbPtr &wkb ) override;
118 bool fromWkt( const QString &wkt ) override;
119
120 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
121 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
122 QString asWkt( int precision = 17 ) const override;
123 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
124 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
125 json asJsonObject( int precision = 17 ) const override SIP_SKIP;
126 QString asKml( int precision = 17 ) const override;
127 void normalize() override SIP_HOLDGIL;
128
129 //surface interface
130 double area() const override SIP_HOLDGIL;
131 double perimeter() const override SIP_HOLDGIL;
132 QgsAbstractGeometry *boundary() const override SIP_FACTORY;
133 QgsPolyhedralSurface *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
134 QgsPolyhedralSurface *simplifyByDistance( double tolerance ) const override SIP_FACTORY;
135 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
136 bool boundingBoxIntersects( const QgsBox3D &box3d ) const override SIP_HOLDGIL;
137
143 int numPatches() const SIP_HOLDGIL
144 {
145 return mPatches.size();
146 }
147
148#ifndef SIP_RUN
149
155 const QgsPolygon *patchN( int i ) const
156 {
157 if ( i < 0 || i >= mPatches.size() )
158 {
159 return nullptr;
160 }
161 return mPatches.at( i );
162 }
163
170 {
171 if ( i < 0 || i >= mPatches.size() )
172 {
173 return nullptr;
174 }
175 return mPatches.at( i );
176 }
177#else
178
186 SIP_PYOBJECT patchN( int i ) SIP_HOLDGIL SIP_TYPEHINT( QgsPolygon );
187 % MethodCode
188 if ( a0 < 0 || a0 >= sipCpp->numPatches() )
189 {
190 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
191 sipIsErr = 1;
192 }
193 else
194 {
195 return sipConvertFromType( const_cast< QgsPolygon * >( sipCpp->patchN( a0 ) ), sipType_QgsPolygon, NULL );
196 }
197 % End
198#endif
199
203 virtual void setPatches( const QVector<QgsPolygon *> &patches SIP_TRANSFER );
204
208 virtual void addPatch( QgsPolygon *patch SIP_TRANSFER );
209
210#ifndef SIP_RUN
211
218 bool removePatch( int patchIndex );
219#else
220
228 bool removePatch( int ringIndex );
229 % MethodCode
230 if ( a0 < 0 || a0 >= sipCpp->numPatches() )
231 {
232 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
233 sipIsErr = 1;
234 }
235 else
236 {
237 return PyBool_FromLong( sipCpp->removePatch( a0 ) );
238 }
239 % End
240#endif
241
242 QPainterPath asQPainterPath() const override;
243 void draw( QPainter &p ) const override;
245 void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
246
247 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
248 bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
249 bool deleteVertex( QgsVertexId position ) override;
250
251 QgsCoordinateSequence coordinateSequence() const override;
252 int nCoordinates() const override;
253 int vertexNumberFromVertexId( QgsVertexId id ) const override;
254 bool isEmpty() const override SIP_HOLDGIL;
255 double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
256
257 bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
258 void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
259 bool hasCurvedSegments() const final;
260
266 QgsAbstractGeometry *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
267
273 double vertexAngle( QgsVertexId vertex ) const override;
274
275 int vertexCount( int part = 0, int ring = 0 ) const override;
276 int ringCount( int part = 0 ) const override SIP_HOLDGIL;
277 int partCount() const override SIP_HOLDGIL;
278 QgsPoint vertexAt( QgsVertexId id ) const override;
279 double segmentLength( QgsVertexId startVertex ) const override;
280
281 bool addZValue( double zValue = 0 ) override;
282 bool addMValue( double mValue = 0 ) override;
283 bool dropZValue() override;
284 bool dropMValue() override;
285 void swapXy() override;
286
287 QgsMultiSurface *toCurveType() const override SIP_FACTORY;
288
289 bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) override;
290
295 QgsMultiPolygon *toMultiPolygon() const SIP_FACTORY;
296
297#ifndef SIP_RUN
298 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
299 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
300
307 inline static const QgsPolyhedralSurface *cast( const QgsAbstractGeometry *geom )
308 {
309 if ( !geom )
310 return nullptr;
311
312 const Qgis::WkbType flatType = QgsWkbTypes::flatType( geom->wkbType() );
313 if ( flatType == Qgis::WkbType::PolyhedralSurface
314 || flatType == Qgis::WkbType::TIN )
315 return static_cast<const QgsPolyhedralSurface *>( geom );
316
317 return nullptr;
318 }
319#endif
320
322
323#ifdef SIP_RUN
324 SIP_PYOBJECT __repr__();
325 % MethodCode
326 QString wkt = sipCpp->asWkt();
327 if ( wkt.length() > 1000 )
328 wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
329 QString str = QStringLiteral( "<QgsPolyhedralSurface: %1>" ).arg( wkt );
330 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
331 % End
332
336 int __len__() const;
337 % MethodCode
338 sipRes = sipCpp->numPatches();
339 % End
340
349 SIP_PYOBJECT __getitem__( int index ) SIP_TYPEHINT( QgsPolygon );
350 % MethodCode
351 const int count = sipCpp->numPatches();
352 if ( a0 < -count || a0 >= count )
353 {
354 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
355 sipIsErr = 1;
356 }
357 else if ( a0 >= 0 )
358 {
359 return sipConvertFromType( sipCpp->patchN( a0 ), sipType_QgsPolygon, NULL );
360 }
361 else
362 {
363 return sipConvertFromType( sipCpp->patchN( count + a0 ), sipType_QgsPolygon, NULL );
364 }
365 % End
366#endif
367
368 protected:
369
370 int childCount() const override;
371 QgsAbstractGeometry *childGeometry( int index ) const override;
372 int compareToSameClass( const QgsAbstractGeometry *other ) const override;
373 QgsBox3D calculateBoundingBox3D() const override;
374
375 QVector< QgsPolygon * > mPatches;
376};
377
378// clazy:excludeall=qstring-allocations
379
380#endif // QGSPOLYHEDRALSURFACE_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ PolyhedralSurface
PolyhedralSurface.
TransformDirection
Indicates the direction (forward or inverse) of a transform.
Definition qgis.h:2502
@ Forward
Forward transform (from source to destination)
An abstract base class for classes which transform geometries by transforming input points to output ...
Abstract base class for all geometries.
virtual QgsBox3D calculateBoundingBox3D() const
Calculates the minimal 3D bounding box for the geometry.
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
virtual int childCount() const
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
virtual void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform)
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
virtual bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const =0
Performs fuzzy comparison between this geometry and other using an epsilon.
virtual QPainterPath asQPainterPath() const =0
Returns the geometry represented as a QPainterPath.
virtual void transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection d=Qgis::TransformDirection::Forward, bool transformZ=false)=0
Transforms the geometry using a coordinate transform.
virtual void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
virtual QgsAbstractGeometry * childGeometry(int index) const
Returns pointer to child geometry (for geometries with child geometries - i.e.
virtual bool operator==(const QgsAbstractGeometry &other) const =0
virtual int compareToSameClass(const QgsAbstractGeometry *other) const =0
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
A const WKB pointer.
Definition qgswkbptr.h:138
Class for doing transforms between two map coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Multi polygon geometry collection.
Multi surface geometry collection.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Polygon geometry type.
Definition qgspolygon.h:33
Polyhedral surface geometry type.
bool operator!=(const QgsAbstractGeometry &other) const override
QVector< QgsPolygon * > mPatches
bool fuzzyDistanceEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy distance comparison between this geometry and other using an epsilon.
static const QgsPolyhedralSurface * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsPolyhedralSurface.
QgsPolygon * patchN(int i)
Retrieves a patch from the polyhedral surface.
bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy comparison between this geometry and other using an epsilon.
bool operator==(const QgsAbstractGeometry &other) const override
const QgsPolygon * patchN(int i) const
Retrieves a patch from the polyhedral surface.
Surface geometry type.
Definition qgssurface.h:34
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
#define str(x)
Definition qgis.cpp:38
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:232
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_HOLDGIL
Definition qgis_sip.h:171
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_THROW(name,...)
Definition qgis_sip.h:203
QVector< QgsRingSequence > QgsCoordinateSequence
double closestSegment(const QgsPolylineXY &pl, const QgsPointXY &pt, int &vertexAfter, double epsilon)
Definition qgstracer.cpp:69
int precision
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30