21#include <nlohmann/json.hpp>
31using namespace Qt::StringLiterals;
45 auto result = std::make_unique< QgsTriangulatedSurface >();
47 return result.release();
103 wkbPtr >> nTriangles;
104 std::unique_ptr< QgsTriangle > currentTriangle;
105 for (
int i = 0; i < nTriangles; ++i )
108 wkbPtr -= 1 +
sizeof( int );
112 currentTriangle = std::make_unique<QgsTriangle>();
118 currentTriangle->fromWkb( wkbPtr );
119 mPatches.append( currentTriangle.release() );
136 QString secondWithoutParentheses =
parts.second;
137 secondWithoutParentheses = secondWithoutParentheses.remove(
'(' ).remove(
')' ).simplified().remove(
' ' );
138 if ( (
parts.second.compare(
"EMPTY"_L1, Qt::CaseInsensitive ) == 0 ) || secondWithoutParentheses.isEmpty() )
141 QString defaultChildWkbType = u
"Triangle%1%2"_s.arg(
is3D() ? u
"Z"_s : QString(),
isMeasure() ? u
"M"_s : QString() );
144 for (
const QString &childWkt : blocks )
158 if ( !
mPatches.back()->fromWkt( childWkt ) )
170 QgsDebugError( u
"gml version 2 does not support TIN geometry"_s );
171 return QDomElement();
176 QDomElement elemTriangulatedSurface = doc.createElementNS( ns, u
"TriangulatedSurface"_s );
179 return elemTriangulatedSurface;
181 QDomElement elemPatches = doc.createElementNS( ns, u
"patches"_s );
188 QDomElement elemTriangle = triangle->
asGml3( doc, precision, ns, axisOrder );
189 elemPatches.appendChild( elemTriangle );
191 elemTriangulatedSurface.appendChild( elemPatches );
193 return elemTriangulatedSurface;
198 QgsDebugError( u
"kml format does not support TIN geometry"_s );
199 return QString(
"" );
234 auto gridifiedTriangle = std::make_unique<QgsTriangle>();
235 gridifiedTriangle->setExteriorRing( exteriorRing.release() );
236 surface->addPatch( gridifiedTriangle.release() );
239 return surface.release();
275 else if ( !triangle->
is3D() )
318 if ( !otherTriangulatedSurface )
321 const int nTriangles1 =
mPatches.size();
322 const int nTriangles2 = otherTriangulatedSurface->
mPatches.size();
323 if ( nTriangles1 < nTriangles2 )
327 if ( nTriangles1 > nTriangles2 )
332 for (
int i = 0; i < nTriangles1; i++ )
334 const int triangleComp =
mPatches.at( i )->compareTo( otherTriangulatedSurface->
mPatches.at( i ) );
335 if ( triangleComp != 0 )
WkbType
The WKB type describes the number of dimensions a geometry has.
virtual QgsAbstractGeometry * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0, bool removeRedundantPoints=false) const =0
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
AxisOrder
Axis order for GML generation.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, Qgis::WkbType baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
QgsAbstractGeometry()=default
QgsGeometryConstPartIterator parts() const
Returns Java-style iterator for traversal of parts of the geometry.
Qgis::WkbType readHeader() const
readHeader
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
bool dropMValue() override
Drops any measure values which exist in the geometry.
Abstract base class for curved geometry type.
void normalize() final
Reorganizes the geometry into a normalized form (or "canonical" form).
static QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType=QString())
Parses a WKT string and returns of list of blocks contained in the WKT.
static QPair< Qgis::WkbType, QString > wktReadBlock(const QString &wkt)
Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents (...
Point geometry type, with support for z-dimension and m-values.
QVector< QgsPolygon * > mPatches
bool isEmpty() const override
Returns true if the geometry is empty.
const QgsPolygon * patchN(int i) const
Retrieves a patch from the polyhedral surface.
QgsPolyhedralSurface & operator=(const QgsPolyhedralSurface &p)
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML3 representation of the geometry.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML3 representation of the geometry.
void clear() override
Clears the geometry, ie reset it to a null geometry.
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
QString asKml(int precision=17) const override
Returns a KML representation of the geometry.
void setTriangles(const QVector< QgsTriangle * > &triangles)
Sets all triangles, transferring ownership to the polyhedral surface.
~QgsTriangulatedSurface() override
void addTriangle(QgsTriangle *triangle)
Adds a triangle to the geometry, transferring ownership to the polyhedral surface.
QgsTriangulatedSurface * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
QgsTriangle * triangleN(int index)
Returns the triangle with the specified index.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
void addPatch(QgsPolygon *patch) override
Adds a patch to the geometry, transferring ownership to the polyhedral surface.
QgsTriangulatedSurface * clone() const override
Clones the geometry by performing a deep copy.
QgsTriangulatedSurface * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0, bool removeRedundantPoints=false) const override
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML2 representation of the geometry.
QString geometryType() const override
Returns a unique string representing the geometry type.
int compareToSameClass(const QgsAbstractGeometry *other) const final
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
void normalize() override
Reorganizes the geometry into a normalized form (or "canonical" form).
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
QgsTriangulatedSurface & operator=(const QgsTriangulatedSurface &p)
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
#define QgsDebugError(str)
Utility class for identifying a unique vertex within a geometry.