Skip to content

Commit

Permalink
[GRASS] Fix writing projection for new mapsets
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Jul 11, 2024
1 parent b1d3f7b commit 3124d4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/plugins/grass/qgsgrassnewmapset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -422,13 +413,20 @@ void QgsGrassNewMapset::setGrassProjection()
{
setError( mProjErrorLabel, tr( "Selected projection is not supported by GRASS!" ) );
}
else
{
mProjSrid = crs.authid().toUpper();
mProjWkt = wkt;
}
}
else // Nothing selected
{
mCellHead.proj = PROJECTION_XY;
mCellHead.zone = 0;
mProjInfo = nullptr;
mProjUnits = nullptr;
mProjSrid.clear();
mProjWkt.clear();
}
button( QWizard::NextButton )->setEnabled( mProjInfo && mProjUnits );
}
Expand Down Expand Up @@ -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 )
{
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/grass/qgsgrassnewmapset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3124d4b

Please sign in to comment.