QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmultipointv2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmultipointv2.cpp
3  -------------------------------------------------------------------
4 Date : 29 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 "qgsmultipointv2.h"
17 #include "qgsapplication.h"
18 #include "qgsgeometryutils.h"
19 #include "qgspointv2.h"
20 #include "qgswkbptr.h"
21 
23 {
24  return new QgsMultiPointV2( *this );
25 }
26 
28 {
29  return fromCollectionWkt( wkt, QList<QgsAbstractGeometryV2*>() << new QgsPointV2, "Point" );
30 }
31 
32 QDomElement QgsMultiPointV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const
33 {
34  QDomElement elemMultiPoint = doc.createElementNS( ns, "MultiPoint" );
35  foreach ( const QgsAbstractGeometryV2 *geom, mGeometries )
36  {
37  if ( dynamic_cast<const QgsPointV2*>( geom ) )
38  {
39  QDomElement elemPointMember = doc.createElementNS( ns, "pointMember" );
40  elemPointMember.appendChild( geom->asGML2( doc, precision, ns ) );
41  elemMultiPoint.appendChild( elemPointMember );
42  }
43  }
44 
45  return elemMultiPoint;
46 }
47 
48 QDomElement QgsMultiPointV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
49 {
50  QDomElement elemMultiPoint = doc.createElementNS( ns, "MultiPoint" );
51  foreach ( const QgsAbstractGeometryV2 *geom, mGeometries )
52  {
53  if ( dynamic_cast<const QgsPointV2*>( geom ) )
54  {
55  QDomElement elemPointMember = doc.createElementNS( ns, "pointMember" );
56  elemPointMember.appendChild( geom->asGML3( doc, precision, ns ) );
57  elemMultiPoint.appendChild( elemPointMember );
58  }
59  }
60 
61  return elemMultiPoint;
62 }
63 
64 QString QgsMultiPointV2::asJSON( int precision ) const
65 {
66  QString json = "{\"type\": \"MultiPoint\", \"coordinates\": [";
67  foreach ( const QgsAbstractGeometryV2 *geom, mGeometries )
68  {
69  if ( dynamic_cast<const QgsPointV2*>( geom ) )
70  {
71  const QgsPointV2* point = static_cast<const QgsPointV2*>( geom );
72  json += QgsGeometryUtils::pointsToJSON( QList<QgsPointV2>() << *point, precision ) + ", ";
73  }
74  }
75  if ( json.endsWith( ", " ) )
76  {
77  json.chop( 2 ); // Remove last ", "
78  }
79  json += "] }";
80  return json;
81 }
82 
84 {
85  if ( !dynamic_cast<QgsPointV2*>( g ) )
86  {
87  delete g;
88  return false;
89  }
92 }
virtual bool addGeometry(QgsAbstractGeometryV2 *g) override
Adds a geometry and takes ownership.
QDomNode appendChild(const QDomNode &newChild)
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.
Multi point geometry collection.
QDomElement createElementNS(const QString &nsURI, const QString &qName)
void chop(int n)
QgsAbstractGeometryV2 * clone() const override
Clones the geometry by performing a deep copy.
Point geometry type.
Definition: qgspointv2.h:29
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
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.
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.
virtual QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const =0
Returns a GML2 representation of the geometry.
QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
QString asJSON(int precision=17) const override
Returns a GeoJSON representation of the geometry.