QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgsgeos.h"
22 
24 {
25  return ( envelope.xMaximum() - envelope.xMinimum() ) < mapToPixelTol && ( envelope.yMaximum() - envelope.yMinimum() ) < mapToPixelTol;
26 }
27 
28 bool QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( const QVector<QPointF> &points, float mapToPixelTol )
29 {
30  QgsRectangle r;
31  r.setMinimal();
32 
33  for ( int i = 0, numPoints = points.size(); i < numPoints; ++i )
34  {
35  r.combineExtentWith( points[i].x(), points[i].y() );
36  }
37  return isGeneralizableByDeviceBoundingBox( r, mapToPixelTol );
38 }
39 
40 /***************************************************************************/
41 
42 QgsTopologyPreservingSimplifier::QgsTopologyPreservingSimplifier( double tolerance ) : mTolerance( tolerance )
43 {
44 }
45 
47 {
48  return geometry.simplify( mTolerance );
49 }
50 
52 {
53  if ( !geometry )
54  {
55  return nullptr;
56  }
57 
58  const QgsGeos geos( geometry );
59  std::unique_ptr< QgsAbstractGeometry > simplifiedGeom( geos.simplify( mTolerance ) );
60  return simplifiedGeom.release();
61 }
62 
QgsRectangle::combineExtentWith
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Definition: qgsrectangle.h:391
qgsrectangle.h
QgsTopologyPreservingSimplifier::simplify
QgsGeometry simplify(const QgsGeometry &geometry) const override
Returns a simplified version the specified geometry.
Definition: qgsgeometrysimplifier.cpp:46
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
geos
Contains geos related utilities and functions.
Definition: qgsgeos.h:41
QgsRectangle::setMinimal
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:172
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsTopologyPreservingSimplifier::QgsTopologyPreservingSimplifier
QgsTopologyPreservingSimplifier(double tolerance)
Constructor for QgsTopologyPreservingSimplifier.
Definition: qgsgeometrysimplifier.cpp:42
qgsgeometrysimplifier.h
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
QgsGeos
Does vector analysis using the geos library and handles import, export, exception handling*.
Definition: qgsgeos.h:103
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:79
QgsGeometry::simplify
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
Definition: qgsgeometry.cpp:2244
QgsRectangle::yMaximum
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
qgsgeometry.h
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox
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...
Definition: qgsgeometrysimplifier.cpp:23
qgsgeos.h
QgsTopologyPreservingSimplifier::mTolerance
double mTolerance
Distance tolerance for the simplification.
Definition: qgsgeometrysimplifier.h:85