Skip to content

Commit

Permalink
#87525R: refactoring and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed Jan 22, 2014
1 parent 12a463d commit f6f0384
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 31 deletions.
3 changes: 0 additions & 3 deletions python/core/qgssimplifymethod.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class QgsSimplifyMethod
/** Gets the tolerance of simplification */ /** Gets the tolerance of simplification */
double tolerance() const; double tolerance() const;


/** Returns the optimal tolerance for Douglas-Peucker simplification algorithms */
double toleranceForDouglasPeuckerAlgorithms() const;

/** Sets whether the simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries */ /** 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 ); 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 */ /** Gets whether the simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries */
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsmaptopixelgeometrysimplifier.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include "qgsmaptopixelgeometrysimplifier.h" #include "qgsmaptopixelgeometrysimplifier.h"
#include "qgsapplication.h" #include "qgsapplication.h"


QgsMapToPixelSimplifier::QgsMapToPixelSimplifier( int simplifyFlags, double map2pixelTol ) QgsMapToPixelSimplifier::QgsMapToPixelSimplifier( int simplifyFlags, double tolerance )
: mSimplifyFlags( simplifyFlags ) : mSimplifyFlags( simplifyFlags )
, mMapToPixelTol( map2pixelTol ) , mTolerance( tolerance )
{ {
} }
QgsMapToPixelSimplifier::~QgsMapToPixelSimplifier() QgsMapToPixelSimplifier::~QgsMapToPixelSimplifier()
Expand Down Expand Up @@ -330,13 +330,13 @@ QgsGeometry* QgsMapToPixelSimplifier::simplify( QgsGeometry* geometry ) const
unsigned char* wkb = ( unsigned char* )malloc( wkbSize ); unsigned char* wkb = ( unsigned char* )malloc( wkbSize );
memcpy( wkb, geometry->asWkb(), wkbSize ); memcpy( wkb, geometry->asWkb(), wkbSize );
g->fromWkb( wkb, wkbSize ); g->fromWkb( wkb, wkbSize );
simplifyGeometry( g, mSimplifyFlags, mMapToPixelTol ); simplifyGeometry( g, mSimplifyFlags, mTolerance );


return g; return g;
} }


//! Simplifies the geometry (Removing duplicated points) when is applied the specified map2pixel context //! Simplifies the geometry (Removing duplicated points) when is applied the specified map2pixel context
bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry, int simplifyFlags, double map2pixelTol ) bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry, int simplifyFlags, double tolerance )
{ {
size_t targetWkbSize = 0; size_t targetWkbSize = 0;


Expand All @@ -351,7 +351,7 @@ bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry, int simpl
size_t wkbSize = geometry->wkbSize( ); size_t wkbSize = geometry->wkbSize( );


// Simplify the geometry rewriting temporally its WKB-stream for saving calloc's. // Simplify the geometry rewriting temporally its WKB-stream for saving calloc's.
if ( simplifyWkbGeometry( simplifyFlags, wkbType, wkb, wkbSize, wkb, targetWkbSize, envelope, map2pixelTol ) ) if ( simplifyWkbGeometry( simplifyFlags, wkbType, wkb, wkbSize, wkb, targetWkbSize, envelope, tolerance ) )
{ {
unsigned char* targetWkb = ( unsigned char* )malloc( targetWkbSize ); unsigned char* targetWkb = ( unsigned char* )malloc( targetWkbSize );
memcpy( targetWkb, wkb, targetWkbSize ); memcpy( targetWkb, wkb, targetWkbSize );
Expand All @@ -364,5 +364,5 @@ bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry, int simpl
//! Simplifies the geometry (Removing duplicated points) when is applied the specified map2pixel context //! Simplifies the geometry (Removing duplicated points) when is applied the specified map2pixel context
bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry ) const bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry ) const
{ {
return simplifyGeometry( geometry, mSimplifyFlags, mMapToPixelTol ); return simplifyGeometry( geometry, mSimplifyFlags, mTolerance );
} }
10 changes: 5 additions & 5 deletions src/core/qgsmaptopixelgeometrysimplifier.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
{ {
public: public:
QgsMapToPixelSimplifier( int simplifyFlags, double map2pixelTol ); QgsMapToPixelSimplifier( int simplifyFlags, double tolerance );
virtual ~QgsMapToPixelSimplifier(); virtual ~QgsMapToPixelSimplifier();


//! Applicable simplification flags //! Applicable simplification flags
Expand All @@ -51,8 +51,8 @@ class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
//! Current simplification flags //! Current simplification flags
int mSimplifyFlags; int mSimplifyFlags;


//! Map2Pixel tolerance for the simplification //! Distance tolerance for the simplification
double mMapToPixelTol; double mTolerance;


//! Returns the squared 2D-distance of the vector defined by the two points specified //! Returns the squared 2D-distance of the vector defined by the two points specified
static float calculateLengthSquared2D( double x1, double y1, double x2, double y2 ); static float calculateLengthSquared2D( double x1, double y1, double x2, double y2 );
Expand All @@ -73,10 +73,10 @@ class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
static bool canbeGeneralizedByMapBoundingBox( const QgsRectangle& envelope, double map2pixelTol ); static bool canbeGeneralizedByMapBoundingBox( const QgsRectangle& envelope, double map2pixelTol );


//! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context //! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context
inline bool canbeGeneralizedByMapBoundingBox( const QgsRectangle& envelope ) const { return canbeGeneralizedByMapBoundingBox( envelope, mMapToPixelTol ); } inline bool canbeGeneralizedByMapBoundingBox( const QgsRectangle& envelope ) const { return canbeGeneralizedByMapBoundingBox( envelope, mTolerance ); }


//! Simplifies the geometry when is applied the specified map2pixel context //! Simplifies the geometry when is applied the specified map2pixel context
static bool simplifyGeometry( QgsGeometry* geometry, int simplifyFlags, double map2pixelTol ); static bool simplifyGeometry( QgsGeometry* geometry, int simplifyFlags, double tolerance );


}; };


Expand Down
6 changes: 0 additions & 6 deletions src/core/qgssimplifymethod.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ void QgsSimplifyMethod::setForceLocalOptimization( bool localOptimization )
mForceLocalOptimization = localOptimization; mForceLocalOptimization = localOptimization;
} }


