mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Use a more appropriate, global snap to grid algorithm when simplifying
geometries for layout exports This avoids all chance of slivers or overlaps between previously adjacent features.
This commit is contained in:
parent
d8d23b56ea
commit
0419f182d8
@ -28,6 +28,7 @@ This class enables simplify the geometries to be rendered in a MapCanvas target
|
||||
Distance,
|
||||
SnapToGrid,
|
||||
Visvalingam,
|
||||
SnappedToGridGlobal,
|
||||
};
|
||||
|
||||
QgsMapToPixelSimplifier( int simplifyFlags, double tolerance, SimplifyAlgorithm simplifyAlgorithm = Distance );
|
||||
|
@ -53,6 +53,7 @@ Gets the simplification hints of the vector layer managed
|
||||
Distance,
|
||||
SnapToGrid,
|
||||
Visvalingam,
|
||||
SnappedToGridGlobal,
|
||||
};
|
||||
|
||||
void setSimplifyAlgorithm( SimplifyAlgorithm simplifyAlgorithm );
|
||||
|
@ -1471,8 +1471,9 @@ QgsVectorSimplifyMethod QgsLayoutExporter::createExportSimplifyMethod()
|
||||
QgsVectorSimplifyMethod simplifyMethod;
|
||||
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::GeometrySimplification );
|
||||
simplifyMethod.setForceLocalOptimization( true );
|
||||
simplifyMethod.setSimplifyAlgorithm( QgsVectorSimplifyMethod::SnapToGrid );
|
||||
simplifyMethod.setThreshold( 0.5 ); // pixels
|
||||
// we use SnappedToGridGlobal, because it avoids gaps and slivers between previously adjacent polygons
|
||||
simplifyMethod.setSimplifyAlgorithm( QgsVectorSimplifyMethod::SnappedToGridGlobal );
|
||||
simplifyMethod.setThreshold( 0.1f ); // (pixels). We are quite conservative here. This could possibly be bumped all the way up to 1. But let's play it safe.
|
||||
return simplifyMethod;
|
||||
}
|
||||
|
||||
|
@ -227,6 +227,12 @@ std::unique_ptr< QgsAbstractGeometry > QgsMapToPixelSimplifier::simplifyGeometry
|
||||
break;
|
||||
}
|
||||
|
||||
case SnappedToGridGlobal:
|
||||
{
|
||||
output.reset( qgsgeometry_cast< QgsCurve * >( srcCurve.snappedToGrid( map2pixelTol, map2pixelTol ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
case Visvalingam:
|
||||
{
|
||||
map2pixelTol *= map2pixelTol; //-> Use mappixelTol for 'Area' calculations.
|
||||
|
@ -44,6 +44,7 @@ class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
|
||||
Distance = 0, //!< The simplification uses the distance between points to remove duplicate points
|
||||
SnapToGrid = 1, //!< The simplification uses a grid (similar to ST_SnapToGrid) to remove duplicate points
|
||||
Visvalingam = 2, //!< The simplification gives each point in a line an importance weighting, so that least important points are removed first
|
||||
SnappedToGridGlobal = 3, //!< Snap to a global grid based on the tolerance. Good for consistent results for incoming vertices, regardless of their feature
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
|
@ -56,6 +56,7 @@ class CORE_EXPORT QgsVectorSimplifyMethod
|
||||
Distance = 0, //!< The simplification uses the distance between points to remove duplicate points
|
||||
SnapToGrid = 1, //!< The simplification uses a grid (similar to ST_SnapToGrid) to remove duplicate points
|
||||
Visvalingam = 2, //!< The simplification gives each point in a line an importance weighting, so that least important points are removed first
|
||||
SnappedToGridGlobal = 3, //!< Snap to a global grid based on the tolerance. Good for consistent results for incoming vertices, regardless of their feature
|
||||
};
|
||||
Q_ENUM( SimplifyAlgorithm )
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user