QGIS API Documentation 3.41.0-Master (cea29feecf2)
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
25class QgsTriangle;
26
27
38{
39 public:
43
44#ifndef SIP_RUN
45 private:
46 bool fuzzyHelper( const QgsAbstractGeometry &other, double epsilon, bool useDistance ) const
47 {
48 const QgsTriangulatedSurface *otherTriangulatedSurface = qgsgeometry_cast< const QgsTriangulatedSurface * >( &other );
49 if ( !otherTriangulatedSurface )
50 return false;
51
52 //run cheap checks first
53 if ( mWkbType != otherTriangulatedSurface->mWkbType )
54 return false;
55
56 if ( mPatches.count() != otherTriangulatedSurface->mPatches.count() )
57 return false;
58
59 for ( int i = 0; i < mPatches.count(); ++i )
60 {
61 if ( ( !mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) ) ||
62 ( mPatches.at( i ) && !otherTriangulatedSurface->mPatches.at( i ) ) )
63 return false;
64
65 if ( useDistance )
66 {
67 if ( mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) &&
68 !( *mPatches.at( i ) ).fuzzyDistanceEqual( *otherTriangulatedSurface->mPatches.at( i ), epsilon ) )
69 return false;
70 }
71 else
72 {
73 if ( mPatches.at( i ) && otherTriangulatedSurface->mPatches.at( i ) &&
74 !( *mPatches.at( i ) ).fuzzyEqual( *otherTriangulatedSurface->mPatches.at( i ), epsilon ) )
75 return false;
76 }
77 }
78
79 return true;
80 }
81#endif
82
83 public:
84 bool fuzzyEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
85 {
86 return fuzzyHelper( other, epsilon, false );
87 }
88 bool fuzzyDistanceEqual( const QgsAbstractGeometry &other, double epsilon = 1e-8 ) const override SIP_HOLDGIL
89 {
90 return fuzzyHelper( other, epsilon, true );
91 }
92
93 bool operator==( const QgsAbstractGeometry &other ) const override
94 {
95 return fuzzyEqual( other, 1e-8 );
96 }
97
98 bool operator!=( const QgsAbstractGeometry &other ) const override
99 {
100 return !operator==( other );
101 }
102
103 ~QgsTriangulatedSurface() override;
104
105 QString geometryType() const override SIP_HOLDGIL;
106 QgsTriangulatedSurface *clone() const override SIP_FACTORY;
107 void clear() override;
108
109 bool fromWkb( QgsConstWkbPtr &wkb ) override;
110 bool fromWkt( const QString &wkt ) override;
111
112 QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
113 QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
114 QString asKml( int precision = 17 ) const override;
115 void normalize() override SIP_HOLDGIL;
116
117 //surface interface
118 QgsTriangulatedSurface *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0, bool removeRedundantPoints = false ) const override SIP_FACTORY;
119
120 bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
121 bool deleteVertex( QgsVertexId position ) override;
122
126 void setTriangles( const QVector<QgsTriangle *> &triangles SIP_TRANSFER );
127
131 void addPatch( QgsPolygon *patch SIP_TRANSFER ) override;
132
136 void addTriangle( QgsTriangle *triangle SIP_TRANSFER );
137
138#ifndef SIP_RUN
139
143 QgsTriangle *triangleN( int index );
144#else
145
151 SIP_PYOBJECT triangleN( int index ) SIP_TYPEHINT( QgsPolygon );
152 % MethodCode
153 if ( a0 < 0 || a0 >= sipCpp->numPatches() )
154 {
155 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
156 sipIsErr = 1;
157 }
158 else
159 {
160 return sipConvertFromType( sipCpp->triangleN( a0 ), sipType_QgsTriangle, NULL );
161 }
162 % End
163#endif
164
165#ifndef SIP_RUN
166
172 const QgsTriangle *triangleN( int index ) const;
173#endif
174
175#ifndef SIP_RUN
176
183 inline static const QgsTriangulatedSurface *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
184 {
185 if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == Qgis::WkbType::TIN )
186 return static_cast<const QgsTriangulatedSurface *>( geom );
187
188 return nullptr;
189 }
190#endif
191
193
194#ifdef SIP_RUN
195 SIP_PYOBJECT __repr__();
196 % MethodCode
197 QString wkt = sipCpp->asWkt();
198 if ( wkt.length() > 1000 )
199 wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
200 QString str = QStringLiteral( "<QgsTriangulatedSurface: %1>" ).arg( wkt );
201 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
202 % End
203#endif
204
205 protected:
206
207 int compareToSameClass( const QgsAbstractGeometry *other ) const final;
208};
209
210// clazy:excludeall=qstring-allocations
211
212#endif // QGSTRIANGULATEDSURFACE_H
Abstract base class for all geometries.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
A const WKB pointer.
Definition qgswkbptr.h:138
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.
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
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:232
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_HOLDGIL
Definition qgis_sip.h:171
#define SIP_FACTORY
Definition qgis_sip.h:76
int precision
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30