Skip to content
Permalink
Browse files

Fix some transforms missing transform context

  • Loading branch information
nyalldawson committed Nov 28, 2017
1 parent 95a2ac0 commit 670858d81c504c1d68c6fd23632ab308f6e2a182
@@ -226,6 +226,16 @@ void Qgs3DMapSettings::setCrs( const QgsCoordinateReferenceSystem &crs )
mCrs = crs;
}

QgsCoordinateTransformContext Qgs3DMapSettings::transformContext() const
{
return mTransformContext;
}

void Qgs3DMapSettings::setTransformContext( const QgsCoordinateTransformContext &context )
{
mTransformContext = context;
}

void Qgs3DMapSettings::setBackgroundColor( const QColor &color )
{
if ( color == mBackgroundColor )
@@ -88,6 +88,24 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
//! Returns coordinate reference system used in the 3D scene
QgsCoordinateReferenceSystem crs() const { return mCrs; }

/**
* Returns the coordinate transform context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \see setTransformContext()
*/
QgsCoordinateTransformContext transformContext() const;

/**
* Sets the coordinate transform \a context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \see transformContext()
*/
void setTransformContext( const QgsCoordinateTransformContext &context );

//! Sets background color of the 3D map view
void setBackgroundColor( const QColor &color );
//! Returns background color of the 3D map view
@@ -239,6 +257,8 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
bool mSkyboxEnabled = false; //!< Whether to render skybox
QString mSkyboxFileBase; //!< Base part of the files with skybox textures
QString mSkyboxFileExtension; //!< Extension part of the files with skybox textures
//! Coordinate transform context
QgsCoordinateTransformContext mTransformContext;
};


@@ -68,7 +68,7 @@ QgsTerrainEntity::QgsTerrainEntity( int maxLevel, const Qgs3DMapSettings &map, Q

connectToLayersRepaintRequest();

mTerrainToMapTransform = new QgsCoordinateTransform( map.terrainGenerator()->crs(), map.crs() );
mTerrainToMapTransform = new QgsCoordinateTransform( map.terrainGenerator()->crs(), map.crs(), map.transformContext() );

mTextureGenerator = new QgsTerrainTextureGenerator( map );

@@ -22,7 +22,7 @@
QgsAABB QgsTerrainGenerator::rootChunkBbox( const Qgs3DMapSettings &map ) const
{
QgsRectangle te = extent();
QgsCoordinateTransform terrainToMapTransform( crs(), map.crs() );
QgsCoordinateTransform terrainToMapTransform( crs(), map.crs(), map.transformContext() );
te = terrainToMapTransform.transformBoundingBox( te );

float hMin, hMax;
@@ -34,7 +34,7 @@ QgsAABB QgsTerrainGenerator::rootChunkBbox( const Qgs3DMapSettings &map ) const
float QgsTerrainGenerator::rootChunkError( const Qgs3DMapSettings &map ) const
{
QgsRectangle te = extent();
QgsCoordinateTransform terrainToMapTransform( crs(), map.crs() );
QgsCoordinateTransform terrainToMapTransform( crs(), map.crs(), map.transformContext() );
te = terrainToMapTransform.transformBoundingBox( te );

// use texel size as the error
@@ -305,7 +305,7 @@ void QgsLayoutMapWidget::mapCrsChanged( const QgsCoordinateReferenceSystem &crs
QgsRectangle newExtent;
try
{
QgsCoordinateTransform xForm( oldCrs, crs.isValid() ? crs : QgsProject::instance()->crs() );
QgsCoordinateTransform xForm( oldCrs, crs.isValid() ? crs : QgsProject::instance()->crs(), QgsProject::instance() );
QgsRectangle prevExtent = mMapItem->extent();
newExtent = xForm.transformBoundingBox( prevExtent );
updateExtent = true;
@@ -526,7 +526,7 @@ void QgsLayoutMapWidget::mSetToMapCanvasExtentButton_clicked()
try
{
QgsCoordinateTransform xForm( QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs(),
mMapItem->crs() );
mMapItem->crs(), QgsProject::instance() );
newExtent = xForm.transformBoundingBox( newExtent );
}
catch ( QgsCsException & )
@@ -559,7 +559,7 @@ void QgsLayoutMapWidget::mViewExtentInCanvasButton_clicked()
try
{
QgsCoordinateTransform xForm( mMapItem->crs(),
QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs() );
QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs(), QgsProject::instance() );
currentMapExtent = xForm.transformBoundingBox( currentMapExtent );
}
catch ( QgsCsException & )
@@ -10392,6 +10392,11 @@ void QgisApp::new3DMapCanvas()
map->setSelectionColor( mMapCanvas->selectionColor() );
map->setBackgroundColor( mMapCanvas->canvasColor() );
map->setLayers( mMapCanvas->layers() );
map->setTransformContext( QgsProject::instance()->transformContext() );
connect( QgsProject::instance(), &QgsProject::transformContextChanged, map, [map]
{
map->setTransformContext( QgsProject::instance()->transformContext() );
} );

QgsFlatTerrainGenerator *flatTerrain = new QgsFlatTerrainGenerator;
flatTerrain->setCrs( map->crs() );
@@ -244,7 +244,7 @@ void TestQgsCoordinateTransform::transformBoundingBox()
QGSCOMPARENEAR( resultRect.yMaximum(), expectedRect.yMaximum(), 0.001 );

// test transforming a bounding box, resulting in an invalid transform - exception must be thrown
tr = QgsCoordinateTransform( QgsCoordinateReferenceSystem( 4326 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28356" ) ) );
tr = QgsCoordinateTransform( QgsCoordinateReferenceSystem( 4326 ), QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28356" ) ), QgsProject::instance() );
QgsRectangle rect( -99999999999, 99999999999, -99999999998, 99999999998 );
bool errorObtained = false;
try

0 comments on commit 670858d

Please sign in to comment.
You can’t perform that action at this time.