QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override;
121
122 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
123 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
124 QString asWkt( int precision = 17 ) const override;
125 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
126 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
127 json asJsonObject( int precision = 17 ) const override SIP_SKIP;
128 QString asKml( int precision = 17 ) const override;
129 void normalize() override SIP_HOLDGIL;
130
131 //surface interface
132 double area() const override SIP_HOLDGIL;
133 double perimeter() const override SIP_HOLDGIL;
134 QgsAbstractGeometry *boundary() const override SIP_FACTORY;
135 QgsPolyhedralSurface *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
136 QgsPolyhedralSurface *simplifyByDistance( double tolerance ) const override SIP_FACTORY;
137 bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
138 bool boundingBoxIntersects( const QgsBox3D &box3d ) const override SIP_HOLDGIL;
139
145 int numPatches() const SIP_HOLDGIL
146 {
147 return mPatches.size();
148 }
149
150#ifndef SIP_RUN
151
157 const QgsPolygon *patchN( int i ) const
158 {
159 if ( i < 0 || i >= mPatches.size() )
160 {
161 return nullptr;
162 }
163 return mPatches.at( i );
164 }
165
172 {
173 if ( i < 0 || i >= mPatches.size() )
174 {
175 return nullptr;
176 }
177 return mPatches.at( i );
178 }
179#else
180
188 SIP_PYOBJECT patchN( int i ) SIP_HOLDGIL SIP_TYPEHINT( QgsPolygon );
189 % MethodCode
190 if ( a0 < 0 || a0 >= sipCpp->numPatches() )
191 {
192 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
193 sipIsErr = 1;
194 }
195 else
196 {
197 return sipConvertFromType( const_cast< QgsPolygon * >( sipCpp->patchN( a0 ) ), sipType_QgsPolygon, NULL );
198 }
199 % End
200#endif
201
205 virtual void setPatches( const QVector<QgsPolygon *> &patches SIP_TRANSFER );
206
210 virtual void addPatch( QgsPolygon *patch SIP_TRANSFER );
211
212#ifndef SIP_RUN
213
220 bool removePatch( int patchIndex );
221#else
222
230 bool removePatch( int ringIndex );
231 % MethodCode
232 if ( a0 < 0 || a0 >= sipCpp->numPatches() )
233 {
234 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
235 sipIsErr = 1;
236 }
237 else
238 {
239 return PyBool_FromLong( sipCpp->removePatch( a0 ) );
240 }
241 % End
242#endif
243
244 QPainterPath asQPainterPath() const override;
245 void draw( QPainter &p ) const override;
247 void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
248
249 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
250 bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
251 bool deleteVertex( QgsVertexId position ) override;
252
253 QgsCoordinateSequence coordinateSequence() const override;
254 int nCoordinates() const override;
255 int vertexNumberFromVertexId( QgsVertexId id ) const override;
256 bool isEmpty() const override SIP_HOLDGIL;
257 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;
258
259 bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
260 void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
261 bool hasCurvedSegments() const final;
262
268 QgsAbstractGeometry *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
269
275 double vertexAngle( QgsVertexId vertex ) const override;
276
277 int vertexCount( int part = 0, int ring = 0 ) const override;
278 int ringCount( int part = 0 ) const override SIP_HOLDGIL;
279 int partCount() const override SIP_HOLDGIL;
280 QgsPoint vertexAt( QgsVertexId id ) const override;
281 double segmentLength( QgsVertexId startVertex ) const override;
282
283 bool addZValue( double zValue = 0 ) override;
284 bool addMValue( double mValue = 0 ) override;
285 bool dropZValue() override;
286 bool dropMValue() override;
287 void swapXy() override;
288
289 QgsMultiSurface *toCurveType() const override SIP_FACTORY;
290
291 bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) override;
292
297 QgsMultiPolygon *toMultiPolygon() const SIP_FACTORY;
298
299#ifndef SIP_RUN
300 void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
301 void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
302
309 inline static const QgsPolyhedralSurface *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
310 {
311 if ( !geom )
312 return nullptr;
313
314 const Qgis::WkbType flatType = QgsWkbTypes::flatType( geom->wkbType() );
315 if ( flatType == Qgis::WkbType::PolyhedralSurface
316 || flatType == Qgis::WkbType::TIN )
317 return static_cast<const QgsPolyhedralSurface *>( geom );
318
319 return nullptr;
320 }
321#endif
322
324
325#ifdef SIP_RUN
326 SIP_PYOBJECT __repr__();
327 % MethodCode
328 QString wkt = sipCpp->asWkt();
329 if ( wkt.length() > 1000 )
330 wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
331 QString str = QStringLiteral( "<QgsPolyhedralSurface: %1>" ).arg( wkt );
332 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
333 % End
334
338 int __len__() const;
339 % MethodCode
340 sipRes = sipCpp->numPatches();
341 % End
342
351 SIP_PYOBJECT __getitem__( int index ) SIP_TYPEHINT( QgsPolygon );
352 % MethodCode
353 const int count = sipCpp->numPatches();
354 if ( a0 < -count || a0 >= count )
355 {
356 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
357 sipIsErr = 1;
358 }
359 else if ( a0 >= 0 )
360 {
361 return sipConvertFromType( sipCpp->patchN( a0 ), sipType_QgsPolygon, NULL );
362 }
363 else
364 {
365 return sipConvertFromType( sipCpp->patchN( count + a0 ), sipType_QgsPolygon, NULL );
366 }
367 % End
368#endif
369
370 protected:
371
372 int childCount() const override;
373 QgsAbstractGeometry *childGeometry( int index ) const override;
374 int compareToSameClass( const QgsAbstractGeometry *other ) const override;
375 QgsBox3D calculateBoundingBox3D() const override;
376
377 QVector< QgsPolygon * > mPatches;
378};
379
380// clazy:excludeall=qstring-allocations
381
382#endif // QGSPOLYHEDRALSURFACE_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
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:39
#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:70
int precision
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30