mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
#87525R: refactoring and minor changes
This commit is contained in:
parent
12a463d2b0
commit
f6f0384c6b
@ -29,9 +29,6 @@ class QgsSimplifyMethod
|
||||
/** Gets the tolerance of simplification */
|
||||
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 */
|
||||
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 */
|
||||
|
@ -18,9 +18,9 @@
|
||||
#include "qgsmaptopixelgeometrysimplifier.h"
|
||||
#include "qgsapplication.h"
|
||||
|
||||
QgsMapToPixelSimplifier::QgsMapToPixelSimplifier( int simplifyFlags, double map2pixelTol )
|
||||
QgsMapToPixelSimplifier::QgsMapToPixelSimplifier( int simplifyFlags, double tolerance )
|
||||
: mSimplifyFlags( simplifyFlags )
|
||||
, mMapToPixelTol( map2pixelTol )
|
||||
, mTolerance( tolerance )
|
||||
{
|
||||
}
|
||||
QgsMapToPixelSimplifier::~QgsMapToPixelSimplifier()
|
||||
@ -330,13 +330,13 @@ QgsGeometry* QgsMapToPixelSimplifier::simplify( QgsGeometry* geometry ) const
|
||||
unsigned char* wkb = ( unsigned char* )malloc( wkbSize );
|
||||
memcpy( wkb, geometry->asWkb(), wkbSize );
|
||||
g->fromWkb( wkb, wkbSize );
|
||||
simplifyGeometry( g, mSimplifyFlags, mMapToPixelTol );
|
||||
simplifyGeometry( g, mSimplifyFlags, mTolerance );
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
//! 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;
|
||||
|
||||
@ -351,7 +351,7 @@ bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry, int simpl
|
||||
size_t wkbSize = geometry->wkbSize( );
|
||||
|
||||
// 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 );
|
||||
memcpy( targetWkb, wkb, targetWkbSize );
|
||||
@ -364,5 +364,5 @@ bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry, int simpl
|
||||
//! Simplifies the geometry (Removing duplicated points) when is applied the specified map2pixel context
|
||||
bool QgsMapToPixelSimplifier::simplifyGeometry( QgsGeometry* geometry ) const
|
||||
{
|
||||
return simplifyGeometry( geometry, mSimplifyFlags, mMapToPixelTol );
|
||||
return simplifyGeometry( geometry, mSimplifyFlags, mTolerance );
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
|
||||
{
|
||||
public:
|
||||
QgsMapToPixelSimplifier( int simplifyFlags, double map2pixelTol );
|
||||
QgsMapToPixelSimplifier( int simplifyFlags, double tolerance );
|
||||
virtual ~QgsMapToPixelSimplifier();
|
||||
|
||||
//! Applicable simplification flags
|
||||
@ -51,8 +51,8 @@ class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
|
||||
//! Current simplification flags
|
||||
int mSimplifyFlags;
|
||||
|
||||
//! Map2Pixel tolerance for the simplification
|
||||
double mMapToPixelTol;
|
||||
//! Distance tolerance for the simplification
|
||||
double mTolerance;
|
||||
|
||||
//! 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 );
|
||||
@ -73,10 +73,10 @@ class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
|
||||
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
|
||||
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
|
||||
static bool simplifyGeometry( QgsGeometry* geometry, int simplifyFlags, double map2pixelTol );
|
||||
static bool simplifyGeometry( QgsGeometry* geometry, int simplifyFlags, double tolerance );
|
||||
|
||||
};
|
||||
|
||||
|
@ -54,12 +54,6 @@ void QgsSimplifyMethod::setForceLocalOptimization( bool 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 )
|
||||
{
|
||||
QgsSimplifyMethod::MethodType methodType = simplifyMethod.methodType();
|
||||
|
@ -48,9 +48,6 @@ class CORE_EXPORT QgsSimplifyMethod
|
||||
//! Gets the tolerance of simplification
|
||||
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
|
||||
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
|
||||
|
@ -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)
|
||||
|
||||
QgsOgrMapToPixelSimplifier::QgsOgrMapToPixelSimplifier( int simplifyFlags, double map2pixelTol )
|
||||
: QgsMapToPixelSimplifier( simplifyFlags, map2pixelTol )
|
||||
QgsOgrMapToPixelSimplifier::QgsOgrMapToPixelSimplifier( int simplifyFlags, double tolerance )
|
||||
: QgsMapToPixelSimplifier( simplifyFlags, tolerance )
|
||||
, mPointBufferPtr( NULL )
|
||||
, mPointBufferCount( 0 )
|
||||
{
|
||||
@ -136,7 +136,7 @@ bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( QGis::GeometryType geometr
|
||||
if ( geometryType == QGis::Point || geometryType == QGis::UnknownGeometry ) return false;
|
||||
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;
|
||||
|
||||
char* xsourcePtr = ( char* )xptr;
|
||||
|
@ -62,7 +62,7 @@ class QgsOgrTopologyPreservingSimplifier : public QgsOgrAbstractGeometrySimplifi
|
||||
class QgsOgrMapToPixelSimplifier : public QgsOgrAbstractGeometrySimplifier, QgsMapToPixelSimplifier
|
||||
{
|
||||
public:
|
||||
QgsOgrMapToPixelSimplifier( int simplifyFlags, double map2pixelTol );
|
||||
QgsOgrMapToPixelSimplifier( int simplifyFlags, double tolerance );
|
||||
virtual ~QgsOgrMapToPixelSimplifier();
|
||||
|
||||
private:
|
||||
|
@ -303,11 +303,9 @@ bool QgsPostgresFeatureIterator::declareCursor( const QString& whereClause )
|
||||
{
|
||||
QString simplifyFunctionName = simplifyMethod.methodType() == QgsSimplifyMethod::OptimizeForRendering
|
||||
? ( 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
|
||||
? simplifyMethod.toleranceForDouglasPeuckerAlgorithms()
|
||||
: simplifyMethod.tolerance();
|
||||
double tolerance = simplifyMethod.tolerance();
|
||||
|
||||
query += QString( "%1(%5(%2%3,%6),'%4')" )
|
||||
.arg( P->mConnectionRO->majorVersion() < 2 ? "asbinary" : "st_asbinary" )
|
||||
|
Loading…
x
Reference in New Issue
Block a user