Skip to content

Commit 6358fde

Browse files
ahuarte47m-kuhn
authored andcommitted
#8725-R: define QgsSimplifyMethod
Define QgsSimplifyMethod to use as optional parameter in QgsFeatureRequest
1 parent 08b5e30 commit 6358fde

5 files changed

+130
-1
lines changed

src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ SET(QGIS_CORE_SRCS
7575
qgsgeometrycache.cpp
7676
qgsgeometryvalidator.cpp
7777
qgsgeometrysimplifier.cpp
78+
qgssimplifymethod.cpp
7879
qgsgml.cpp
7980
qgsgmlschema.cpp
8081
qgshttptransaction.cpp

src/core/qgsfeaturerequest.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ QgsFeatureRequest& QgsFeatureRequest::operator=( const QgsFeatureRequest & rh )
7070
mFilterExpression = 0;
7171
}
7272
mAttrs = rh.mAttrs;
73+
mSimplifyMethod = rh.mSimplifyMethod;
7374
return *this;
7475
}
7576

@@ -120,7 +121,6 @@ QgsFeatureRequest& QgsFeatureRequest::setSubsetOfAttributes( const QgsAttributeL
120121
return *this;
121122
}
122123

123-
124124
QgsFeatureRequest& QgsFeatureRequest::setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields )
125125
{
126126
mFlags |= SubsetOfAttributes;
@@ -135,6 +135,12 @@ QgsFeatureRequest& QgsFeatureRequest::setSubsetOfAttributes( const QStringList&
135135
return *this;
136136
}
137137

138+
QgsFeatureRequest& QgsFeatureRequest::setSimplifyMethod( const QgsSimplifyMethod& simplifyMethod )
139+
{
140+
mSimplifyMethod = simplifyMethod;
141+
return *this;
142+
}
143+
138144
bool QgsFeatureRequest::acceptFeature( const QgsFeature& feature )
139145
{
140146
switch ( mFilter )

src/core/qgsfeaturerequest.h

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgsfeature.h"
2121
#include "qgsrectangle.h"
2222
#include "qgsexpression.h"
23+
#include "qgssimplifymethod.h"
2324

2425
#include <QList>
2526
typedef QList<int> QgsAttributeList;
@@ -36,6 +37,7 @@ typedef QList<int> QgsAttributeList;
3637
* For efficiency, it is also possible to tell provider that some data is not required:
3738
* - NoGeometry flag
3839
* - SubsetOfAttributes flag
40+
* - SimplifyMethod for geometries to fetch
3941
*
4042
* The options may be chained, e.g.:
4143
* QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1)).setFlags(QgsFeatureRequest::ExactIntersect)
@@ -120,6 +122,10 @@ class CORE_EXPORT QgsFeatureRequest
120122
//! Set a subset of attributes by names that will be fetched
121123
QgsFeatureRequest& setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields );
122124

125+
//! Set a simplification method for geometries that will be fetched
126+
QgsFeatureRequest& setSimplifyMethod( const QgsSimplifyMethod& simplifyMethod );
127+
const QgsSimplifyMethod& simplifyMethod() const { return mSimplifyMethod; }
128+
123129
/**
124130
* Check if a feature is accepted by this requests filter
125131
*
@@ -143,6 +149,7 @@ class CORE_EXPORT QgsFeatureRequest
143149
QgsExpression* mFilterExpression;
144150
Flags mFlags;
145151
QgsAttributeList mAttrs;
152+
QgsSimplifyMethod mSimplifyMethod;
146153
};
147154

148155
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )

src/core/qgssimplifymethod.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/***************************************************************************
2+
qgssimplifymethod.cpp
3+
---------------------
4+
begin : December 2013
5+
copyright : (C) 2013 by Matthias Kuhn / Alvaro Huarte
6+
email :
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgssimplifymethod.h"
17+
18+
QgsSimplifyMethod::QgsSimplifyMethod()
19+
: mMethodType( QgsSimplifyMethod::NoSimplification )
20+
, mTolerance( 1 )
21+
, mForceLocalOptimization( true )
22+
{
23+
}
24+
25+
QgsSimplifyMethod::QgsSimplifyMethod( const QgsSimplifyMethod &rh )
26+
{
27+
operator=( rh );
28+
}
29+
30+
QgsSimplifyMethod& QgsSimplifyMethod::operator=( const QgsSimplifyMethod &rh )
31+
{
32+
mMethodType = rh.mMethodType;
33+
mTolerance = rh.mTolerance;
34+
mForceLocalOptimization = rh.mForceLocalOptimization;
35+
36+
return *this;
37+
}
38+
39+
void QgsSimplifyMethod::setMethodType( MethodType methodType )
40+
{
41+
mMethodType = methodType;
42+
}
43+
44+
void QgsSimplifyMethod::setTolerance( double tolerance )
45+
{
46+
mTolerance = tolerance;
47+
}
48+
49+
void QgsSimplifyMethod::setForceLocalOptimization( bool localOptimization )
50+
{
51+
mForceLocalOptimization = localOptimization;
52+
}

src/core/qgssimplifymethod.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/***************************************************************************
2+
qgssimplifymethod.h
3+
---------------------
4+
begin : December 2013
5+
copyright : (C) 2013 by Matthias Kuhn / Alvaro Huarte
6+
email :
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSSIMPLIFYMETHOD_H
17+
#define QGSSIMPLIFYMETHOD_H
18+
19+
/**
20+
* This class contains information about how to simplify geometries fetched from a QgsFeatureIterator
21+
*/
22+
class CORE_EXPORT QgsSimplifyMethod
23+
{
24+
public:
25+
enum MethodType
26+
{
27+
NoSimplification, //!< No simplification is applied
28+
OptimizeForRendering, //!< Simplify using the map2pixel data to optimize the rendering of geometries
29+
PreserveTopology //!< Simplify using the Douglas-Peucker algorithm ensuring that the result is a valid geometry
30+
};
31+
32+
//! construct a default method
33+
QgsSimplifyMethod();
34+
//! copy constructor
35+
QgsSimplifyMethod( const QgsSimplifyMethod& rh );
36+
//! assignment operator
37+
QgsSimplifyMethod& operator=( const QgsSimplifyMethod& rh );
38+
39+
//! Sets the simplification type
40+
void setMethodType( MethodType methodType );
41+
//! Gets the simplification type
42+
inline MethodType methodType() const { return mMethodType; }
43+
44+
//! Sets the tolerance of simplification. Represents the maximum distance between two coordinates which can be considered equal
45+
void setTolerance( double tolerance );
46+
//! Gets the tolerance of simplification
47+
inline double tolerance() const { return mTolerance; }
48+
49+
//! Sets whether the simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries
50+
void setForceLocalOptimization( bool localOptimization );
51+
//! Gets whether the simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries
52+
inline bool forceLocalOptimization() const { return mForceLocalOptimization; }
53+
54+
protected:
55+
//! Simplification method
56+
MethodType mMethodType;
57+
//! Tolerance of simplification, it represents the maximum distance between two coordinates which can be considered equal
58+
double mTolerance;
59+
//! Simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries
60+
bool mForceLocalOptimization;
61+
};
62+
63+
#endif // QGSSIMPLIFYMETHOD_H

0 commit comments

Comments
 (0)