QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "qgsvectorlayer.h"
22 #include "qgsfield.h"
23 #include "qgsfeature.h"
24 #include "qgsgeometry.h"
25 #include "qgsfield.h"
26 #include "qgsdistancearea.h"
27 
29 class QProgressDialog;
30 
31 
36 class ANALYSIS_EXPORT QgsGeometryAnalyzer
37 {
38  public:
39 
48  bool simplify( QgsVectorLayer* layer, const QString& shapefileName, double tolerance,
49  bool onlySelectedFeatures = false, QProgressDialog* p = 0 );
50 
58  bool centroids( QgsVectorLayer* layer, const QString& shapefileName,
59  bool onlySelectedFeatures = false, QProgressDialog* p = 0 );
60 
67  bool extent( QgsVectorLayer* layer, const QString& shapefileName, bool onlySelectedFeatures = false, QProgressDialog* p = 0 );
68 
78  bool buffer( QgsVectorLayer* layer, const QString& shapefileName, double bufferDistance,
79  bool onlySelectedFeatures = false, bool dissolve = false, int bufferDistanceField = -1, QProgressDialog* p = 0 );
80 
89  bool convexHull( QgsVectorLayer* layer, const QString& shapefileName, bool onlySelectedFeatures = false,
90  int uniqueIdField = -1, QProgressDialog* p = 0 );
91 
100  bool dissolve( QgsVectorLayer* layer, const QString& shapefileName, bool onlySelectedFeatures = false,
101  int uniqueIdField = -1, QProgressDialog* p = 0 );
102 
120  bool eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer* eventLayer, int lineField, int eventField, QList<int>& unlocatedFeatureIds, const QString& outputLayer,
121  const QString& outputFormat, int locationField1, int locationField2 = -1, int offsetField = -1, double offsetScale = 1.0,
122  bool forceSingleGeometry = false, QgsVectorDataProvider* memoryProvider = 0, QProgressDialog* p = 0 );
123 
125  QgsGeometry* locateBetweenMeasures( double fromMeasure, double toMeasure, QgsGeometry* lineGeom );
128  QgsGeometry* locateAlongMeasure( double measure, QgsGeometry* lineGeom );
129 
130  private:
131 
132  QList<double> simpleMeasure( QgsGeometry* geometry );
133  double perimeterMeasure( QgsGeometry* geometry, QgsDistanceArea& measure );
135  void simplifyFeature( QgsFeature& f, QgsVectorFileWriter* vfw, double tolerance );
137  void centroidFeature( QgsFeature& f, QgsVectorFileWriter* vfw );
139  void bufferFeature( QgsFeature& f, int nProcessedFeatures, QgsVectorFileWriter* vfw, bool dissolve, QgsGeometry** dissolveGeometry,
140  double bufferDistance, int bufferDistanceField );
142  void convexFeature( QgsFeature& f, int nProcessedFeatures, QgsGeometry** dissolveGeometry );
144  void dissolveFeature( QgsFeature& f, int nProcessedFeatures, QgsGeometry** dissolveGeometry );
145 
146  //helper functions for event layer
147  void addEventLayerFeature( QgsFeature& feature, QgsGeometry* geom, QgsGeometry* lineGeom, QgsVectorFileWriter* fileWriter, QgsFeatureList& memoryFeatures, int offsetField = -1, double offsetScale = 1.0,
148  bool forceSingleType = false );
153  void createOffsetGeometry( QgsGeometry* geom, QgsGeometry* lineGeom, double offset );
154  QgsPoint createPointOffset( double x, double y, double dist, QgsGeometry* lineGeom ) const;
155  const unsigned char* locateBetweenWkbString( const unsigned char* ptr, QgsMultiPolyline& result, double fromMeasure, double toMeasure );
156  const unsigned char* locateAlongWkbString( const unsigned char* 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