Skip to content

Commit

Permalink
fix(geometry_checker): do not call crs() on layer from another thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Djedouas authored and nyalldawson committed Aug 1, 2024
1 parent b358ab8 commit fa961c7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The geometry will not be reprojected regardless of useMapCrs.
%End



QString layerId() const;
%Docstring
The layer id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The geometry will not be reprojected regardless of useMapCrs.
%End



QString layerId() const;
%Docstring
The layer id.
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/geometry_checker/qgsgeometrychecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
{
const QMap<QgsFeatureId, QList<QgsGeometryCheck::Change>> &layerChanges = it.value();
QgsFeaturePool *featurePool = mFeaturePools[it.key()];
QgsCoordinateTransform t( featurePool->layer()->crs(), mContext->mapCrs, QgsProject::instance() );
QgsCoordinateTransform t( featurePool->crs(), mContext->mapCrs, QgsProject::instance() );
t.setBallparkTransformsAreAppropriate( true );
for ( auto layerChangeIt = layerChanges.constBegin(); layerChangeIt != layerChanges.constEnd(); ++layerChangeIt )
{
Expand Down Expand Up @@ -189,7 +189,7 @@ bool QgsGeometryChecker::fixError( QgsGeometryCheckError *error, int method, boo
for ( auto it = mFeaturePools.constBegin(); it != mFeaturePools.constEnd(); it++ )
{
QgsFeaturePool *featurePool = it.value();
QgsCoordinateTransform t( mContext->mapCrs, featurePool->layer()->crs(), QgsProject::instance() );
QgsCoordinateTransform t( mContext->mapCrs, featurePool->crs(), QgsProject::instance() );
recheckAreaFeatures[it.key()] = featurePool->getIntersects( t.transform( recheckArea ) );
}

Expand Down
20 changes: 8 additions & 12 deletions src/analysis/vector/geometry_checker/qgsgeometrycheckerror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,15 @@ QgsGeometryCheckError::QgsGeometryCheckError( const QgsGeometryCheck *check,
}
if ( !layerFeature.useMapCrs() )
{
QgsVectorLayer *vl = layerFeature.layer().data();
if ( vl )
const QgsCoordinateTransform ct( layerFeature.layerCrs(), check->context()->mapCrs, check->context()->transformContext );
try
{
const QgsCoordinateTransform ct( vl->crs(), check->context()->mapCrs, check->context()->transformContext );
try
{
mGeometry.transform( ct );
mErrorLocation = ct.transform( mErrorLocation );
}
catch ( const QgsCsException & )
{
QgsDebugError( QStringLiteral( "Can not show error in current map coordinate reference system" ) );
}
mGeometry.transform( ct );
mErrorLocation = ct.transform( mErrorLocation );
}
catch ( const QgsCsException & )
{
QgsDebugError( QStringLiteral( "Can not show error in current map coordinate reference system" ) );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ QgsFeature QgsGeometryCheckerUtils::LayerFeature::feature() const
return mFeature;
}

QgsCoordinateReferenceSystem QgsGeometryCheckerUtils::LayerFeature::layerCrs() const
{
return mFeaturePool->crs();
}

QPointer<QgsVectorLayer> QgsGeometryCheckerUtils::LayerFeature::layer() const
{
return mFeaturePool->layerPtr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class ANALYSIS_EXPORT QgsGeometryCheckerUtils
*/
QgsFeature feature() const;

/**
* The layer CRS.
*/
QgsCoordinateReferenceSystem layerCrs() const SIP_SKIP;

/**
* The layer.
*/
Expand Down

0 comments on commit fa961c7

Please sign in to comment.