QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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
18
19#include <limits>
20
21#include "qgsgeometry.h"
22#include "qgsgeos.h"
23#include "qgsrectangle.h"
24
26{
27 return ( envelope.xMaximum() - envelope.xMinimum() ) < mapToPixelTol && ( envelope.yMaximum() - envelope.yMinimum() ) < mapToPixelTol;
28}
29
30bool QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( const QVector<QPointF> &points, float mapToPixelTol )
31{
33 r.setNull();
34
35 for ( int i = 0, numPoints = points.size(); i < numPoints; ++i )
36 {
37 r.combineExtentWith( points[i].x(), points[i].y() );
38 }
39 return isGeneralizableByDeviceBoundingBox( r, mapToPixelTol );
40}
41
42/***************************************************************************/
43
47
49{
50 return geometry.simplify( mTolerance );
51}
52
54{
55 if ( !geometry )
56 {
57 return nullptr;
58 }
59
60 const QgsGeos geos( geometry );
61 std::unique_ptr< QgsAbstractGeometry > simplifiedGeom( geos.simplify( mTolerance ) );
62 return simplifiedGeom.release();
63}
64
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...
Abstract base class for all geometries.
A geometry is the spatial representation of a feature.
QgsGeometry simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
Does vector analysis using the GEOS library and handles import, export, and exception handling.
Definition qgsgeos.h:141
A rectangle specified with double values.
double xMinimum
double yMinimum
double xMaximum
double yMaximum
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
void setNull()
Mark a rectangle as being null (holding no spatial information).
QgsGeometry simplify(const QgsGeometry &geometry) const override
Returns a simplified version the specified geometry.
double mTolerance
Distance tolerance for the simplification.
QgsTopologyPreservingSimplifier(double tolerance)
Constructor for QgsTopologyPreservingSimplifier.
Contains geos related utilities and functions.
Definition qgsgeos.h:77