QGIS API Documentation  2.99.0-Master (6a61179)
qgsgeometryanalyzer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometryanalyzer.h - QGIS Tools for vector geometry analysis
3  -------------------
4  begin : 19 March 2009
5  copyright : (C) Carson Farmer
6  email : [email protected]
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 QGSGEOMETRYANALYZERH
19 #define QGSGEOMETRYANALYZERH
20 
21 #include "qgsfeature.h"
22 #include "qgsgeometry.h"
23 
25 class QProgressDialog;
27 class QgsDistanceArea;
28 
33 class ANALYSIS_EXPORT QgsGeometryAnalyzer
34 {
35  public:
36 
45  bool simplify( QgsVectorLayer* layer, const QString& shapefileName, double tolerance,
46  bool onlySelectedFeatures = false, QProgressDialog* p = nullptr );
47 
55  bool centroids( QgsVectorLayer* layer, const QString& shapefileName,
56  bool onlySelectedFeatures = false, QProgressDialog* p = nullptr );
57 
64  bool extent( QgsVectorLayer* layer, const QString& shapefileName, bool onlySelectedFeatures = false, QProgressDialog* p = 0 );
65 
75  bool buffer( QgsVectorLayer* layer, const QString& shapefileName, double bufferDistance,
76  bool onlySelectedFeatures = false, bool dissolve = false, int bufferDistanceField = -1, QProgressDialog* p = nullptr );
77 
86  bool convexHull( QgsVectorLayer* layer, const QString& shapefileName, bool onlySelectedFeatures = false,
87  int uniqueIdField = -1, QProgressDialog* p = nullptr );
88 
97  bool dissolve( QgsVectorLayer* layer, const QString& shapefileName, bool onlySelectedFeatures = false,
98  int uniqueIdField = -1, QProgressDialog* p = nullptr );
99 
117  bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, QgsFeatureIds &unlocatedFeatureIds, const QString& outputLayer,
118  const QString& outputFormat, int locationField1, int locationField2 = -1, int offsetField = -1, double offsetScale = 1.0,
119  bool forceSingleGeometry = false, QgsVectorDataProvider* memoryProvider = nullptr, QProgressDialog* p = nullptr );
120 
122  QgsGeometry locateBetweenMeasures( double fromMeasure, double toMeasure, const QgsGeometry& lineGeom );
123 
127  QgsGeometry locateAlongMeasure( double measure, const QgsGeometry& lineGeom );
128 
129  private:
130 
131  QList<double> simpleMeasure( QgsGeometry& geometry );
132  double perimeterMeasure( const QgsGeometry& geometry, QgsDistanceArea& measure );
134  void simplifyFeature( QgsFeature& f, QgsVectorFileWriter* vfw, double tolerance );
136  void centroidFeature( QgsFeature& f, QgsVectorFileWriter* vfw );
138  void bufferFeature( QgsFeature& f, int nProcessedFeatures, QgsVectorFileWriter* vfw, bool dissolve, QgsGeometry& dissolveGeometry,
139  double bufferDistance, int bufferDistanceField );
141  void convexFeature( QgsFeature& f, int nProcessedFeatures, QgsGeometry& dissolveGeometry );
143  QgsGeometry dissolveFeature( const QgsFeature& f, const QgsGeometry& dissolveInto );
144 
145  //helper functions for event layer
146  void addEventLayerFeature( QgsFeature& feature, const QgsGeometry& geom, const QgsGeometry& lineGeom, QgsVectorFileWriter* fileWriter, QgsFeatureList& memoryFeatures, int offsetField = -1, double offsetScale = 1.0,
147  bool forceSingleType = false );
148 
153  QgsGeometry createOffsetGeometry( const QgsGeometry& geom, const QgsGeometry& lineGeom, double offset );
154  QgsPoint createPointOffset( double x, double y, double dist, const QgsGeometry& lineGeom ) const;
155  QgsConstWkbPtr locateBetweenWkbString( QgsConstWkbPtr ptr, QgsMultiPolyline& result, double fromMeasure, double toMeasure );
156  QgsConstWkbPtr locateAlongWkbString( QgsConstWkbPtr ptr, QgsMultiPoint& result, double measure );
157  static bool clipSegmentByRange( double x1, double y1, double m1, double x2, double y2, double m2, double range1, double range2, QgsPoint& pt1, QgsPoint& pt2, bool& secondPointClipped );
158  static void locateAlongSegment( double x1, double y1, double m1, double x2, double y2, double m2, double measure, bool& pt1Ok, QgsPoint& pt1, bool& pt2Ok, QgsPoint& pt2 );
159 };
160 #endif //QGSVECTORANALYZER
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:355
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:360
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:78
A convenience class for writing vector files to disk.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:135
The QGis class provides vector geometry analysis functions.
QVector< QgsPoint > QgsMultiPoint
A collection of QgsPoints that share a common collection of attributes.
Definition: qgsgeometry.h:55
A class to represent a point.
Definition: qgspoint.h:111
QVector< QgsPolyline > QgsMultiPolyline
A collection of QgsPolylines that share a common collection of attributes.
Definition: qgsgeometry.h:58
General purpose distance and area calculator.
This is the base class for vector data providers.
Represents a vector layer which manages a vector based data sets.