QGIS API Documentation  2.99.0-Master (c42dad3)
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 "qgis.h"
21 #include "qgsgeometrysimplifier.h"
22 #include <QPolygonF>
23 
25 class QgsWkbPtr;
26 class QgsConstWkbPtr;
27 
28 
36 {
37  public:
40  {
41  Distance = 0,
42  SnapToGrid = 1,
43  Visvalingam = 2,
44  };
45 
47  QgsMapToPixelSimplifier( int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );
48  virtual ~QgsMapToPixelSimplifier();
49 
52  {
53  NoFlags = 0,
54  SimplifyGeometry = 1,
55  SimplifyEnvelope = 2,
56  };
57 
58  private:
60  static QgsGeometry simplifyGeometry( int simplifyFlags, SimplifyAlgorithm simplifyAlgorithm, QgsWkbTypes::Type wkbType, const QgsAbstractGeometry& geometry, const QgsRectangle &envelope, double map2pixelTol, bool isaLinearRing );
61 
62  protected:
65 
68 
70  double mTolerance;
71 
73  static float calculateLengthSquared2D( double x1, double y1, double x2, double y2 );
74 
76  static bool equalSnapToGrid( double x1, double y1, double x2, double y2, double gridOriginX, double gridOriginY, float gridInverseSizeXY );
77 
78  public:
80  int simplifyFlags() const { return mSimplifyFlags; }
82  void setSimplifyFlags( int simplifyFlags ) { mSimplifyFlags = simplifyFlags; }
83 
85  SimplifyAlgorithm simplifyAlgorithm() const { return mSimplifyAlgorithm; }
87  void setSimplifyAlgorithm( SimplifyAlgorithm simplifyAlgorithm ) { mSimplifyAlgorithm = simplifyAlgorithm; }
88 
90  virtual QgsGeometry simplify( const QgsGeometry& geometry ) const override;
91 
93  void setTolerance( double value ) { mTolerance = value; }
94 
95  // MapToPixel simplification helper methods
96  public:
97 
99  static bool isGeneralizableByMapBoundingBox( const QgsRectangle& envelope, double map2pixelTol );
100 
102  inline bool isGeneralizableByMapBoundingBox( const QgsRectangle& envelope ) const
103  {
104  return isGeneralizableByMapBoundingBox( envelope, mTolerance );
105  }
106 };
107 
108 #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.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:78
SimplifyAlgorithm
Types of simplification algorithms that can be used.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
int simplifyFlags() const
Gets the simplification hints of the vector layer managed.
Abstract base class for all geometries.
void setTolerance(double value)
Sets the tolerance of the vector layer managed.
Implementation of GeometrySimplifier using the "MapToPixel" algorithm.
double mTolerance
Distance tolerance for the simplification.
void setSimplifyAlgorithm(SimplifyAlgorithm simplifyAlgorithm)
Sets the local simplification algorithm of the vector layer managed.
int mSimplifyFlags
Current simplification flags.
SimplifyAlgorithm mSimplifyAlgorithm
Current algorithm.
virtual QgsGeometry simplify(const QgsGeometry &geometry) const =0
Returns a simplified version the specified geometry.
SimplifyFlag
Applicable simplification flags.
bool isGeneralizableByMapBoundingBox(const QgsRectangle &envelope) const
Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel cont...
Abstract base class for simplify geometries using a specific algorithm.