QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsmultilinestringv2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmultilinestringv2.cpp
3  -------------------------------------------------------------------
4 Date : 28 Oct 2014
5 Copyright : (C) 2014 by Marco Hugentobler
6 email : marco.hugentobler at sourcepole dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsmultilinestringv2.h"
17 #include "qgsapplication.h"
18 #include "qgscurvev2.h"
19 #include "qgscircularstringv2.h"
20 #include "qgscompoundcurvev2.h"
21 #include "qgsgeometryutils.h"
22 #include "qgslinestringv2.h"
23 #include "qgsmulticurvev2.h"
24 
26  : QgsMultiCurveV2()
27 {
29 }
30 
32 {
33  return new QgsMultiLineStringV2( *this );
34 }
35 
37 {
38  return fromCollectionWkt( wkt, QList<QgsAbstractGeometryV2*>() << new QgsLineStringV2, "LineString" );
39 }
40 
41 QDomElement QgsMultiLineStringV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const
42 {
43  QDomElement elemMultiLineString = doc.createElementNS( ns, "MultiLineString" );
44  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
45  {
46  if ( dynamic_cast<const QgsLineStringV2*>( geom ) )
47  {
48  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
49 
50  QDomElement elemLineStringMember = doc.createElementNS( ns, "lineStringMember" );
51  elemLineStringMember.appendChild( lineString->asGML2( doc, precision, ns ) );
52  elemMultiLineString.appendChild( elemLineStringMember );
53  }
54  }
55 
56  return elemMultiLineString;
57 }
58 
59 QDomElement QgsMultiLineStringV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
60 {
61  QDomElement elemMultiCurve = doc.createElementNS( ns, "MultiCurve" );
62  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
63  {
64  if ( dynamic_cast<const QgsLineStringV2*>( geom ) )
65  {
66  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
67 
68  QDomElement elemCurveMember = doc.createElementNS( ns, "curveMember" );
69  elemCurveMember.appendChild( lineString->asGML3( doc, precision, ns ) );
70  elemMultiCurve.appendChild( elemCurveMember );
71  }
72  }
73 
74  return elemMultiCurve;
75 }
76 
77 QString QgsMultiLineStringV2::asJSON( int precision ) const
78 {
79  QString json = "{\"type\": \"MultiLineString\", \"coordinates\": [";
80  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
81  {
82  if ( dynamic_cast<const QgsCurveV2*>( geom ) )
83  {
84  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
86  lineString->points( pts );
87  json += QgsGeometryUtils::pointsToJSON( pts, precision ) + ", ";
88  }
89  }
90  if ( json.endsWith( ", " ) )
91  {
92  json.chop( 2 ); // Remove last ", "
93  }
94  json += "] }";
95  return json;
96 }
97 
99 {
100  if ( !dynamic_cast<QgsLineStringV2*>( g ) )
101  {
102  delete g;
103  return false;
104  }
105 
108 }
109 
111 {
112  QgsMultiCurveV2* multiCurve = new QgsMultiCurveV2();
113  for ( int i = 0; i < mGeometries.size(); ++i )
114  {
115  multiCurve->addGeometry( mGeometries.at( i )->clone() );
116  }
117  return multiCurve;
118 }
119 
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
QDomNode appendChild(const QDomNode &newChild)
QgsMultiLineStringV2 * clone() const override
Clones the geometry by performing a deep copy.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
void points(QgsPointSequenceV2 &pt) const override
Returns a list of points within the curve.
virtual bool addGeometry(QgsAbstractGeometryV2 *g) override
Adds a geometry and takes ownership.
Multi curve geometry collection.
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
static QString pointsToJSON(const QgsPointSequenceV2 &points, int precision)
Returns a geoJSON coordinates string.
Abstract base class for all geometries.
QgsAbstractGeometryV2 * toCurveType() const override
Returns the geometry converted to the more generic curve type QgsMultiCurveV2.
QDomElement createElementNS(const QString &nsURI, const QString &qName)
void chop(int n)
Multi line string geometry collection.
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
Line string geometry type, with support for z-dimension and m-values.
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
virtual bool addGeometry(QgsAbstractGeometryV2 *g) override
Adds a geometry and takes ownership.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
void setZMTypeFromSubGeometry(const QgsAbstractGeometryV2 *subggeom, QgsWKBTypes::Type baseGeomType)
Updates the geometry type based on whether sub geometries contain z or m values.
QVector< QgsAbstractGeometryV2 *> mGeometries
const T & at(int i) const
bool fromCollectionWkt(const QString &wkt, const QList< QgsAbstractGeometryV2 *> &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
virtual bool addGeometry(QgsAbstractGeometryV2 *g)
Adds a geometry and takes ownership.
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.
int size() const