21#include <nlohmann/json.hpp>
41 auto result = std::make_unique< QgsTriangulatedSurface >();
43 return result.release();
48 return QStringLiteral(
"TIN" );
100 std::unique_ptr< QgsTriangle > currentTriangle;
101 for (
int i = 0; i < nTriangles; ++i )
104 wkbPtr -= 1 +
sizeof( int );
108 currentTriangle = std::make_unique<QgsTriangle>( );
114 currentTriangle->fromWkb( wkbPtr );
115 mPatches.append( currentTriangle.release() );
132 QString secondWithoutParentheses =
parts.second;
133 secondWithoutParentheses = secondWithoutParentheses.remove(
'(' ).remove(
')' ).simplified().remove(
' ' );
134 if ( (
parts.second.compare( QLatin1String(
"EMPTY" ), Qt::CaseInsensitive ) == 0 ) ||
135 secondWithoutParentheses.isEmpty() )
138 QString defaultChildWkbType = QStringLiteral(
"Triangle%1%2" ).arg(
is3D() ? QStringLiteral(
"Z" ) : QString(),
isMeasure() ? QStringLiteral(
"M" ) : QString() );
141 for (
const QString &childWkt : blocks )
155 if ( !
mPatches.back()->fromWkt( childWkt ) )
167 QgsDebugError( QStringLiteral(
"gml version 2 does not support TIN geometry" ) );
168 return QDomElement();
173 QDomElement elemTriangulatedSurface = doc.createElementNS( ns, QStringLiteral(
"TriangulatedSurface" ) );
176 return elemTriangulatedSurface;
178 QDomElement elemPatches = doc.createElementNS( ns, QStringLiteral(
"patches" ) );
185 QDomElement elemTriangle = triangle->
asGml3( doc, precision, ns, axisOrder );
186 elemPatches.appendChild( elemTriangle );
188 elemTriangulatedSurface.appendChild( elemPatches );
190 return elemTriangulatedSurface;
195 QgsDebugError( QStringLiteral(
"kml format does not support TIN geometry" ) );
196 return QString(
"" );
231 auto gridifiedTriangle = std::make_unique<QgsTriangle>();
232 gridifiedTriangle->setExteriorRing( exteriorRing.release() );
233 surface->addPatch( gridifiedTriangle.release() );
236 return surface.release();
272 else if ( !triangle->
is3D() )
315 if ( !otherTriangulatedSurface )
318 const int nTriangles1 =
mPatches.size();
319 const int nTriangles2 = otherTriangulatedSurface->
mPatches.size();
320 if ( nTriangles1 < nTriangles2 )
324 if ( nTriangles1 > nTriangles2 )
329 for (
int i = 0; i < nTriangles1; i++ )
331 const int triangleComp =
mPatches.at( i )->compareTo( otherTriangulatedSurface->
mPatches.at( i ) );
332 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.