QGIS API Documentation 3.99.0-Master (e9821da5c6b)
Loading...
Searching...
No Matches
qgstriangulatedsurface.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstriangulatedsurface.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 QGSTRIANGULATEDSURFACE_H
19#define QGSTRIANGULATEDSURFACE_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
24
25#include <QString>
26
27using namespace Qt::StringLiterals;
28
29class QgsTriangle;
30
31
42{
43 public:
47
48#ifndef SIP_RUN
49 private:
50 bool fuzzyHelper( const QgsAbstractGeometry &other, double epsilon, bool useDistance ) const
51 {
52 const QgsTriangulatedSurface *otherTriangulatedSurface = qgsgeometry_cast< const QgsTriangulatedSurface * >( &other );
53 if ( !otherTriangulatedSurface )
54 return false;
55
56 //run cheap checks first
57 if ( mWkbType != otherTriangulatedSurface->mWkbType )
58 return false;
59
60 if ( mPatches.count() != otherTriangulatedSurface->mPatches.count() )
61 return false;
62
63 for ( int i = 0; i < mPatches.count(); ++i )
64 {
65 if ( ( !mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) ) ||
66 ( mPatches.at( i ) && !otherTriangulatedSurface->mPatches.at( i ) ) )
67 return false;
68
69 if ( useDistance )
70 {
71 if ( mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) &&
72 !( *mPatches.at( i ) ).fuzzyDistanceEqual( *otherTriangulatedSurface->mPatches.at( i ), epsilon ) )
73 return false;
74 }
75 else
76 {
77 if ( mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) &&
78 !( *mPatches.at( i ) ).fuzzyEqual( *otherTriangulatedSurface->mPatches.at( i ), epsilon ) )
79 return false;
80 }
81 }
82
83 return true;
84 }
85#endif
86
87 public:
88 bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
89 {
90 return fuzzyHelper( other, epsilon, false );
91 }
92 bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
93 {
94 return fuzzyHelper( other, epsilon, true );
95 }
96
97 bool operator==( const QgsAbstractGeometry &other ) const override
98 {
99 return fuzzyEqual( other, 1e-8 );
100 }
101
102 bool operator!=( const QgsAbstractGeometry &other ) const override
103 {
104 return !operator==( other );
105 }
106
107 ~QgsTriangulatedSurface() override;
108
109 QString geometryType() const override SIP_HOLDGIL;
110 QgsTriangulatedSurface *clone() const override SIP_FACTORY;
111 void clear() override;
112
113 bool fromWkb( QgsConstWkbPtr &wkb ) override;
114 bool fromWkt( const QString &wkt ) override;
115
116 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
117 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
118 QString asKml( int precision = 17 ) const override;
119 void normalize() override SIP_HOLDGIL;
120
121 //surface interface
122 QgsTriangulatedSurface *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
123
124 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
125 bool deleteVertex( QgsVertexId position ) override;
126
130 void setTriangles( const QVector<QgsTriangle *> &triangles SIP_TRANSFER );
131
135 void addPatch( QgsPolygon *patch SIP_TRANSFER ) override;
136
140 void addTriangle( QgsTriangle *triangle SIP_TRANSFER );
141
142#ifndef SIP_RUN
143
147 QgsTriangle *triangleN( int index );
148#else
149
155 SIP_PYOBJECT triangleN( int index ) SIP_TYPEHINT( QgsPolygon );
156 % MethodCode
157 if ( a0 < 0 || a0 >= sipCpp->numPatches() )
158 {
159 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
160 sipIsErr = 1;
161 }
162 else
163 {
164 return sipConvertFromType( sipCpp->triangleN( a0 ), sipType_QgsTriangle, NULL );
165 }
166 % End
167#endif
168
169#ifndef SIP_RUN
170
176 const QgsTriangle *triangleN( int index ) const;
177#endif
178
179#ifndef SIP_RUN
180
189 inline static const QgsTriangulatedSurface *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
190 {
191 if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == Qgis::WkbType::TIN )
192 return static_cast<const QgsTriangulatedSurface *>( geom );
193
194 return nullptr;
195 }
196
205 inline static QgsTriangulatedSurface *cast( QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
206 {
207 if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == Qgis::WkbType::TIN )
208 return static_cast<QgsTriangulatedSurface *>( geom );
209
210 return nullptr;
211 }
212#endif
213
215
216#ifdef SIP_RUN
217 SIP_PYOBJECT __repr__();
218 % MethodCode
219 QString wkt = sipCpp->asWkt();
220 if ( wkt.length() > 1000 )
221 wkt = wkt.left( 1000 ) + u"..."_s;
222 QString str = u"<QgsTriangulatedSurface: %1>"_s.arg( wkt );
223 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
224 % End
225#endif
226
227 protected:
228
229 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
230};
231
232// clazy:excludeall=qstring-allocations
233
234#endif // QGSTRIANGULATEDSURFACE_H
@ TIN
TIN.
Definition qgis.h:296
Abstract base class for all geometries.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
QgsAbstractGeometry()=default
A const WKB pointer.
Definition qgswkbptr.h:139
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
Polygon geometry type.
Definition qgspolygon.h:37
QVector< QgsPolygon * > mPatches
QString geometryType() const override
Returns a unique string representing the geometry type.
int compareToSameClass(const QgsAbstractGeometry *other) const override
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
QgsPolyhedralSurface * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
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
QgsPolyhedralSurface & operator=(const QgsPolyhedralSurface &p)
Triangle geometry type.
Definition qgstriangle.h:33
Triangulated surface geometry type.
bool operator!=(const QgsAbstractGeometry &other) const override
static QgsTriangulatedSurface * cast(QgsAbstractGeometry *geom)
Cast the geom to a QgsTriangulatedSurface.
bool fuzzyEqual(const QgsAbstractGeometry &other, double epsilon=1e-8) const override
Performs fuzzy comparison between this geometry and other using an epsilon.
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 QgsTriangulatedSurface * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsTriangulatedSurface.
bool operator==(const QgsAbstractGeometry &other) const override
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:240
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_HOLDGIL
Definition qgis_sip.h:179
#define SIP_FACTORY
Definition qgis_sip.h:84
T qgsgeometry_cast(QgsAbstractGeometry *geom)
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:34