Skip to content

Commit

Permalink
#8725-R: define QgsSimplifyMethod
Browse files Browse the repository at this point in the history
Define QgsSimplifyMethod to use as optional parameter in
QgsFeatureRequest
  • Loading branch information
ahuarte47 authored and m-kuhn committed Jan 15, 2014
1 parent 08b5e30 commit 6358fde
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -75,6 +75,7 @@ SET(QGIS_CORE_SRCS
qgsgeometrycache.cpp
qgsgeometryvalidator.cpp
qgsgeometrysimplifier.cpp
qgssimplifymethod.cpp
qgsgml.cpp
qgsgmlschema.cpp
qgshttptransaction.cpp
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsfeaturerequest.cpp
Expand Up @@ -70,6 +70,7 @@ QgsFeatureRequest& QgsFeatureRequest::operator=( const QgsFeatureRequest & rh )
mFilterExpression = 0;
}
mAttrs = rh.mAttrs;
mSimplifyMethod = rh.mSimplifyMethod;
return *this;
}

Expand Down Expand Up @@ -120,7 +121,6 @@ QgsFeatureRequest& QgsFeatureRequest::setSubsetOfAttributes( const QgsAttributeL
return *this;
}


QgsFeatureRequest& QgsFeatureRequest::setSubsetOfAttributes( const QStringList& attrNames, const QgsFields& fields )
{
mFlags |= SubsetOfAttributes;
Expand All @@ -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 )
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsfeaturerequest.h
Expand Up @@ -20,6 +20,7 @@
#include "qgsfeature.h"
#include "qgsrectangle.h"
#include "qgsexpression.h"
#include "qgssimplifymethod.h"

#include <QList>
typedef QList<int> QgsAttributeList;
Expand All @@ -36,6 +37,7 @@ typedef QList<int> 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)
Expand Down Expand Up @@ -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
*
Expand All @@ -143,6 +149,7 @@ class CORE_EXPORT QgsFeatureRequest
QgsExpression* mFilterExpression;
Flags mFlags;
QgsAttributeList mAttrs;
QgsSimplifyMethod mSimplifyMethod;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )
Expand Down
52 changes: 52 additions & 0 deletions 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;
}
63 changes: 63 additions & 0 deletions 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

0 comments on commit 6358fde

Please sign in to comment.