QGIS API Documentation  3.6.0-Noosa (5873452)
qgsgeometrysimplifier.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometrysimplifier.cpp
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 #include <limits>
18 #include "qgsgeometrysimplifier.h"
19 #include "qgsrectangle.h"
20 #include "qgsgeometry.h"
21 
23 {
24  return ( envelope.xMaximum() - envelope.xMinimum() ) < mapToPixelTol && ( envelope.yMaximum() - envelope.yMinimum() ) < mapToPixelTol;
25 }
26 
27 bool QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( const QVector<QPointF> &points, float mapToPixelTol )
28 {
29  QgsRectangle r;
30  r.setMinimal();
31 
32  for ( int i = 0, numPoints = points.size(); i < numPoints; ++i )
33  {
34  r.combineExtentWith( points[i].x(), points[i].y() );
35  }
36  return isGeneralizableByDeviceBoundingBox( r, mapToPixelTol );
37 }
38 
39 /***************************************************************************/
40 
41 QgsTopologyPreservingSimplifier::QgsTopologyPreservingSimplifier( double tolerance ) : mTolerance( tolerance )
42 {
43 }
44 
46 {
47  return geometry.simplify( mTolerance );
48 }
49 
A rectangle specified with double values.
Definition: qgsrectangle.h:41
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:151
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
double mTolerance
Distance tolerance for the simplification.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle...
Definition: qgsrectangle.h:359
QgsGeometry simplify(const QgsGeometry &geometry) const override
Returns a simplified version the specified geometry.
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
QgsTopologyPreservingSimplifier(double tolerance)
Constructor for QgsTopologyPreservingSimplifier.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
static bool isGeneralizableByDeviceBoundingBox(const QgsRectangle &envelope, float mapToPixelTol=1.0f)
Returns whether the device-envelope can be replaced by its BBOX when is applied the specified toleran...