QGIS API Documentation  2.12.0-Lyon
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 
25 {
26  return new QgsMultiLineStringV2( *this );
27 }
28 
30 {
31  return fromCollectionWkt( wkt, QList<QgsAbstractGeometryV2*>() << new QgsLineStringV2, "LineString" );
32 }
33 
34 QDomElement QgsMultiLineStringV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const
35 {
36  QDomElement elemMultiLineString = doc.createElementNS( ns, "MultiLineString" );
37  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
38  {
39  if ( dynamic_cast<const QgsLineStringV2*>( geom ) )
40  {
41  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
42 
43  QDomElement elemLineStringMember = doc.createElementNS( ns, "lineStringMember" );
44  elemLineStringMember.appendChild( lineString->asGML2( doc, precision, ns ) );
45  elemMultiLineString.appendChild( elemLineStringMember );
46 
47  delete lineString;
48  }
49  }
50 
51  return elemMultiLineString;
52 }
53 
54 QDomElement QgsMultiLineStringV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
55 {
56  QDomElement elemMultiCurve = doc.createElementNS( ns, "MultiLineString" );
57  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
58  {
59  if ( dynamic_cast<const QgsLineStringV2*>( geom ) )
60  {
61  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
62 
63  QDomElement elemCurveMember = doc.createElementNS( ns, "curveMember" );
64  elemCurveMember.appendChild( lineString->asGML3( doc, precision, ns ) );
65  elemMultiCurve.appendChild( elemCurveMember );
66  }
67  }
68 
69  return elemMultiCurve;
70 }
71 
72 QString QgsMultiLineStringV2::asJSON( int precision ) const
73 {
74  QString json = "{\"type\": \"MultiLineString\", \"coordinates\": [";
75  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
76  {
77  if ( dynamic_cast<const QgsCurveV2*>( geom ) )
78  {
79  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
81  lineString->points( pts );
82  json += QgsGeometryUtils::pointsToJSON( pts, precision ) + ", ";
83  }
84  }
85  if ( json.endsWith( ", " ) )
86  {
87  json.chop( 2 ); // Remove last ", "
88  }
89  json += "] }";
90  return json;
91 }
92 
94 {
95  if ( !dynamic_cast<QgsLineStringV2*>( g ) )
96  {
97  delete g;
98  return false;
99  }
100 
103 }
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(QList< QgsPointV2 > &pt) const override
Returns a list of points within the curve.
virtual bool addGeometry(QgsAbstractGeometryV2 *g) override
Adds a geometry and takes ownership.
QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
static QString pointsToJSON(const QList< QgsPointV2 > &points, int precision)
Returns a geoJSON coordinates string.
Abstract base class for all geometries.
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.
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
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
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.