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