QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
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 
24 {
26 }
27 
29 {
30  return new QgsMultiPointV2( *this );
31 }
32 
34 {
35  QString collectionWkt( wkt );
36  //test for non-standard MultiPoint(x1 y1, x2 y2) format
37  QRegExp regex( "^\\s*MultiPoint\\s*[ZM]*\\s*\\(\\s*\\d" );
38  regex.setCaseSensitivity( Qt::CaseInsensitive );
39  if ( regex.indexIn( collectionWkt ) >= 0 )
40  {
41  //alternate style without extra brackets, upgrade to standard
42  collectionWkt.replace( '(', "((" ).replace( ')', "))" ).replace( ',', "),(" );
43  }
44 
45  return fromCollectionWkt( collectionWkt, QList<QgsAbstractGeometryV2*>() << new QgsPointV2, "Point" );
46 }
47 
48 QDomElement QgsMultiPointV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const
49 {
50  QDomElement elemMultiPoint = doc.createElementNS( ns, "MultiPoint" );
51  Q_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->asGML2( doc, precision, ns ) );
57  elemMultiPoint.appendChild( elemPointMember );
58  }
59  }
60 
61  return elemMultiPoint;
62 }
63 
64 QDomElement QgsMultiPointV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
65 {
66  QDomElement elemMultiPoint = doc.createElementNS( ns, "MultiPoint" );
67  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
68  {
69  if ( dynamic_cast<const QgsPointV2*>( geom ) )
70  {
71  QDomElement elemPointMember = doc.createElementNS( ns, "pointMember" );
72  elemPointMember.appendChild( geom->asGML3( doc, precision, ns ) );
73  elemMultiPoint.appendChild( elemPointMember );
74  }
75  }
76 
77  return elemMultiPoint;
78 }
79 
80 QString QgsMultiPointV2::asJSON( int precision ) const
81 {
82  QString json = "{\"type\": \"MultiPoint\", \"coordinates\": ";
83 
85  Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
86  {
87  if ( dynamic_cast<const QgsPointV2*>( geom ) )
88  {
89  const QgsPointV2* point = static_cast<const QgsPointV2*>( geom );
90  pts << *point;
91  }
92  }
93  json += QgsGeometryUtils::pointsToJSON( pts, precision );
94  json += " }";
95  return json;
96 }
97 
99 {
100  if ( !dynamic_cast<QgsPointV2*>( g ) )
101  {
102  delete g;
103  return false;
104  }
107 }
108 
110 {
111  return nullptr;
112 }
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 QgsPointSequenceV2 &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)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
virtual QgsAbstractGeometryV2 * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
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.
void setCaseSensitivity(Qt::CaseSensitivity cs)
QVector< QgsAbstractGeometryV2 * > mGeometries
QString & replace(int position, int n, QChar after)
QgsMultiPointV2 * clone() const override
Clones the geometry by performing a deep copy.
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.