Skip to content

Commit

Permalink
[processing] Try directly interpreting string as CRS first
Browse files Browse the repository at this point in the history
...before falling back to alternatives like treating it as a map
layer

Fixes #57494
  • Loading branch information
nyalldawson committed May 23, 2024
1 parent 23ab4eb commit 53e5b34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,13 @@ QString QgsProcessingParameterCrs::valueAsPythonString( const QVariant &value, Q

QString QgsProcessingParameterCrs::valueAsString( const QVariant &value, QgsProcessingContext &context, bool &ok ) const
{
if ( value.type() == QVariant::String )
{
const QgsCoordinateReferenceSystem crs( value.toString() );
if ( crs.isValid() )
return value.toString();
}

return valueAsStringPrivate( value, context, ok, ValueAsStringFlag::AllowMapLayerValues );
}

Expand Down
11 changes: 7 additions & 4 deletions src/core/processing/qgsprocessingutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,14 +675,17 @@ QgsCoordinateReferenceSystem QgsProcessingUtils::variantToCrs( const QVariant &v
if ( context.project() && crsText.compare( QLatin1String( "ProjectCrs" ), Qt::CaseInsensitive ) == 0 )
return context.project()->crs();

// else CRS from string
const QgsCoordinateReferenceSystem crs( crsText );
if ( crs.isValid() )
return crs;

// maybe a map layer reference
if ( QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( crsText, context ) )
return layer->crs();

// else CRS from string
QgsCoordinateReferenceSystem crs;
crs.createFromString( crsText );
return crs;
// no luck!
return QgsCoordinateReferenceSystem();
}

bool QgsProcessingUtils::canUseLayer( const QgsMeshLayer *layer )
Expand Down

0 comments on commit 53e5b34

Please sign in to comment.