From 6358fde727e7171574edfb3e54f5083364e68c9e Mon Sep 17 00:00:00 2001 From: ahuarte47 Date: Tue, 24 Dec 2013 07:51:26 +0100 Subject: [PATCH] #8725-R: define QgsSimplifyMethod Define QgsSimplifyMethod to use as optional parameter in QgsFeatureRequest --- src/core/CMakeLists.txt | 1 + src/core/qgsfeaturerequest.cpp | 8 ++++- src/core/qgsfeaturerequest.h | 7 ++++ src/core/qgssimplifymethod.cpp | 52 ++++++++++++++++++++++++++++ src/core/qgssimplifymethod.h | 63 ++++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 src/core/qgssimplifymethod.cpp create mode 100644 src/core/qgssimplifymethod.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 5b9dc5fc8dd..9f78a8fb6aa 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -75,6 +75,7 @@ SET(QGIS_CORE_SRCS qgsgeometrycache.cpp qgsgeometryvalidator.cpp qgsgeometrysimplifier.cpp + qgssimplifymethod.cpp qgsgml.cpp qgsgmlschema.cpp qgshttptransaction.cpp diff --git a/src/core/qgsfeaturerequest.cpp b/src/core/qgsfeaturerequest.cpp index 6e33543310d..1b407cf867a 100644 --- a/src/core/qgsfeaturerequest.cpp +++ b/src/core/qgsfeaturerequest.cpp @@ -70,6 +70,7 @@ QgsFeatureRequest& QgsFeatureRequest::operator=( const QgsFeatureRequest & rh ) mFilterExpression = 0; } mAttrs = rh.mAttrs; + mSimplifyMethod = rh.mSimplifyMethod; return *this; } @@ -120,7 +121,6 @@ QgsFeatureRequest& QgsFeatureRequest::setSubsetOfAttributes( const QgsAttributeL return *this; } - QgsFeatureRequest& QgsFeatureRequest::setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields ) { mFlags |= SubsetOfAttributes; @@ -135,6 +135,12 @@ QgsFeatureRequest& QgsFeatureRequest::setSubsetOfAttributes( const QStringList& return *this; } +QgsFeatureRequest& QgsFeatureRequest::setSimplifyMethod( const QgsSimplifyMethod& simplifyMethod ) +{ + mSimplifyMethod = simplifyMethod; + return *this; +} + bool QgsFeatureRequest::acceptFeature( const QgsFeature& feature ) { switch ( mFilter ) diff --git a/src/core/qgsfeaturerequest.h b/src/core/qgsfeaturerequest.h index 203f63d81f6..cebd5331eaf 100644 --- a/src/core/qgsfeaturerequest.h +++ b/src/core/qgsfeaturerequest.h @@ -20,6 +20,7 @@ #include "qgsfeature.h" #include "qgsrectangle.h" #include "qgsexpression.h" +#include "qgssimplifymethod.h" #include typedef QList QgsAttributeList; @@ -36,6 +37,7 @@ typedef QList QgsAttributeList; * For efficiency, it is also possible to tell provider that some data is not required: * - NoGeometry flag * - SubsetOfAttributes flag + * - SimplifyMethod for geometries to fetch * * The options may be chained, e.g.: * QgsFeatureRequest().setFilterRect(QgsRectangle(0,0,1,1)).setFlags(QgsFeatureRequest::ExactIntersect) @@ -120,6 +122,10 @@ class CORE_EXPORT QgsFeatureRequest //! Set a subset of attributes by names that will be fetched QgsFeatureRequest& setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields ); + //! Set a simplification method for geometries that will be fetched + QgsFeatureRequest& setSimplifyMethod( const QgsSimplifyMethod& simplifyMethod ); + const QgsSimplifyMethod& simplifyMethod() const { return mSimplifyMethod; } + /** * Check if a feature is accepted by this requests filter * @@ -143,6 +149,7 @@ class CORE_EXPORT QgsFeatureRequest QgsExpression* mFilterExpression; Flags mFlags; QgsAttributeList mAttrs; + QgsSimplifyMethod mSimplifyMethod; }; Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags ) diff --git a/src/core/qgssimplifymethod.cpp b/src/core/qgssimplifymethod.cpp new file mode 100644 index 00000000000..a2efeea7344 --- /dev/null +++ b/src/core/qgssimplifymethod.cpp @@ -0,0 +1,52 @@ +/*************************************************************************** + qgssimplifymethod.cpp + --------------------- + begin : December 2013 + copyright : (C) 2013 by Matthias Kuhn / Alvaro Huarte + email : + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "qgssimplifymethod.h" + +QgsSimplifyMethod::QgsSimplifyMethod() + : mMethodType( QgsSimplifyMethod::NoSimplification ) + , mTolerance( 1 ) + , mForceLocalOptimization( true ) +{ +} + +QgsSimplifyMethod::QgsSimplifyMethod( const QgsSimplifyMethod &rh ) +{ + operator=( rh ); +} + +QgsSimplifyMethod& QgsSimplifyMethod::operator=( const QgsSimplifyMethod &rh ) +{ + mMethodType = rh.mMethodType; + mTolerance = rh.mTolerance; + mForceLocalOptimization = rh.mForceLocalOptimization; + + return *this; +} + +void QgsSimplifyMethod::setMethodType( MethodType methodType ) +{ + mMethodType = methodType; +} + +void QgsSimplifyMethod::setTolerance( double tolerance ) +{ + mTolerance = tolerance; +} + +void QgsSimplifyMethod::setForceLocalOptimization( bool localOptimization ) +{ + mForceLocalOptimization = localOptimization; +} diff --git a/src/core/qgssimplifymethod.h b/src/core/qgssimplifymethod.h new file mode 100644 index 00000000000..276361445db --- /dev/null +++ b/src/core/qgssimplifymethod.h @@ -0,0 +1,63 @@ +/*************************************************************************** + qgssimplifymethod.h + --------------------- + begin : December 2013 + copyright : (C) 2013 by Matthias Kuhn / Alvaro Huarte + email : + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef QGSSIMPLIFYMETHOD_H +#define QGSSIMPLIFYMETHOD_H + +/** + * This class contains information about how to simplify geometries fetched from a QgsFeatureIterator + */ +class CORE_EXPORT QgsSimplifyMethod +{ + public: + enum MethodType + { + NoSimplification, //!< No simplification is applied + OptimizeForRendering, //!< Simplify using the map2pixel data to optimize the rendering of geometries + PreserveTopology //!< Simplify using the Douglas-Peucker algorithm ensuring that the result is a valid geometry + }; + + //! construct a default method + QgsSimplifyMethod(); + //! copy constructor + QgsSimplifyMethod( const QgsSimplifyMethod& rh ); + //! assignment operator + QgsSimplifyMethod& operator=( const QgsSimplifyMethod& rh ); + + //! Sets the simplification type + void setMethodType( MethodType methodType ); + //! Gets the simplification type + inline MethodType methodType() const { return mMethodType; } + + //! Sets the tolerance of simplification. Represents the maximum distance between two coordinates which can be considered equal + void setTolerance( double tolerance ); + //! Gets the tolerance of simplification + inline double tolerance() const { return mTolerance; } + + //! Sets whether the simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries + void setForceLocalOptimization( bool localOptimization ); + //! Gets whether the simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries + inline bool forceLocalOptimization() const { return mForceLocalOptimization; } + + protected: + //! Simplification method + MethodType mMethodType; + //! Tolerance of simplification, it represents the maximum distance between two coordinates which can be considered equal + double mTolerance; + //! Simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries + bool mForceLocalOptimization; +}; + +#endif // QGSSIMPLIFYMETHOD_H