mirror of
https://github.com/qgis/QGIS.git
synced 2025-06-19 00:02:48 -04:00
Do not store context in layer (but in provider) ...
... also use transform context in raster projector and deprecate setCrs without context
This commit is contained in:
parent
7f52e2938a
commit
b3a448a2b2
@ -202,9 +202,9 @@ Interpolates the value on the given point from given dataset.
|
||||
|
||||
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext );
|
||||
%Docstring
|
||||
Triggered when the coordinate transform context has changed ``transformContext``
|
||||
Sets the coordinate transform context to ``transformContext``.
|
||||
|
||||
.. versionadded:: 3.10
|
||||
.. versionadded:: 3.8
|
||||
%End
|
||||
|
||||
|
||||
|
@ -387,26 +387,7 @@ Returns ``True`` if metadata was successfully written to the data provider.
|
||||
.. versionadded:: 3.0
|
||||
%End
|
||||
|
||||
QgsCoordinateTransformContext transformContext() const;
|
||||
%Docstring
|
||||
Returns data provider coordinate transform context
|
||||
|
||||
.. seealso:: :py:func:`setTransformContext`
|
||||
|
||||
.. versionadded:: 3.10
|
||||
%End
|
||||
|
||||
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext );
|
||||
%Docstring
|
||||
Sets data coordinate transform context to ``transformContext``
|
||||
|
||||
The default implementation is a simple setter, subclasses may override to perform
|
||||
additional actions required by a change of coordinate transform context.
|
||||
|
||||
.. seealso:: :py:func:`transformContext`
|
||||
|
||||
.. versionadded:: 3.10
|
||||
%End
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -2346,9 +2346,9 @@ rollBack().
|
||||
|
||||
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext );
|
||||
%Docstring
|
||||
Triggered when the coordinate transform context has changed ``transformContext``
|
||||
Sets the coordinate transform context to ``transformContext``
|
||||
|
||||
.. versionadded:: 3.10
|
||||
.. versionadded:: 3.8
|
||||
%End
|
||||
|
||||
signals:
|
||||
|
@ -386,9 +386,9 @@ Writes the symbology of the layer into the document provided in SLD 1.0.0 format
|
||||
|
||||
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext );
|
||||
%Docstring
|
||||
Triggered when the coordinate transform context has changed ``transformContext``
|
||||
Sets the coordinate transform context to ``transformContext``
|
||||
|
||||
.. versionadded:: 3.10
|
||||
.. versionadded:: 3.8
|
||||
%End
|
||||
|
||||
protected:
|
||||
|
@ -46,10 +46,20 @@ which are used to calculate affine transformation matrices.
|
||||
virtual Qgis::DataType dataType( int bandNo ) const;
|
||||
|
||||
|
||||
void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
|
||||
int srcDatumTransform = -1, int destDatumTransform = -1 );
|
||||
void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
|
||||
int srcDatumTransform = -1, int destDatumTransform = -1 ) /Deprecated/;
|
||||
%Docstring
|
||||
Sets the source and destination CRS
|
||||
|
||||
.. deprecated:: since QGIS 3.8, use transformContext version instead
|
||||
%End
|
||||
|
||||
void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
|
||||
QgsCoordinateTransformContext transformContext );
|
||||
%Docstring
|
||||
Sets source CRS to ``srcCRS`` and destination CRS to ``destCRS`` and the transformation context to ``transformContext``
|
||||
|
||||
.. versionadded:: 3.8
|
||||
%End
|
||||
|
||||
QgsCoordinateReferenceSystem sourceCrs() const;
|
||||
|
@ -41,7 +41,6 @@ QgsMeshLayer::QgsMeshLayer( const QString &meshLayerPath,
|
||||
const QString &providerKey,
|
||||
const QgsMeshLayer::LayerOptions &options )
|
||||
: QgsMapLayer( QgsMapLayerType::MeshLayer, baseName, meshLayerPath )
|
||||
, mOptions( options )
|
||||
{
|
||||
setProviderType( providerKey );
|
||||
// if we’re given a provider type, try to create and bind one to this layer
|
||||
@ -89,7 +88,12 @@ const QgsMeshDataProvider *QgsMeshLayer::dataProvider() const
|
||||
|
||||
QgsMeshLayer *QgsMeshLayer::clone() const
|
||||
{
|
||||
QgsMeshLayer *layer = new QgsMeshLayer( source(), name(), mProviderKey, mOptions );
|
||||
QgsMeshLayer::LayerOptions options;
|
||||
if ( mDataProvider )
|
||||
{
|
||||
options.transformContext = mDataProvider->transformContext();
|
||||
}
|
||||
QgsMeshLayer *layer = new QgsMeshLayer( source(), name(), mProviderKey, options );
|
||||
QgsMapLayer::clone( layer );
|
||||
return layer;
|
||||
}
|
||||
|
@ -231,9 +231,9 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
|
||||
public slots:
|
||||
|
||||
/**
|
||||
* Triggered when the coordinate transform context has changed \a transformContext
|
||||
* Sets the coordinate transform context to \a transformContext.
|
||||
*
|
||||
* \since QGIS 3.10
|
||||
* \since QGIS 3.8
|
||||
*/
|
||||
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
|
||||
|
||||
@ -306,8 +306,6 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
|
||||
//! Time format configuration
|
||||
QgsMeshTimeSettings mTimeSettings;
|
||||
|
||||
//! Layer options
|
||||
QgsMeshLayer::LayerOptions mOptions;
|
||||
};
|
||||
|
||||
#endif //QGSMESHLAYER_H
|
||||
|
@ -527,9 +527,10 @@ class CORE_EXPORT QgsDataProvider : public QObject
|
||||
*
|
||||
* \see setTransformContext()
|
||||
*
|
||||
* \since QGIS 3.10
|
||||
* \since QGIS 3.8
|
||||
* \note not available in Python bindings
|
||||
*/
|
||||
QgsCoordinateTransformContext transformContext() const;
|
||||
QgsCoordinateTransformContext transformContext() const SIP_SKIP;
|
||||
|
||||
/**
|
||||
* Sets data coordinate transform context to \a transformContext
|
||||
@ -539,9 +540,10 @@ class CORE_EXPORT QgsDataProvider : public QObject
|
||||
*
|
||||
* \see transformContext()
|
||||
*
|
||||
* \since QGIS 3.10
|
||||
* \since QGIS 3.8
|
||||
* \note not available in Python bindings
|
||||
*/
|
||||
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext );
|
||||
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -147,7 +147,6 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
|
||||
, mAuxiliaryLayer( nullptr )
|
||||
, mAuxiliaryLayerKey( QString() )
|
||||
, mReadExtentFromXml( options.readExtentFromXml )
|
||||
, mOptions( options )
|
||||
{
|
||||
setProviderType( providerKey );
|
||||
|
||||
@ -208,7 +207,12 @@ QgsVectorLayer::~QgsVectorLayer()
|
||||
|
||||
QgsVectorLayer *QgsVectorLayer::clone() const
|
||||
{
|
||||
QgsVectorLayer *layer = new QgsVectorLayer( source(), name(), mProviderKey, mOptions );
|
||||
QgsVectorLayer::LayerOptions options;
|
||||
if ( mDataProvider )
|
||||
{
|
||||
options.transformContext = mDataProvider->transformContext();
|
||||
}
|
||||
QgsVectorLayer *layer = new QgsVectorLayer( source(), name(), mProviderKey, options );
|
||||
QgsMapLayer::clone( layer );
|
||||
|
||||
QList<QgsVectorLayerJoinInfo> joins = vectorJoins();
|
||||
|
@ -2161,9 +2161,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
|
||||
bool startEditing();
|
||||
|
||||
/**
|
||||
* Triggered when the coordinate transform context has changed \a transformContext
|
||||
* Sets the coordinate transform context to \a transformContext
|
||||
*
|
||||
* \since QGIS 3.10
|
||||
* \since QGIS 3.8
|
||||
*/
|
||||
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
|
||||
|
||||
@ -2593,8 +2593,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
|
||||
|
||||
bool mAllowCommit = true;
|
||||
|
||||
QgsVectorLayer::LayerOptions mOptions;
|
||||
|
||||
friend class QgsVectorLayerFeatureSource;
|
||||
};
|
||||
|
||||
|
@ -137,7 +137,12 @@ QgsRasterLayer::~QgsRasterLayer()
|
||||
|
||||
QgsRasterLayer *QgsRasterLayer::clone() const
|
||||
{
|
||||
QgsRasterLayer *layer = new QgsRasterLayer( source(), name(), mProviderKey );
|
||||
QgsRasterLayer::LayerOptions options;
|
||||
if ( mDataProvider )
|
||||
{
|
||||
options.transformContext = mDataProvider->transformContext();
|
||||
}
|
||||
QgsRasterLayer *layer = new QgsRasterLayer( source(), name(), mProviderKey, options );
|
||||
QgsMapLayer::clone( layer );
|
||||
|
||||
// do not clone data provider which is the first element in pipe
|
||||
|
@ -185,7 +185,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
|
||||
|
||||
/**
|
||||
* Coordinate transform context
|
||||
* \since QGIS 3.10
|
||||
* \since QGIS 3.8
|
||||
*/
|
||||
QgsCoordinateTransformContext transformContext = QgsCoordinateTransformContext();
|
||||
|
||||
@ -439,9 +439,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
|
||||
void showStatusMessage( const QString &message );
|
||||
|
||||
/**
|
||||
* Triggered when the coordinate transform context has changed \a transformContext
|
||||
* Sets the coordinate transform context to \a transformContext
|
||||
*
|
||||
* \since QGIS 3.10
|
||||
* \since QGIS 3.8
|
||||
*/
|
||||
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) override;
|
||||
|
||||
|
@ -39,6 +39,7 @@ QgsRasterProjector *QgsRasterProjector::clone() const
|
||||
projector->mSrcDatumTransform = mSrcDatumTransform;
|
||||
projector->mDestDatumTransform = mDestDatumTransform;
|
||||
projector->mPrecision = mPrecision;
|
||||
projector->mTransformContext = mTransformContext;
|
||||
return projector;
|
||||
}
|
||||
|
||||
@ -60,12 +61,24 @@ Qgis::DataType QgsRasterProjector::dataType( int bandNo ) const
|
||||
/// @cond PRIVATE
|
||||
|
||||
|
||||
void QgsRasterProjector::setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform, int destDatumTransform )
|
||||
void QgsRasterProjector::setCrs( const QgsCoordinateReferenceSystem &srcCRS,
|
||||
const QgsCoordinateReferenceSystem &destCRS,
|
||||
int srcDatumTransform,
|
||||
int destDatumTransform )
|
||||
{
|
||||
mSrcCRS = srcCRS;
|
||||
mDestCRS = destCRS;
|
||||
mSrcDatumTransform = srcDatumTransform;
|
||||
mDestDatumTransform = destDatumTransform;
|
||||
mTransformContext = QgsCoordinateTransformContext();
|
||||
mTransformContext.addSourceDestinationDatumTransform( srcCRS, destCRS, srcDatumTransform, destDatumTransform );
|
||||
}
|
||||
|
||||
void QgsRasterProjector::setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, QgsCoordinateTransformContext transformContext )
|
||||
{
|
||||
mSrcCRS = srcCRS;
|
||||
mDestCRS = destCRS;
|
||||
mTransformContext = transformContext;
|
||||
}
|
||||
|
||||
|
||||
@ -747,13 +760,23 @@ QgsRasterBlock *QgsRasterProjector::block( int bandNo, QgsRectangle const &exte
|
||||
if ( feedback && feedback->isCanceled() )
|
||||
return new QgsRasterBlock();
|
||||
|
||||
// TODO: check if the last condition always apply to context
|
||||
if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS )
|
||||
{
|
||||
QgsDebugMsgLevel( QStringLiteral( "No projection necessary" ), 4 );
|
||||
return mInput->block( bandNo, extent, width, height, feedback );
|
||||
}
|
||||
|
||||
QgsCoordinateTransform inverseCt( mDestCRS, mSrcCRS, mDestDatumTransform, mSrcDatumTransform );
|
||||
QgsCoordinateTransform inverseCt;
|
||||
|
||||
if ( mSrcDatumTransform != -1 && mDestDatumTransform != -1 )
|
||||
{
|
||||
inverseCt = QgsCoordinateTransform( mDestCRS, mSrcCRS, mDestDatumTransform, mSrcDatumTransform );
|
||||
}
|
||||
else
|
||||
{
|
||||
inverseCt = QgsCoordinateTransform( mDestCRS, mSrcCRS, mTransformContext );
|
||||
}
|
||||
|
||||
ProjectorData pd( extent, width, height, mInput, inverseCt, mPrecision );
|
||||
|
||||
@ -774,7 +797,7 @@ QgsRasterBlock *QgsRasterProjector::block( int bandNo, QgsRectangle const &exte
|
||||
return new QgsRasterBlock();
|
||||
}
|
||||
|
||||
qgssize pixelSize = QgsRasterBlock::typeSize( mInput->dataType( bandNo ) );
|
||||
qgssize pixelSize = static_cast<qgssize>( QgsRasterBlock::typeSize( mInput->dataType( bandNo ) ) );
|
||||
|
||||
std::unique_ptr< QgsRasterBlock > outputBlock( new QgsRasterBlock( inputBlock->dataType(), width, height ) );
|
||||
if ( inputBlock->hasNoDataValue() )
|
||||
@ -814,7 +837,7 @@ QgsRasterBlock *QgsRasterProjector::block( int bandNo, QgsRectangle const &exte
|
||||
bool inside = pd.srcRowCol( i, j, &srcRow, &srcCol );
|
||||
if ( !inside ) continue; // we have everything set to no data
|
||||
|
||||
qgssize srcIndex = static_cast< qgssize >( srcRow ) * pd.srcCols() + srcCol;
|
||||
qgssize srcIndex = static_cast< qgssize >( srcRow * pd.srcCols() + srcCol );
|
||||
|
||||
// isNoData() may be slow so we check doNoData first
|
||||
if ( doNoData && inputBlock->isNoData( srcRow, srcCol ) )
|
||||
@ -823,7 +846,7 @@ QgsRasterBlock *QgsRasterProjector::block( int bandNo, QgsRectangle const &exte
|
||||
continue;
|
||||
}
|
||||
|
||||
qgssize destIndex = static_cast< qgssize >( i ) * width + j;
|
||||
qgssize destIndex = static_cast< qgssize >( i * width + j );
|
||||
char *srcBits = inputBlock->bits( srcIndex );
|
||||
char *destBits = outputBlock->bits( destIndex );
|
||||
if ( !srcBits )
|
||||
@ -851,8 +874,15 @@ bool QgsRasterProjector::destExtentSize( const QgsRectangle &srcExtent, int srcX
|
||||
{
|
||||
return false;
|
||||
}
|
||||
QgsCoordinateTransform ct( mSrcCRS, mDestCRS, mSrcDatumTransform, mDestDatumTransform );
|
||||
|
||||
QgsCoordinateTransform ct;
|
||||
if ( mSrcDatumTransform != -1 && mDestDatumTransform != -1 )
|
||||
{
|
||||
ct = QgsCoordinateTransform( mSrcCRS, mDestCRS, mSrcDatumTransform, mDestDatumTransform );
|
||||
}
|
||||
else
|
||||
{
|
||||
ct = QgsCoordinateTransform( mSrcCRS, mDestCRS, mTransformContext );
|
||||
}
|
||||
return extentSize( ct, srcExtent, srcXSize, srcYSize, destExtent, destXSize, destYSize );
|
||||
}
|
||||
|
||||
|
@ -69,9 +69,19 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
|
||||
|
||||
Qgis::DataType dataType( int bandNo ) const override;
|
||||
|
||||
//! Sets the source and destination CRS
|
||||
/**
|
||||
* Sets the source and destination CRS
|
||||
* \deprecated since QGIS 3.8, use transformContext version instead
|
||||
*/
|
||||
Q_DECL_DEPRECATED void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
|
||||
int srcDatumTransform = -1, int destDatumTransform = -1 ) SIP_DEPRECATED;
|
||||
|
||||
/**
|
||||
* Sets source CRS to \a srcCRS and destination CRS to \a destCRS and the transformation context to \a transformContext
|
||||
* \since QGIS 3.8
|
||||
*/
|
||||
void setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS,
|
||||
int srcDatumTransform = -1, int destDatumTransform = -1 );
|
||||
QgsCoordinateTransformContext transformContext );
|
||||
|
||||
//! Returns the source CRS
|
||||
QgsCoordinateReferenceSystem sourceCrs() const { return mSrcCRS; }
|
||||
@ -112,6 +122,9 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
|
||||
//! Requested precision
|
||||
Precision mPrecision = Approximate;
|
||||
|
||||
//! Transform context
|
||||
QgsCoordinateTransformContext mTransformContext;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user