26#include <nlohmann/json.hpp>
40 auto result = std::make_unique< QgsTriangulatedSurface >();
42 return result.release();
47 return QStringLiteral(
"TIN" );
99 std::unique_ptr< QgsTriangle > currentTriangle;
100 for (
int i = 0; i < nTriangles; ++i )
103 wkbPtr -= 1 +
sizeof( int );
113 currentTriangle->fromWkb( wkbPtr );
114 mPatches.append( currentTriangle.release() );
131 QString secondWithoutParentheses =
parts.second;
132 secondWithoutParentheses = secondWithoutParentheses.remove(
'(' ).remove(
')' ).simplified().remove(
' ' );
133 if ( (
parts.second.compare( QLatin1String(
"EMPTY" ), Qt::CaseInsensitive ) == 0 ) ||
134 secondWithoutParentheses.isEmpty() )
137 QString defaultChildWkbType = QStringLiteral(
"Triangle%1%2" ).arg(
is3D() ? QStringLiteral(
"Z" ) : QString(),
isMeasure() ? QStringLiteral(
"M" ) : QString() );
140 for (
const QString &childWkt : blocks )
154 if ( !
mPatches.back()->fromWkt( childWkt ) )
166 QgsDebugError( QStringLiteral(
"gml version 2 does not support TIN geometry" ) );
167 return QDomElement();
172 QDomElement elemTriangulatedSurface = doc.createElementNS( ns, QStringLiteral(
"TriangulatedSurface" ) );
175 return elemTriangulatedSurface;
177 QDomElement elemPatches = doc.createElementNS( ns, QStringLiteral(
"patches" ) );
180 QgsTriangle *triangle = qgsgeometry_cast<QgsTriangle *>( patch );
184 QDomElement elemTriangle = triangle->
asGml3( doc,
precision, ns, axisOrder );
185 elemPatches.appendChild( elemTriangle );
187 elemTriangulatedSurface.appendChild( elemPatches );
189 return elemTriangulatedSurface;
194 QgsDebugError( QStringLiteral(
"kml format does not support TIN geometry" ) );
195 return QString(
"" );
202 QgsTriangle *triangle = qgsgeometry_cast<QgsTriangle *>( patch );
220 QgsTriangle *triangle = qgsgeometry_cast<QgsTriangle *>( patch );
224 std::unique_ptr<QgsCurve> exteriorRing( qgsgeometry_cast< QgsCurve *>( triangle->
exteriorRing()->
snappedToGrid( hSpacing, vSpacing, dSpacing, mSpacing, removeRedundantPoints ) ) );
230 std::unique_ptr<QgsTriangle> gridifiedTriangle = std::make_unique<QgsTriangle>();
231 gridifiedTriangle->setExteriorRing( exteriorRing.release() );
232 surface->addPatch( gridifiedTriangle.release() );
235 return surface.release();
253 QgsTriangle *triangle = qgsgeometry_cast<QgsTriangle *>( patch );
271 else if ( !triangle->
is3D() )
290 return qgsgeometry_cast< QgsTriangle * >(
patchN( index ) );
295 return qgsgeometry_cast< const QgsTriangle * >(
patchN( index ) );
313 const QgsTriangulatedSurface *otherTriangulatedSurface = qgsgeometry_cast<const QgsTriangulatedSurface *>( other );
314 if ( !otherTriangulatedSurface )
317 const int nTriangles1 =
mPatches.size();
318 const int nTriangles2 = otherTriangulatedSurface->
mPatches.size();
319 if ( nTriangles1 < nTriangles2 )
323 if ( nTriangles1 > nTriangles2 )
328 for (
int i = 0; i < nTriangles1; i++ )
330 const int triangleComp =
mPatches.at( i )->compareTo( otherTriangulatedSurface->
mPatches.at( i ) );
331 if ( triangleComp != 0 )
WkbType
The WKB type describes the number of dimensions a geometry has.
Abstract base class for all geometries.
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.
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.
Polyhedral surface geometry type.
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.
Triangulated surface geometry type.
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.
#define QgsDebugError(str)
Utility class for identifying a unique vertex within a geometry.