QGIS API Documentation  2.12.0-Lyon
qgsmulticurvev2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmulticurvev2.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 "qgsmulticurvev2.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 QgsMultiCurveV2( *this );
27 }
28 
30 {
31  return fromCollectionWkt( wkt,
33  "LineString" );
34 }
35 
36 QDomElement QgsMultiCurveV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const
37 {
38  // GML2 does not support curves
39  QDomElement elemMultiLineString = doc.createElementNS( ns, "MultiLineString" );
40  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
41  {
42  if ( dynamic_cast<const QgsCurveV2*>( geom ) )
43  {
44  QgsLineStringV2* lineString = static_cast<const QgsCurveV2*>( geom )->curveToLine();
45 
46  QDomElement elemLineStringMember = doc.createElementNS( ns, "lineStringMember" );
47  elemLineStringMember.appendChild( lineString->asGML2( doc, precision, ns ) );
48  elemMultiLineString.appendChild( elemLineStringMember );
49 
50  delete lineString;
51  }
52  }
53 
54  return elemMultiLineString;
55 }
56 
57 QDomElement QgsMultiCurveV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
58 {
59  QDomElement elemMultiCurve = doc.createElementNS( ns, "MultiCurve" );
60  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
61  {
62  if ( dynamic_cast<const QgsCurveV2*>( geom ) )
63  {
64  const QgsCurveV2* curve = static_cast<const QgsCurveV2*>( geom );
65 
66  QDomElement elemCurveMember = doc.createElementNS( ns, "curveMember" );
67  elemCurveMember.appendChild( curve->asGML3( doc, precision, ns ) );
68  elemMultiCurve.appendChild( elemCurveMember );
69  }
70  }
71 
72  return elemMultiCurve;
73 }
74 
75 QString QgsMultiCurveV2::asJSON( int precision ) const
76 {
77  // GeoJSON does not support curves
78  QString json = "{\"type\": \"MultiLineString\", \"coordinates\": [";
79  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
80  {
81  if ( dynamic_cast<const QgsCurveV2*>( geom ) )
82  {
83  QgsLineStringV2* lineString = static_cast<const QgsCurveV2*>( geom )->curveToLine();
85  lineString->points( pts );
86  json += QgsGeometryUtils::pointsToJSON( pts, precision ) + ", ";
87  delete lineString;
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<QgsCurveV2*>( g ) )
101  {
102  delete g;
103  return false;
104  }
105 
108 }
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
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)
void points(QList< QgsPointV2 > &pt) const override
Returns a list of points within the curve.
Circular string geometry type.
Multi curve geometry collection.
static QString pointsToJSON(const QList< QgsPointV2 > &points, int precision)
Returns a geoJSON coordinates string.
QgsMultiCurveV2 * clone() const override
Clones the geometry by performing a deep copy.
Abstract base class for all geometries.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
QDomElement createElementNS(const QString &nsURI, const QString &qName)
void chop(int n)
Line string geometry type.
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.
virtual QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const =0
Returns a GML3 representation of the geometry.
Compound curve geometry type.
bool fromCollectionWkt(const QString &wkt, const QList< QgsAbstractGeometryV2 * > &subtypes, const QString &defaultChildWkbType=QString())
Reads a collection from a WKT string.
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.
QVector< QgsAbstractGeometryV2 * > mGeometries
virtual bool addGeometry(QgsAbstractGeometryV2 *g)
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.
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32