QGIS API Documentation  2.14.11-Essen
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 {
27  return new QgsMultiLineStringV2( *this );
28 }
29 
31 {
32  return fromCollectionWkt( wkt, QList<QgsAbstractGeometryV2*>() << new QgsLineStringV2, "LineString" );
33 }
34 
35 QDomElement QgsMultiLineStringV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const
36 {
37  QDomElement elemMultiLineString = doc.createElementNS( ns, "MultiLineString" );
38  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
39  {
40  if ( dynamic_cast<const QgsLineStringV2*>( geom ) )
41  {
42  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
43 
44  QDomElement elemLineStringMember = doc.createElementNS( ns, "lineStringMember" );
45  elemLineStringMember.appendChild( lineString->asGML2( doc, precision, ns ) );
46  elemMultiLineString.appendChild( elemLineStringMember );
47 
48  delete lineString;
49  }
50  }
51 
52  return elemMultiLineString;
53 }
54 
55 QDomElement QgsMultiLineStringV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
56 {
57  QDomElement elemMultiCurve = doc.createElementNS( ns, "MultiLineString" );
58  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
59  {
60  if ( dynamic_cast<const QgsLineStringV2*>( geom ) )
61  {
62  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
63 
64  QDomElement elemCurveMember = doc.createElementNS( ns, "curveMember" );
65  elemCurveMember.appendChild( lineString->asGML3( doc, precision, ns ) );
66  elemMultiCurve.appendChild( elemCurveMember );
67  }
68  }
69 
70  return elemMultiCurve;
71 }
72 
73 QString QgsMultiLineStringV2::asJSON( int precision ) const
74 {
75  QString json = "{\"type\": \"MultiLineString\", \"coordinates\": [";
76  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
77  {
78  if ( dynamic_cast<const QgsCurveV2*>( geom ) )
79  {
80  const QgsLineStringV2* lineString = static_cast<const QgsLineStringV2*>( geom );
82  lineString->points( pts );
83  json += QgsGeometryUtils::pointsToJSON( pts, precision ) + ", ";
84  }
85  }
86  if ( json.endsWith( ", " ) )
87  {
88  json.chop( 2 ); // Remove last ", "
89  }
90  json += "] }";
91  return json;
92 }
93 
95 {
96  if ( !dynamic_cast<QgsLineStringV2*>( g ) )
97  {
98  delete g;
99  return false;
100  }
101 
104 }
105 
107 {
108  QgsMultiCurveV2* multiCurve = new QgsMultiCurveV2();
109  for ( int i = 0; i < mGeometries.size(); ++i )
110  {
111  multiCurve->addGeometry( mGeometries.at( i )->clone() );
112  }
113  return multiCurve;
114 }
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 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