QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
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  delete lineString;
55  }
56  }
57 
58  return elemMultiLineString;
59 }
60 
61 QDomElement QgsMultiLineStringV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
62 {
63  QDomElement elemMultiCurve = doc.createElementNS( ns, "MultiLineString" );
64  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
65  {
66  if ( dynamic_cast<const QgsLineStringV2*>( geom ) )
67  {
68  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
69 
70  QDomElement elemCurveMember = doc.createElementNS( ns, "curveMember" );
71  elemCurveMember.appendChild( lineString->asGML3( doc, precision, ns ) );
72  elemMultiCurve.appendChild( elemCurveMember );
73  }
74  }
75 
76  return elemMultiCurve;
77 }
78 
79 QString QgsMultiLineStringV2::asJSON( int precision ) const
80 {
81  QString json = "{\"type\": \"MultiLineString\", \"coordinates\": [";
82  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
83  {
84  if ( dynamic_cast<const QgsCurveV2*>( geom ) )
85  {
86  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
88  lineString->points( pts );
89  json += QgsGeometryUtils::pointsToJSON( pts, precision ) + ", ";
90  }
91  }
92  if ( json.endsWith( ", " ) )
93  {
94  json.chop( 2 ); // Remove last ", "
95  }
96  json += "] }";
97  return json;
98 }
99 
101 {
102  if ( !dynamic_cast<QgsLineStringV2*>( g ) )
103  {
104  delete g;
105  return false;
106  }
107 
110 }
111 
113 {
114  QgsMultiCurveV2* multiCurve = new QgsMultiCurveV2();
115  for ( int i = 0; i < mGeometries.size(); ++i )
116  {
117  multiCurve->addGeometry( mGeometries.at( i )->clone() );
118  }
119  return multiCurve;
120 }
121 
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.
bool fromCollectionWkt(const QString &wkt, const QList< QgsAbstractGeometryV2 * > &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
QVector< QgsAbstractGeometryV2 * > mGeometries
const T & at(int i) const
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