/
qgsmultipointv2.cpp
102 lines (92 loc) · 3.54 KB
/
qgsmultipointv2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/***************************************************************************
qgsmultipointv2.cpp
-------------------------------------------------------------------
Date : 29 Oct 2014
Copyright : (C) 2014 by Marco Hugentobler
email : marco.hugentobler at sourcepole dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsmultipointv2.h"
#include "qgsapplication.h"
#include "qgsgeometryutils.h"
#include "qgspointv2.h"
#include "qgswkbptr.h"
QgsMultiPointV2 *QgsMultiPointV2::clone() const
{
return new QgsMultiPointV2( *this );
}
bool QgsMultiPointV2::fromWkt( const QString& wkt )
{
QString collectionWkt( wkt );
//test for non-standard MultiPoint(x1 y1, x2 y2) format
QRegExp regex( "^\\s*MultiPoint\\s*[ZM]*\\s*\\(\\s*\\d" );
regex.setCaseSensitivity( Qt::CaseInsensitive );
if ( regex.indexIn( collectionWkt ) >= 0 )
{
//alternate style without extra brackets, upgrade to standard
collectionWkt.replace( "(", "((" ).replace( ")", "))" ).replace( ",", "),(" );
}
return fromCollectionWkt( collectionWkt, QList<QgsAbstractGeometryV2*>() << new QgsPointV2, "Point" );
}
QDomElement QgsMultiPointV2::asGML2( QDomDocument& doc, int precision, const QString& ns ) const
{
QDomElement elemMultiPoint = doc.createElementNS( ns, "MultiPoint" );
Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
{
if ( dynamic_cast<const QgsPointV2*>( geom ) )
{
QDomElement elemPointMember = doc.createElementNS( ns, "pointMember" );
elemPointMember.appendChild( geom->asGML2( doc, precision, ns ) );
elemMultiPoint.appendChild( elemPointMember );
}
}
return elemMultiPoint;
}
QDomElement QgsMultiPointV2::asGML3( QDomDocument& doc, int precision, const QString& ns ) const
{
QDomElement elemMultiPoint = doc.createElementNS( ns, "MultiPoint" );
Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
{
if ( dynamic_cast<const QgsPointV2*>( geom ) )
{
QDomElement elemPointMember = doc.createElementNS( ns, "pointMember" );
elemPointMember.appendChild( geom->asGML3( doc, precision, ns ) );
elemMultiPoint.appendChild( elemPointMember );
}
}
return elemMultiPoint;
}
QString QgsMultiPointV2::asJSON( int precision ) const
{
QString json = "{\"type\": \"MultiPoint\", \"coordinates\": [";
Q_FOREACH ( const QgsAbstractGeometryV2 *geom, mGeometries )
{
if ( dynamic_cast<const QgsPointV2*>( geom ) )
{
const QgsPointV2* point = static_cast<const QgsPointV2*>( geom );
json += QgsGeometryUtils::pointsToJSON( QList<QgsPointV2>() << *point, precision ) + ", ";
}
}
if ( json.endsWith( ", " ) )
{
json.chop( 2 ); // Remove last ", "
}
json += "] }";
return json;
}
bool QgsMultiPointV2::addGeometry( QgsAbstractGeometryV2* g )
{
if ( !dynamic_cast<QgsPointV2*>( g ) )
{
delete g;
return false;
}
setZMTypeFromSubGeometry( g, QgsWKBTypes::MultiPoint );
return QgsGeometryCollectionV2::addGeometry( g );
}