1 /***************************************************************************
2                         qgsmultipoint.h
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 #ifndef QGSMULTIPOINT_H
17 #define QGSMULTIPOINT_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgsgeometrycollection.h"
22 
23 /**
24  * \ingroup core
25  * \class QgsMultiPoint
26  * \brief Multi point geometry collection.
27  * \since QGIS 2.10
28  */
29 class CORE_EXPORT QgsMultiPoint: public QgsGeometryCollection
30 {
31   public:
32 
33     /**
34      * Constructor for an empty multipoint geometry.
35      */
36     QgsMultiPoint() SIP_HOLDGIL;
37 
38 #ifndef SIP_RUN
39 
40     /**
41      * Returns the point with the specified \a index.
42      *
43      * \since QGIS 3.16
44      */
45     QgsPoint *pointN( int index );
46 #else
47 
48     /**
49      * Returns the point with the specified \a index.
50      *
51      * \throws IndexError if no point with the specified index exists.
52      *
53      * \since QGIS 3.16
54      */
55     SIP_PYOBJECT pointN( int index ) SIP_TYPEHINT( QgsPoint );
56     % MethodCode
57     if ( a0 < 0 || a0 >= sipCpp->numGeometries() )
58     {
59       PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
60       sipIsErr = 1;
61     }
62     else
63     {
64       return sipConvertFromType( sipCpp->pointN( a0 ), sipType_QgsPoint, NULL );
65     }
66     % End
67 #endif
68 
69 #ifndef SIP_RUN
70 
71     /**
72      * Returns the point with the specified \a index.
73      *
74      * \note Not available in Python bindings
75      *
76      * \since QGIS 3.16
77      */
78     const QgsPoint *pointN( int index ) const;
79 #endif
80 
81     QString geometryType() const override;
82     QgsMultiPoint *clone() const override SIP_FACTORY;
83     QgsMultiPoint *toCurveType() const override SIP_FACTORY;
84     bool fromWkt( const QString &wkt ) override;
85     void clear() override;
86     QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
87     QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
88     json asJsonObject( int precision = 17 ) const override SIP_SKIP;
89     int nCoordinates() const override SIP_HOLDGIL;
90     bool addGeometry( QgsAbstractGeometry *g SIP_TRANSFER ) override;
91     bool insertGeometry( QgsAbstractGeometry *g SIP_TRANSFER, int index ) override;
92     QgsAbstractGeometry *boundary() const override SIP_FACTORY;
93     int vertexNumberFromVertexId( QgsVertexId id ) const override;
94     double segmentLength( QgsVertexId startVertex ) const override;
95     bool isValid( QString &error SIP_OUT, Qgis::GeometryValidityFlags flags = Qgis::GeometryValidityFlags() ) const override SIP_HOLDGIL;
96 
97 #ifndef SIP_RUN
98     void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
99 
100     /**
101      * Cast the \a geom to a QgsLineString.
102      * Should be used by qgsgeometry_cast<QgsLineString *>( geometry ).
103      *
104      * \note Not available in Python. Objects will be automatically be converted to the appropriate target type.
105      * \since QGIS 3.0
106      */
cast(const QgsAbstractGeometry * geom)107     inline static const QgsMultiPoint *cast( const QgsAbstractGeometry *geom )
108     {
109       if ( geom && QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::MultiPoint )
110         return static_cast<const QgsMultiPoint *>( geom );
111       return nullptr;
112     }
113 #endif
114 
115     QgsMultiPoint *createEmptyWithSameType() const override SIP_FACTORY;
116 
117 #ifdef SIP_RUN
118     SIP_PYOBJECT __repr__();
119     % MethodCode
120     QString wkt = sipCpp->asWkt();
121     if ( wkt.length() > 1000 )
122       wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
123     QString str = QStringLiteral( "<QgsMultiPoint: %1>" ).arg( wkt );
124     sipRes = PyUnicode_FromString( str.toUtf8().constData() );
125     % End
126 #endif
127 
128   protected:
129 
130     bool wktOmitChildType() const override;
131 
132 };
133 
134 // clazy:excludeall=qstring-allocations
135 
136 #endif // QGSMULTIPOINT_H
137