82 changes: 82 additions & 0 deletions src/providers/ogr/qgsogrgeometrysimplifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/***************************************************************************
qgsogrgeometrysimplifier.h
---------------------
begin : December 2013
copyright : (C) 2013 by Alvaro Huarte
email : http://wiki.osgeo.org/wiki/Alvaro_Huarte
***************************************************************************
* *
* 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 QGSOGRGEOMETRYSIMPLIFIER_H
#define QGSOGRGEOMETRYSIMPLIFIER_H

#include "qgsmaptopixelgeometrysimplifier.h"
#include <ogr_geometry.h>

/**
* Abstract base class for simplify OGR-geometries using a specific algorithm
*/
class QgsOgrAbstractGeometrySimplifier
{
public:
virtual ~QgsOgrAbstractGeometrySimplifier();

//! Simplifies the specified geometry
virtual bool simplifyGeometry( OGRGeometry* geometry ) = 0;
};

/**
* OGR Implementation of GeometrySimplifier using the Douglas-Peucker algorithm
*
* Simplifies a geometry, ensuring that the result is a valid geometry having the same dimension and number of components as the input.
* The simplification uses a maximum distance difference algorithm similar to the one used in the Douglas-Peucker algorithm.
*/
class QgsOgrTopologyPreservingSimplifier : public QgsOgrAbstractGeometrySimplifier, QgsTopologyPreservingSimplifier
{
public:
QgsOgrTopologyPreservingSimplifier( double tolerance );
virtual ~QgsOgrTopologyPreservingSimplifier();

//! Simplifies the specified geometry
virtual bool simplifyGeometry( OGRGeometry* geometry );
};

/**
* OGR implementation of GeometrySimplifier using the "MapToPixel" algorithm
*
* Simplifies a geometry removing points within of the maximum distance difference that defines the MapToPixel info of a RenderContext request.
* This class enables simplify the geometries to be rendered in a MapCanvas target to speed up the vector drawing.
*/
class QgsOgrMapToPixelSimplifier : public QgsOgrAbstractGeometrySimplifier, QgsMapToPixelSimplifier
{
public:
QgsOgrMapToPixelSimplifier( int simplifyFlags, double map2pixelTol );
virtual ~QgsOgrMapToPixelSimplifier();

private:
//! Point memory buffer for optimize the simplification process
OGRRawPoint* mPointBufferPtr;
//! Current Point memory buffer size
int mPointBufferCount;

//! Simplifies the OGR-geometry (Removing duplicated points) when is applied the specified map2pixel context
bool simplifyOgrGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount );
//! Simplifies the OGR-geometry (Removing duplicated points) when is applied the specified map2pixel context
bool simplifyOgrGeometry( OGRGeometry* geometry, bool isaLinearRing );

//! Returns a point buffer of the specified size
OGRRawPoint* mallocPoints( int numPoints );

public:
//! Simplifies the specified geometry
virtual bool simplifyGeometry( OGRGeometry* geometry );
};

#endif // QGSOGRGEOMETRYSIMPLIFIER_H
3 changes: 3 additions & 0 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,9 @@ int QgsOgrProvider::capabilities() const
ability &= ~( AddAttributes | DeleteFeatures );
}
}

// supports geometry simplification on provider side
ability |= QgsVectorDataProvider::SimplifyGeometries;
}

return ability;
Expand Down