From 3124d4be96b7cfd129b45f501c97c08b6d41db62 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 11 Jul 2024 11:57:26 +1000 Subject: [PATCH] [GRASS] Fix writing projection for new mapsets Use the more modern API so that the projection SRID and WKT are written losslessly to the mapset Avoids loss of projection information when creating mapsets --- src/plugins/grass/qgsgrassnewmapset.cpp | 23 ++++++++++++----------- src/plugins/grass/qgsgrassnewmapset.h | 2 ++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/plugins/grass/qgsgrassnewmapset.cpp b/src/plugins/grass/qgsgrassnewmapset.cpp index 99ecd6ee9b07..df3896cc666d 100644 --- a/src/plugins/grass/qgsgrassnewmapset.cpp +++ b/src/plugins/grass/qgsgrassnewmapset.cpp @@ -399,18 +399,9 @@ void QgsGrassNewMapset::setGrassProjection() const QString wkt = crs.toWkt( QgsCoordinateReferenceSystem::WktVariant::WKT_PREFERRED ); QgsDebugMsgLevel( QStringLiteral( "wkt = %1" ).arg( crs.toWkt( Qgis::CrsWktVariant::Preferred ) ), 3 ); - // Note: GPJ_osr_to_grass() defaults in PROJECTION_XY if projection - // cannot be set - G_TRY { - // There was a bug in GRASS, it is present in 6.0.x line - int ret = GPJ_wkt_to_grass( &mCellHead, &mProjInfo, &mProjUnits, wkt.toUtf8().constData(), 0 ); - // Note: It seems that GPJ_osr_to_grass()returns always 1, - // -> test if mProjInfo was set - - Q_UNUSED( ret ) - QgsDebugMsgLevel( QString( "ret = %1" ).arg( ret ), 2 ); + GPJ_wkt_to_grass( &mCellHead, &mProjInfo, &mProjUnits, wkt.toUtf8().constData(), 0 ); } G_CATCH( QgsGrass::Exception & e ) { @@ -422,6 +413,11 @@ void QgsGrassNewMapset::setGrassProjection() { setError( mProjErrorLabel, tr( "Selected projection is not supported by GRASS!" ) ); } + else + { + mProjSrid = crs.authid().toUpper(); + mProjWkt = wkt; + } } else // Nothing selected { @@ -429,6 +425,8 @@ void QgsGrassNewMapset::setGrassProjection() mCellHead.zone = 0; mProjInfo = nullptr; mProjUnits = nullptr; + mProjSrid.clear(); + mProjWkt.clear(); } button( QWizard::NextButton )->setEnabled( mProjInfo && mProjUnits ); } @@ -1106,7 +1104,10 @@ void QgsGrassNewMapset::createMapset() QString error; G_TRY { - ret = G_make_location( location.toUtf8().constData(), &mCellHead, mProjInfo, mProjUnits ); + ret = G_make_location_crs( location.toUtf8().constData(), + &mCellHead, mProjInfo, mProjUnits, + mProjSrid.toUtf8().constData(), + mProjWkt.toUtf8().constData() ); } G_CATCH( QgsGrass::Exception & e ) { diff --git a/src/plugins/grass/qgsgrassnewmapset.h b/src/plugins/grass/qgsgrassnewmapset.h index 4c34e01a34be..0d423290ef6e 100644 --- a/src/plugins/grass/qgsgrassnewmapset.h +++ b/src/plugins/grass/qgsgrassnewmapset.h @@ -195,6 +195,8 @@ class QgsGrassNewMapset : public QWizard, private Ui::QgsGrassNewMapsetBase struct Cell_head mCellHead; struct Key_Value *mProjInfo = nullptr; struct Key_Value *mProjUnits = nullptr; + QString mProjSrid; + QString mProjWkt; //! Previous page int mPreviousPage = -1;