18#include <nlohmann/json.hpp>
35 if ( linestrings.empty() )
49 if ( linestrings.empty() )
73 return QStringLiteral(
"MultiLineString" );
78 auto result = std::make_unique< QgsMultiLineString >();
80 return result.release();
101 QDomElement elemMultiLineString = doc.createElementNS( ns, QStringLiteral(
"MultiLineString" ) );
104 return elemMultiLineString;
110 QDomElement elemLineStringMember = doc.createElementNS( ns, QStringLiteral(
"lineStringMember" ) );
111 elemLineStringMember.appendChild( lineString->asGml2( doc, precision, ns, axisOrder ) );
112 elemMultiLineString.appendChild( elemLineStringMember );
116 return elemMultiLineString;
121 QDomElement elemMultiCurve = doc.createElementNS( ns, QStringLiteral(
"MultiCurve" ) );
124 return elemMultiCurve;
130 QDomElement elemCurveMember = doc.createElementNS( ns, QStringLiteral(
"curveMember" ) );
131 elemCurveMember.appendChild( lineString->asGml3( doc, precision, ns, axisOrder ) );
132 elemMultiCurve.appendChild( elemCurveMember );
136 return elemMultiCurve;
141 json coordinates( json::array( ) );
148 lineString->
points( pts );
154 {
"type",
"MultiLineString" },
155 {
"coordinates", coordinates }
188 qDeleteAll( geometries );
200 if (
is3D() && !g->is3D() )
202 else if ( !
is3D() && g->is3D() )
206 else if ( !
isMeasure() && g->isMeasure() )
228 auto result = std::make_unique< QgsMultiLineString >();
232 result->addGeometry(
mGeometries.at( i )->simplifyByDistance( tolerance ) );
234 return result.release();
255 auto result = std::make_unique< QgsMultiLineString >();
259 return result.release();
264 const double range{end - start};
265 double lengthSoFar{0.0};
272 const double subStart{ ( start + range *lengthSoFar /
length ) };
273 const double subEnd{ ( start + range * ( lengthSoFar + subLength ) /
length ) };
278 lengthSoFar += subLength;
281 return result.release();
@ MultiLineString
MultiLineString.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
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.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
void setZMTypeFromSubGeometry(const QgsAbstractGeometry *subggeom, Qgis::WkbType baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
virtual double length() const
Returns the planar, 2-dimensional length of the geometry.
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
QgsAbstractGeometry()=default
QVector< QgsAbstractGeometry * > mGeometries
bool fromCollectionWkt(const QString &wkt, const QVector< Qgis::WkbType > &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
void reserve(int size)
Attempts to allocate memory for at least size geometries.
void clearCache() const override
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
bool isEmpty() const override
Returns true if the geometry is empty.
double length() const override
Returns the planar, 2-dimensional length of the geometry.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
static json pointsToJson(const QgsPointSequence &points, int precision)
Returns coordinates as json object.
Line string geometry type, with support for z-dimension and m-values.
void points(QgsPointSequence &pt) const override
Returns a list of points within the curve.
bool insertGeometry(QgsAbstractGeometry *g, int index) override
Inserts a geometry before a specified index and takes ownership.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
void clear() override
Clears the geometry, ie reset it to a null geometry.
void clear() override
Clears the geometry, ie reset it to a null geometry.
QString geometryType() const override
Returns a unique string representing the geometry type.
bool addGeometries(const QVector< QgsAbstractGeometry * > &geometries) final
Adds a list of geometries to the collection, transferring ownership to the collection.
QgsMultiCurve * toCurveType() const override
Returns the geometry converted to the more generic curve type QgsMultiCurve.
bool wktOmitChildType() const override
Returns whether child type names are omitted from Wkt representations of the collection.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
bool insertGeometry(QgsAbstractGeometry *g, int index) override
Inserts a geometry before a specified index and takes ownership.
json asJsonObject(int precision=17) const override
Returns a json object representation of the geometry.
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.
QgsMultiLineString * measuredLine(double start, double end) const
Re-write the measure ordinate (or add one, if it isn't already there) interpolating the measure betwe...
QgsMultiLineString * clone() const override
Clones the geometry by performing a deep copy.
QgsMultiLineString * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
QgsMultiLineString()
Constructor for an empty multilinestring geometry.
bool addGeometry(QgsAbstractGeometry *g) override
Adds a geometry and takes ownership. Returns true in case of success.
QgsMultiLineString * simplifyByDistance(double tolerance) const override
Simplifies the geometry by applying the Douglas Peucker simplification by distance algorithm.
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.
QgsLineString * lineStringN(int index)
Returns the line string with the specified index.
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QVector< QgsPoint > QgsPointSequence