QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 ) ) || ( mPatches.at( i ) && !otherTriangulatedSurface->mPatches.at( i ) ) )
66 return false;
67
68 if ( useDistance )
69 {
70 if ( mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) && !( *mPatches.at( i ) ).fuzzyDistanceEqual( *otherTriangulatedSurface->mPatches.at( i ), epsilon ) )
71 return false;
72 }
73 else
74 {
75 if ( mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) && !( *mPatches.at( i ) ).fuzzyEqual( *otherTriangulatedSurface->mPatches.at( i ), epsilon ) )
76 return false;
77 }
78 }
79
80 return true;
81 }
82#endif
83
84 public:
85 // clang-format off
86 bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
87 // clang-format on
88 {
89 return fuzzyHelper( other, epsilon, false );
90 }
91 bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
92 {
93 return fuzzyHelper( other, epsilon, true );
94 }
95
96 bool operator==( const QgsAbstractGeometry &other ) const override
97 {
98 return fuzzyEqual( other, 1e-8 );
99 }
100
101 bool operator!=( const QgsAbstractGeometry &other ) const override
102 {
103 return !operator==( other );
104 }
105
106 ~QgsTriangulatedSurface() override;
107
108 QString geometryType() const override SIP_HOLDGIL;
109 QgsTriangulatedSurface *clone() const override SIP_FACTORY;
110 void clear() override;
111
112 bool fromWkb( QgsConstWkbPtr &wkb ) override;
113 bool fromWkt( const QString &wkt ) override;
114
115 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
116 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
117 QString asKml( int precision = 17 ) const override;
118 void normalize() override SIP_HOLDGIL;
119
120 //surface interface
121 QgsTriangulatedSurface *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
122
123 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
124 bool deleteVertex( QgsVertexId position ) override;
125
129 void setTriangles( const QVector<QgsTriangle *> &triangles SIP_TRANSFER );
130
134 void addPatch( QgsPolygon *patch SIP_TRANSFER ) override;
135
139 void addTriangle( QgsTriangle *triangle SIP_TRANSFER );
140
141#ifndef SIP_RUN
142
146 QgsTriangle *triangleN( int index );
147#else
148// clang-format off
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// clang-format on
168#endif
169
170#ifndef SIP_RUN
171
177 const QgsTriangle *triangleN( int index ) const;
178#endif
179
180#ifndef SIP_RUN
181
190 inline static const QgsTriangulatedSurface *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
191 {
192 if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == Qgis::WkbType::TIN )
193 return static_cast<const QgsTriangulatedSurface *>( geom );
194
195 return nullptr;
196 }
197
206 inline static QgsTriangulatedSurface *cast( QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
207 {
208 if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == Qgis::WkbType::TIN )
209 return static_cast<QgsTriangulatedSurface *>( geom );
210
211 return nullptr;
212 }
213#endif
214
216
217#ifdef SIP_RUN
218// clang-format off
219 SIP_PYOBJECT __repr__();
220 % MethodCode
221 QString wkt = sipCpp->asWkt();
222 if ( wkt.length() > 1000 )
223 wkt = wkt.left( 1000 ) + u"..."_s;
224 QString str = u"<QgsTriangulatedSurface: %1>"_s.arg( wkt );
225 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
226 % End
227// clang-format on
228#endif
229
230 protected:
231
232 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
233};
234
235// clazy:excludeall=qstring-allocations
236
237#endif // QGSTRIANGULATEDSURFACE_H
@ TIN
TIN.
Definition qgis.h:310
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:211
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:239
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_HOLDGIL
Definition qgis_sip.h:178
#define SIP_FACTORY
Definition qgis_sip.h:83
T qgsgeometry_cast(QgsAbstractGeometry *geom)
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:34