QGIS API Documentation  2.14.0-Essen
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 
21 {
22 }
23 
26 {
27  return ( envelope.xMaximum() - envelope.xMinimum() ) < mapToPixelTol && ( envelope.yMaximum() - envelope.yMinimum() ) < mapToPixelTol;
28 }
29 
32 {
33  QgsRectangle r;
34  r.setMinimal();
35 
36  for ( int i = 0, numPoints = points.size(); i < numPoints; ++i )
37  {
38  r.combineExtentWith( points[i].x(), points[i].y() );
39  }
40  return isGeneralizableByDeviceBoundingBox( r, mapToPixelTol );
41 }
42 
43 /***************************************************************************/
47 QgsTopologyPreservingSimplifier::QgsTopologyPreservingSimplifier( double tolerance ) : mTolerance( tolerance )
48 {
49 }
51 {
52 }
53 
56 {
57  return geometry->simplify( mTolerance );
58 }
59 
62 {
63  QgsGeometry* g = geometry->simplify( mTolerance );
64 
65  if ( g )
66  {
67  int wkbSize = g->wkbSize();
68  unsigned char *wkb = new unsigned char[ wkbSize ];
69  memcpy( wkb, g->asWkb(), wkbSize );
70  geometry->fromWkb( wkb, wkbSize );
71  delete g;
72 
73  return true;
74  }
75  return false;
76 }
QgsGeometry * simplify(double tolerance) const
Returns a simplified version of this geometry using a specified tolerance value.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer&#39;s length...
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:197
static bool isGeneralizableByDeviceBoundingBox(const QVector< QPointF > &points, float mapToPixelTol=1.0f)
Returns whether the device-geometry can be replaced by its BBOX when is applied the specified toleran...
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
virtual QgsGeometry * simplify(QgsGeometry *geometry) const override
Returns a simplified version the specified geometry.
void combineExtentWith(QgsRectangle *rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:202
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:187
double mTolerance
Distance tolerance for the simplification.
int wkbSize() const
Returns the size of the WKB in asWkb().
QgsTopologyPreservingSimplifier(double tolerance)
Implementation of GeometrySimplifier using the Douglas-Peucker algorithm.
virtual bool simplifyGeometry(QgsGeometry *geometry) const override
Simplifies the specified geometry.
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...
int size() const
const unsigned char * asWkb() const
Returns the buffer containing this geometry in WKB format.
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:192