double QgsSimplifyMethod::toleranceForDouglasPeuckerAlgorithms() const
{
//TODO: define more precise value, now, it is experimental but conservative
return mTolerance / 5.0;
}

QgsAbstractGeometrySimplifier* QgsSimplifyMethod::createGeometrySimplifier( const QgsSimplifyMethod& simplifyMethod ) QgsAbstractGeometrySimplifier* QgsSimplifyMethod::createGeometrySimplifier( const QgsSimplifyMethod& simplifyMethod )
{ {
QgsSimplifyMethod::MethodType methodType = simplifyMethod.methodType(); QgsSimplifyMethod::MethodType methodType = simplifyMethod.methodType();
Expand Down
3 changes: 0 additions & 3 deletions src/core/qgssimplifymethod.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class CORE_EXPORT QgsSimplifyMethod
//! Gets the tolerance of simplification //! Gets the tolerance of simplification
inline double tolerance() const { return mTolerance; } inline double tolerance() const { return mTolerance; }


//! Returns the optimal tolerance for Douglas-Peucker simplification algorithms
double toleranceForDouglasPeuckerAlgorithms() const;

//! Sets whether the simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries //! 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 ); 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 //! Gets whether the simplification executes after fetch the geometries from provider, otherwise it executes, when supported, in provider before fetch the geometries
Expand Down
6 changes: 3 additions & 3 deletions src/providers/ogr/qgsogrgeometrysimplifier.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ bool QgsOgrTopologyPreservingSimplifier::simplifyGeometry( OGRGeometryH geometry


#if defined(GDAL_VERSION_NUM) && defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0) #if defined(GDAL_VERSION_NUM) && defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0)


QgsOgrMapToPixelSimplifier::QgsOgrMapToPixelSimplifier( int simplifyFlags, double map2pixelTol ) QgsOgrMapToPixelSimplifier::QgsOgrMapToPixelSimplifier( int simplifyFlags, double tolerance )
: QgsMapToPixelSimplifier( simplifyFlags, map2pixelTol ) : QgsMapToPixelSimplifier( simplifyFlags, tolerance )
, mPointBufferPtr( NULL ) , mPointBufferPtr( NULL )
, mPointBufferCount( 0 ) , mPointBufferCount( 0 )
{ {
Expand Down Expand Up @@ -136,7 +136,7 @@ bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( QGis::GeometryType geometr
if ( geometryType == QGis::Point || geometryType == QGis::UnknownGeometry ) return false; if ( geometryType == QGis::Point || geometryType == QGis::UnknownGeometry ) return false;
pointSimplifiedCount = 0; pointSimplifiedCount = 0;


double map2pixelTol = mMapToPixelTol * mMapToPixelTol; //-> Use mappixelTol for 'LengthSquare' calculations. double map2pixelTol = mTolerance * mTolerance; //-> Use mappixelTol for 'LengthSquare' calculations.
double x, y, lastX = 0, lastY = 0; double x, y, lastX = 0, lastY = 0;


char* xsourcePtr = ( char* )xptr; char* xsourcePtr = ( char* )xptr;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrgeometrysimplifier.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class QgsOgrTopologyPreservingSimplifier : public QgsOgrAbstractGeometrySimplifi
class QgsOgrMapToPixelSimplifier : public QgsOgrAbstractGeometrySimplifier, QgsMapToPixelSimplifier class QgsOgrMapToPixelSimplifier : public QgsOgrAbstractGeometrySimplifier, QgsMapToPixelSimplifier
{ {
public: public:
QgsOgrMapToPixelSimplifier( int simplifyFlags, double map2pixelTol ); QgsOgrMapToPixelSimplifier( int simplifyFlags, double tolerance );
virtual ~QgsOgrMapToPixelSimplifier(); virtual ~QgsOgrMapToPixelSimplifier();


private: private:
Expand Down
6 changes: 2 additions & 4 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -303,11 +303,9 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
{ {
QString simplifyFunctionName = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering QString simplifyFunctionName = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering
? ( P->mConnectionRO->majorVersion() < 2 ? "simplify" : "st_simplify" ) ? ( P->mConnectionRO->majorVersion() < 2 ? "simplify" : "st_simplify" )
: ( P->mConnectionRO->majorVersion() < 2 ? "simplifypreservetopology" : "st_simplifypreservetopology" ); : ( P->mConnectionRO->majorVersion() < 2 ? "simplifypreservetopology" : "st_simplifypreservetopology" );


double tolerance = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering double tolerance = simplifyMethod.tolerance();
? simplifyMethod.toleranceForDouglasPeuckerAlgorithms()
: simplifyMethod.tolerance();


query += QString( "%1(%5(%2%3,%6),'%4')" ) query += QString( "%1(%5(%2%3,%6),'%4')" )
.arg( P->mConnectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" ) .arg( P->mConnectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
Expand Down

0 comments on commit f6f0384

Please sign in to comment.