Skip to content

Commit

Permalink
qgsvectorlayerprofilegenerator: Add support for custom tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitjano authored and lbartoletti committed Jan 13, 2025
1 parent 45902c7 commit 7c56654
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/core/vector/qgsvectorlayerprofilegenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ QgsVectorLayerProfileGenerator::QgsVectorLayerProfileGenerator( QgsVectorLayer *
, mBinding( qgis::down_cast< QgsVectorLayerElevationProperties * >( layer->elevationProperties() )->binding() )
, mExtrusionEnabled( qgis::down_cast< QgsVectorLayerElevationProperties * >( layer->elevationProperties() )->extrusionEnabled() )
, mExtrusionHeight( qgis::down_cast< QgsVectorLayerElevationProperties * >( layer->elevationProperties() )->extrusionHeight() )
, mCustomToleranceEnabled( qgis::down_cast< QgsVectorLayerElevationProperties * >( layer->elevationProperties() )->customToleranceEnabled() )
, mCustomTolerance( qgis::down_cast< QgsVectorLayerElevationProperties * >( layer->elevationProperties() )->customTolerance() )
, mExpressionContext( request.expressionContext() )
, mFields( layer->fields() )
, mDataDefinedProperties( layer->elevationProperties()->dataDefinedProperties() )
Expand Down Expand Up @@ -818,13 +820,13 @@ bool QgsVectorLayerProfileGenerator::generateProfileInner( const QgsProfileGener
mProfileCurveEngine.reset( new QgsGeos( mProfileCurve.get() ) );
mProfileCurveEngine->prepareGeometry();

if ( mTolerance == 0.0 ) // geos does not handle very well buffer with 0 size
if ( tolerance() == 0.0 ) // geos does not handle very well buffer with 0 size
{
mProfileBufferedCurve = std::unique_ptr<QgsAbstractGeometry>( mProfileCurve->clone() );
}
else
{
mProfileBufferedCurve = std::unique_ptr<QgsAbstractGeometry>( mProfileCurveEngine->buffer( mTolerance, 8, Qgis::EndCapStyle::Flat, Qgis::JoinStyle::Round, 2 ) );
mProfileBufferedCurve = std::unique_ptr<QgsAbstractGeometry>( mProfileCurveEngine->buffer( tolerance(), 8, Qgis::EndCapStyle::Flat, Qgis::JoinStyle::Round, 2 ) );
}

mProfileBufferedCurveEngine.reset( new QgsGeos( mProfileBufferedCurve.get() ) );
Expand Down Expand Up @@ -875,7 +877,7 @@ bool QgsVectorLayerProfileGenerator::generateProfileForPoints()
// get features from layer
QgsFeatureRequest request;
request.setCoordinateTransform( QgsCoordinateTransform( mSourceCrs, mTargetCrs, mTransformContext ) );
request.setDistanceWithin( QgsGeometry( mProfileCurve->clone() ), mTolerance );
request.setDistanceWithin( QgsGeometry( mProfileCurve->clone() ), tolerance() );
request.setSubsetOfAttributes( mDataDefinedProperties.referencedFields( mExpressionContext ), mFields );
request.setFeedback( mFeedback.get() );

Expand Down Expand Up @@ -1038,9 +1040,9 @@ bool QgsVectorLayerProfileGenerator::generateProfileForLines()
// get features from layer
QgsFeatureRequest request;
request.setDestinationCrs( mTargetCrs, mTransformContext );
if ( mTolerance > 0 )
if ( tolerance() > 0 )
{
request.setDistanceWithin( QgsGeometry( mProfileCurve->clone() ), mTolerance );
request.setDistanceWithin( QgsGeometry( mProfileCurve->clone() ), tolerance() );
}
else
{
Expand Down Expand Up @@ -1330,9 +1332,9 @@ bool QgsVectorLayerProfileGenerator::generateProfileForPolygons()
// get features from layer
QgsFeatureRequest request;
request.setDestinationCrs( mTargetCrs, mTransformContext );
if ( mTolerance > 0 )
if ( tolerance() > 0 )
{
request.setDistanceWithin( QgsGeometry( mProfileCurve->clone() ), mTolerance );
request.setDistanceWithin( QgsGeometry( mProfileCurve->clone() ), tolerance() );
}
else
{
Expand Down Expand Up @@ -1403,7 +1405,7 @@ bool QgsVectorLayerProfileGenerator::generateProfileForPolygons()
if ( mFeedback->isCanceled() )
return;

if ( mTolerance > 0.0 ) // if the tolerance is not 0.0 we will have a polygon / polygon intersection, we do not need tessellation
if ( tolerance() > 0.0 ) // if the tolerance is not 0.0 we will have a polygon / polygon intersection, we do not need tessellation
{
QString error;
if ( mProfileBufferedCurveEngine->intersects( clampedPolygon.get(), &error ) )
Expand Down Expand Up @@ -1625,6 +1627,11 @@ bool QgsVectorLayerProfileGenerator::generateProfileForPolygons()
return true;
}

double QgsVectorLayerProfileGenerator::tolerance() const
{
return mCustomToleranceEnabled ? mCustomTolerance : mTolerance;
}

double QgsVectorLayerProfileGenerator::terrainHeight( double x, double y ) const
{
if ( !mTerrainProvider )
Expand Down
4 changes: 4 additions & 0 deletions src/core/vector/qgsvectorlayerprofilegenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class CORE_EXPORT QgsVectorLayerProfileGenerator : public QgsAbstractProfileSurf
void processTriangleIntersectForLine( const QgsPolygon *triangle, const QgsLineString *intersect, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts );
void processTriangleIntersectForPolygon( const QgsPolygon *triangle, const QgsPolygon *intersectionPolygon, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts );

double tolerance() const;

double terrainHeight( double x, double y ) const;
double featureZToHeight( double x, double y, double z, double offset ) const;

Expand Down Expand Up @@ -171,6 +173,8 @@ class CORE_EXPORT QgsVectorLayerProfileGenerator : public QgsAbstractProfileSurf
Qgis::AltitudeBinding mBinding = Qgis::AltitudeBinding::Centroid;
bool mExtrusionEnabled = false;
double mExtrusionHeight = 0;
bool mCustomToleranceEnabled = false;
double mCustomTolerance = 0;

QgsExpressionContext mExpressionContext;
QgsFields mFields;
Expand Down

0 comments on commit 7c56654

Please sign in to comment.