1 /*************************************************************************** 2 qgsgeometryfactory.h 3 ----------------------- 4 begin : September 2014 5 copyright : (C) 2014 by Marco Hugentobler 6 email : marco at sourcepole dot ch 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef QGSGEOMETRYFACTORY_H 19 #define QGSGEOMETRYFACTORY_H 20 21 #define SIP_NO_FILE 22 23 #include "qgis_core.h" 24 #include "qgswkbtypes.h" 25 #include <QString> 26 #include <memory> 27 28 class QgsAbstractGeometry; 29 class QgsLineString; 30 class QgsConstWkbPtr; 31 class QgsRectangle; 32 class QgsGeometryCollection; 33 class QgsMultiPoint; 34 class QgsMultiLineString; 35 class QgsPolygon; 36 class QgsMultiPolygon; 37 38 //compatibility with old classes 39 #include "qgspointxy.h" 40 typedef QVector<QgsPointXY> QgsPolylineXY; 41 typedef QVector<QgsPolylineXY> QgsPolygonXY; 42 typedef QVector<QgsPointXY> QgsMultiPointXY; 43 typedef QVector<QgsPolylineXY> QgsMultiPolylineXY; 44 typedef QVector<QgsPolygonXY> QgsMultiPolygonXY; 45 46 /** 47 * \ingroup core 48 * \class QgsGeometryFactory 49 * \brief Contains geometry creation routines. 50 * \note not available in Python bindings 51 * \since QGIS 2.10 52 */ 53 class CORE_EXPORT QgsGeometryFactory 54 { 55 public: 56 57 /** 58 * Construct geometry from a WKB string. 59 * Updates position of the passed WKB pointer. 60 */ 61 static std::unique_ptr< QgsAbstractGeometry > geomFromWkb( QgsConstWkbPtr &wkb ); 62 63 /** 64 * Construct geometry from a WKT string. 65 */ 66 static std::unique_ptr< QgsAbstractGeometry > geomFromWkt( const QString &text ); 67 68 //! Construct geometry from a point 69 static std::unique_ptr< QgsAbstractGeometry > fromPointXY( const QgsPointXY &point ); 70 //! Construct geometry from a multipoint 71 static std::unique_ptr<QgsMultiPoint> fromMultiPointXY( const QgsMultiPointXY &multipoint ); 72 //! Construct geometry from a polyline 73 static std::unique_ptr< QgsAbstractGeometry > fromPolylineXY( const QgsPolylineXY &polyline ); 74 //! Construct geometry from a multipolyline 75 static std::unique_ptr<QgsMultiLineString> fromMultiPolylineXY( const QgsMultiPolylineXY &multiline ); 76 //! Construct geometry from a polygon 77 static std::unique_ptr<QgsPolygon> fromPolygonXY( const QgsPolygonXY &polygon ); 78 //! Construct geometry from a multipolygon 79 static std::unique_ptr<QgsMultiPolygon> fromMultiPolygonXY( const QgsMultiPolygonXY &multipoly ); 80 //! Returns empty geometry from wkb type 81 static std::unique_ptr< QgsAbstractGeometry > geomFromWkbType( QgsWkbTypes::Type t ); 82 83 /** 84 * Returns a new geometry collection matching a specified WKB \a type. For instance, if 85 * type is PolygonM the returned geometry will be a QgsMultiPolygon with M values. 86 */ 87 static std::unique_ptr< QgsGeometryCollection > createCollectionOfType( QgsWkbTypes::Type type ); 88 89 private: 90 static std::unique_ptr< QgsLineString > linestringFromPolyline( const QgsPolylineXY &polyline ); 91 }; 92 93 #endif // QGSGEOMETRYFACTORY_H 94