QGIS API Documentation  2.15.0-Master (972fc9f)
qgsmaptopixelgeometrysimplifier.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptopixelgeometrysimplifier.h
3  ---------------------
4  begin : December 2013
5  copyright : (C) 2013 by Alvaro Huarte
6  email : http://wiki.osgeo.org/wiki/Alvaro_Huarte
7 
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSMAPTOPIXELGEOMETRYSIMPLIFIER_H
18 #define QGSMAPTOPIXELGEOMETRYSIMPLIFIER_H
19 
20 #include "qgsgeometry.h"
21 #include "qgscoordinatetransform.h"
22 #include "qgsmaptopixel.h"
23 
24 #include "qgsgeometrysimplifier.h"
25 
33 {
34  public:
37  {
38  Distance = 0,
39  SnapToGrid = 1,
40  Visvalingam = 2,
41  };
42 
44  QgsMapToPixelSimplifier( int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );
45  virtual ~QgsMapToPixelSimplifier();
46 
49  {
50  NoFlags = 0,
51  SimplifyGeometry = 1,
52  SimplifyEnvelope = 2,
53  };
54 
55  private:
57  static bool simplifyWkbGeometry( int simplifyFlags, SimplifyAlgorithm simplifyAlgorithm, QGis::WkbType wkbType, QgsConstWkbPtr sourceWkbPtr, QgsWkbPtr targetWkbPtr, int &targetWkbSize, const QgsRectangle& envelope, double map2pixelTol, bool writeHeader = true, bool isaLinearRing = false );
58 
59  protected:
62 
65 
67  double mTolerance;
68 
70  static float calculateLengthSquared2D( double x1, double y1, double x2, double y2 );
71 
73  static bool equalSnapToGrid( double x1, double y1, double x2, double y2, double gridOriginX, double gridOriginY, float gridInverseSizeXY );
74 
75  public:
77  int simplifyFlags() const { return mSimplifyFlags; }
79  void setSimplifyFlags( int simplifyFlags ) { mSimplifyFlags = simplifyFlags; }
80 
82  SimplifyAlgorithm simplifyAlgorithm() const { return mSimplifyAlgorithm; }
84  void setSimplifyAlgorithm( SimplifyAlgorithm simplifyAlgorithm ) { mSimplifyAlgorithm = simplifyAlgorithm; }
85 
87  virtual QgsGeometry* simplify( QgsGeometry* geometry ) const override;
89  virtual bool simplifyGeometry( QgsGeometry* geometry ) const override;
90 
92  virtual bool simplifyPoints( QgsWKBTypes::Type wkbType, QgsConstWkbPtr& sourceWkbPtr, QPolygonF& targetPoints ) const;
93 
94  // MapToPixel simplification helper methods
95  public:
96 
98  static bool isGeneralizableByMapBoundingBox( const QgsRectangle& envelope, double map2pixelTol );
99 
101  inline bool isGeneralizableByMapBoundingBox( const QgsRectangle& envelope ) const
102  {
103  return isGeneralizableByMapBoundingBox( envelope, mTolerance );
104  }
105 
107  static bool simplifyGeometry( QgsGeometry* geometry, int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );
108 
110  static bool simplifyPoints( QgsWKBTypes::Type wkbType, QgsConstWkbPtr& sourceWkbPtr, QPolygonF& targetPoints, int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );
111 };
112 
113 #endif // QGSMAPTOPIXELGEOMETRYSIMPLIFIER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setSimplifyFlags(int simplifyFlags)
Sets the simplification hints of the vector layer managed.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
WkbType
Used for symbology operations.
Definition: qgis.h:61
SimplifyAlgorithm
Types of simplification algorithms that can be used.
virtual bool simplifyGeometry(QgsGeometry *geometry) const =0
Simplifies the specified geometry.
int simplifyFlags() const
Gets the simplification hints of the vector layer managed.
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
double mTolerance
Distance tolerance for the simplification.
virtual QgsGeometry * simplify(QgsGeometry *geometry) const =0
Returns a simplified version the specified geometry.
void setSimplifyAlgorithm(SimplifyAlgorithm simplifyAlgorithm)
Sets the local simplification algorithm of the vector layer managed.
int mSimplifyFlags
Current simplification flags.
SimplifyAlgorithm mSimplifyAlgorithm
Current algorithm.
SimplifyFlag
Applicable simplification flags.
Abstract base class for simplify geometries using a specific algorithm.
bool isGeneralizableByMapBoundingBox(const QgsRectangle &envelope) const
Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel cont...