31   : mSimplifyFlags( simplifyFlags )
 
   32   , mSimplifyAlgorithm( simplifyAlgorithm )
 
   33   , mTolerance( tolerance )
 
   42   float vx = 
static_cast< float >( x2 - x1 );
 
   43   float vy = 
static_cast< float >( y2 - y1 );
 
   45   return ( vx * vx ) + ( vy * vy );
 
   50   int grid_x1 = std::round( ( x1 - gridOriginX ) * gridInverseSizeXY );
 
   51   int grid_x2 = std::round( ( x2 - gridOriginX ) * gridInverseSizeXY );
 
   52   if ( grid_x1 != grid_x2 ) 
return false;
 
   54   int grid_y1 = std::round( ( y1 - gridOriginY ) * gridInverseSizeXY );
 
   55   int grid_y2 = std::round( ( y2 - gridOriginY ) * gridInverseSizeXY );
 
   56   return grid_y1 == grid_y2;
 
   66 #include "simplify/effectivearea.h" 
   71 static std::unique_ptr< QgsAbstractGeometry > generalizeWkbGeometryByBoundingBox(
 
   84     return std::unique_ptr< QgsAbstractGeometry >( geometry.
clone() );
 
   87   const double x1 = envelope.
xMinimum();
 
   88   const double y1 = envelope.
yMinimum();
 
   89   const double x2 = envelope.
xMaximum();
 
   90   const double y2 = envelope.
yMaximum();
 
   95     return std::make_unique< QgsLineString >( QVector<double>() << x1 << x2, QVector<double>() << y1 << y2 );
 
   99     std::unique_ptr< QgsLineString > ext = std::make_unique< QgsLineString >(
 
  100         QVector< double >() << x1
 
  105         QVector< double >() << y1
 
  111       return std::move( ext );
 
  114       std::unique_ptr< QgsPolygon > polygon = std::make_unique< QgsPolygon >();
 
  115       polygon->setExteriorRing( ext.release() );
 
  116       return std::move( polygon );
 
  121 std::unique_ptr< QgsAbstractGeometry > QgsMapToPixelSimplifier::simplifyGeometry( 
int simplifyFlags,
 
  122     SimplifyAlgorithm simplifyAlgorithm,
 
  126   bool isGeneralizable = 
true;
 
  134     return generalizeWkbGeometryByBoundingBox( wkbType, geometry, envelope, isaLinearRing );
 
  138     isGeneralizable = 
false;
 
  146     const int numPoints = srcCurve.
numPoints();
 
  148     std::unique_ptr<QgsCurve> output;
 
  150     QVector< double > lineStringX;
 
  151     QVector< double > lineStringY;
 
  156       lineStringX.reserve( numPoints );
 
  157       lineStringY.reserve( numPoints );
 
  164     double x = 0.0, y = 0.0, lastX = 0.0, lastY = 0.0;
 
  166     if ( numPoints <= ( isaLinearRing ? 4 : 2 ) )
 
  167       isGeneralizable = 
false;
 
  170     bool hasLongSegments = 
false; 
 
  184         double gridOriginX = envelope.
xMinimum();
 
  185         double gridOriginY = envelope.
yMinimum();
 
  188         float gridInverseSizeXY = map2pixelTol != 0 ? ( float )( 1.0f / ( 0.8 * map2pixelTol ) ) : 0.0f;
 
  190         const double *xData = 
nullptr;
 
  191         const double *yData = 
nullptr;
 
  194           xData = qgsgeometry_cast< const QgsLineString * >( &srcCurve )->xData();
 
  195           yData = qgsgeometry_cast< const QgsLineString * >( &srcCurve )->yData();
 
  198         for ( 
int i = 0; i < numPoints; ++i )
 
  200           if ( xData && yData )
 
  207             x = srcCurve.
xAt( i );
 
  208             y = srcCurve.
yAt( i );
 
  213                !
equalSnapToGrid( x, y, lastX, lastY, gridOriginX, gridOriginY, gridInverseSizeXY ) ||
 
  214                ( !isaLinearRing && ( i == 1 || i >= numPoints - 2 ) ) )
 
  220               lineStringX.append( x );
 
  221               lineStringY.append( y );
 
  232         output.reset( qgsgeometry_cast< QgsCurve * >( srcCurve.
snappedToGrid( map2pixelTol, map2pixelTol ) ) );
 
  238         map2pixelTol *= map2pixelTol; 
 
  240         EFFECTIVE_AREAS ea( srcCurve );
 
  243         ptarray_calc_areas( &ea, isaLinearRing ? 4 : 2, set_area, map2pixelTol );
 
  245         for ( 
int i = 0; i < numPoints; ++i )
 
  247           if ( ea.res_arealist[ i ] > map2pixelTol )
 
  250               output->insertVertex( 
QgsVertexId( 0, 0, output->numPoints() ), ea.inpts.at( i ) );
 
  253               lineStringX.append( ea.inpts.at( i ).x() );
 
  254               lineStringY.append( ea.inpts.at( i ).y() );
 
  263         map2pixelTol *= map2pixelTol; 
 
  265         const double *xData = 
nullptr;
 
  266         const double *yData = 
nullptr;
 
  269           xData = qgsgeometry_cast< const QgsLineString * >( &srcCurve )->xData();
 
  270           yData = qgsgeometry_cast< const QgsLineString * >( &srcCurve )->yData();
 
  273         for ( 
int i = 0; i < numPoints; ++i )
 
  275           if ( xData && yData )
 
  282             x = srcCurve.
xAt( i );
 
  283             y = srcCurve.
yAt( i );
 
  286           isLongSegment = 
false;
 
  291                ( !isaLinearRing && ( i == 1 || i >= numPoints - 2 ) ) )
 
  297               lineStringX.append( x );
 
  298               lineStringY.append( y );
 
  303             hasLongSegments |= isLongSegment;
 
  311       output = std::make_unique< QgsLineString >( lineStringX, lineStringY );
 
  313     if ( output->numPoints() < ( isaLinearRing ? 4 : 2 ) )
 
  316       if ( !hasLongSegments )
 
  320         return generalizeWkbGeometryByBoundingBox( wkbType, geometry, envelope, isaLinearRing );
 
  327         return std::unique_ptr< QgsAbstractGeometry >( geometry.
clone() );
 
  336         output->insertVertex( 
QgsVertexId( 0, 0, output->numPoints() ), 
QgsPoint( output->xAt( 0 ), output->yAt( 0 ) ) );
 
  340     return std::move( output );
 
  345     std::unique_ptr<QgsPolygon> polygon( 
new QgsPolygon() );
 
  347     polygon->setExteriorRing( qgsgeometry_cast<QgsCurve *>( extRing.release() ) );
 
  352       polygon->addInteriorRing( qgsgeometry_cast<QgsCurve *>( ring.release() ) );
 
  354     return std::move( polygon );
 
  361     collection->reserve( numGeoms );
 
  362     for ( 
int i = 0; i < numGeoms; ++i )
 
  366       collection->addGeometry( part.release() );
 
  368     return std::move( collection );
 
  370   return std::unique_ptr< QgsAbstractGeometry >( geometry.
clone() );
 
  378   return envelope.
width() < map2pixelTol && envelope.
height() < map2pixelTol;
 
  403   if ( numPoints <= ( isaLinearRing ? 6 : 3 ) )
 
  447   if ( numPoints <= ( isaLinearRing ? 6 : 3 ) )
 
Abstract base class for all geometries.
virtual QgsRectangle boundingBox() const =0
Returns the minimal bounding box for the geometry.
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
virtual QgsAbstractGeometry * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const =0
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
const QgsCurve * interiorRing(int i) const SIP_HOLDGIL
Retrieves an interior ring from the curve polygon.
const QgsCurve * exteriorRing() const SIP_HOLDGIL
Returns the curve polygon's exterior ring.
int numInteriorRings() const SIP_HOLDGIL
Returns the number of interior rings contained with the curve polygon.
Abstract base class for curved geometry type.
virtual int numPoints() const =0
Returns the number of points in the curve.
virtual double xAt(int index) const =0
Returns the x-coordinate of the specified node in the line string.
virtual double yAt(int index) const =0
Returns the y-coordinate of the specified node in the line string.
int numGeometries() const SIP_HOLDGIL
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
QgsGeometryCollection * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
double mTolerance
Distance tolerance for the simplification.
static float calculateLengthSquared2D(double x1, double y1, double x2, double y2)
Returns the squared 2D-distance of the vector defined by the two points specified.
SimplifyAlgorithm
Types of simplification algorithms that can be used.
@ Visvalingam
The simplification gives each point in a line an importance weighting, so that least important points...
@ SnapToGrid
The simplification uses a grid (similar to ST_SnapToGrid) to remove duplicate points.
@ Distance
The simplification uses the distance between points to remove duplicate points.
@ SnappedToGridGlobal
Snap to a global grid based on the tolerance. Good for consistent results for incoming vertices,...
static bool isGeneralizableByMapBoundingBox(const QgsRectangle &envelope, double map2pixelTol)
Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel cont...
int simplifyFlags() const
Gets the simplification hints of the vector layer managed.
QgsMapToPixelSimplifier(int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm=Distance)
Constructor.
SimplifyAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
@ NoFlags
No simplification can be applied.
@ SimplifyEnvelope
The geometries can be fully simplified by its BoundingBox.
@ SimplifyGeometry
The geometries can be simplified using the current map2pixel context state.
int mSimplifyFlags
Current simplification flags.
static bool equalSnapToGrid(double x1, double y1, double x2, double y2, double gridOriginX, double gridOriginY, float gridInverseSizeXY)
Returns whether the points belong to the same grid.
QgsGeometry simplify(const QgsGeometry &geometry) const override
Returns a simplified version the specified geometry.
SimplifyAlgorithm mSimplifyAlgorithm
Current algorithm.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
static bool isMultiType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a multi type.
Type
The WKB type describes the number of dimensions a geometry has.
static Type singleType(Type type) SIP_HOLDGIL
Returns the single type for a WKB type.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Utility class for identifying a unique vertex within a geometry.