Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Possibility to add / remove default transformations in options tab
  • Loading branch information
mhugent committed Nov 16, 2013
1 parent 7fbc692 commit bc73b4e
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 29 deletions.
112 changes: 112 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -410,6 +410,51 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
//display the crs as friendly text rather than in wkt
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );

//default datum transformations
settings.beginGroup( "/Projections" );
QStringList projectionKeys = settings.allKeys();

//collect src and dest entries that belong together
QMap< QPair< QString, QString >, QPair< int, int > > transforms;
QStringList::const_iterator pkeyIt = projectionKeys.constBegin();
for ( ; pkeyIt != projectionKeys.constEnd(); ++pkeyIt )
{
if ( pkeyIt->contains( "srcTransform" ) || pkeyIt->contains( "destTransform" ) )
{
QStringList split = pkeyIt->split( "/" );
QString srcAuthId, destAuthId;
if ( split.size() > 0 )
{
srcAuthId = split.at( 0 );
}
if ( split.size() > 1 )
{
destAuthId = split.at( 1 ).split( "_" ).at( 0 );
}

if ( pkeyIt->contains( "srcTransform" ) )
{
transforms[ qMakePair( srcAuthId, destAuthId )].first = settings.value( *pkeyIt ).toInt();
}
else if ( pkeyIt->contains( "destTransform" ) )
{
transforms[ qMakePair( srcAuthId, destAuthId )].second = settings.value( *pkeyIt ).toInt();
}
}
}
settings.endGroup();

QMap< QPair< QString, QString >, QPair< int, int > >::const_iterator transformIt = transforms.constBegin();
for ( ; transformIt != transforms.constEnd(); ++transformIt )
{
const QPair< int, int >& v = transformIt.value();
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText( 0, transformIt.key().first );
item->setText( 1, transformIt.key().second );
item->setText( 2, QString::number( v.first ) );
item->setText( 3, QString::number( v.second ) );
mDefaultDatumTransformTreeWidget->addTopLevelItem( item );
}

// Set the units for measuring
QGis::UnitType myDisplayUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
Expand Down Expand Up @@ -1196,6 +1241,8 @@ void QgsOptions::saveOptions()
{
mStyleSheetBuilder->saveToSettings( mStyleSheetNewOpts );
}

saveDefaultDatumTransformations();
}

void QgsOptions::rejectOptions()
Expand Down Expand Up @@ -1850,3 +1897,68 @@ void QgsOptions::saveContrastEnhancement( QComboBox *cbox, QString name )
settings.setValue( "/Raster/defaultContrastEnhancementAlgorithm/" + name, value );
}

void QgsOptions::on_mRemoveDefaultTransformButton_clicked()
{
QList<QTreeWidgetItem*> items = mDefaultDatumTransformTreeWidget->selectedItems();
for ( int i = 0; i < items.size(); ++i )
{
int idx = mDefaultDatumTransformTreeWidget->indexOfTopLevelItem( items.at( i ) );
if ( idx >= 0 )
{
delete mDefaultDatumTransformTreeWidget->takeTopLevelItem( idx );
}
}
}

void QgsOptions::on_mAddDefaultTransformButton_clicked()
{
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setText( 0, "" );
item->setText( 1, "" );
item->setText( 2, "" );
item->setText( 3, "" );
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
mDefaultDatumTransformTreeWidget->addTopLevelItem( item );
}

void QgsOptions::saveDefaultDatumTransformations()
{
QSettings s;
s.beginGroup( "/Projections" );
QStringList groupKeys = s.allKeys();
QStringList::const_iterator groupKeyIt = groupKeys.constBegin();
for ( ; groupKeyIt != groupKeys.constEnd(); ++groupKeyIt )
{
if ( groupKeyIt->contains( "srcTransform" ) || groupKeyIt->contains( "destTransform" ) )
{
s.remove( *groupKeyIt );
}
}

int nDefaultTransforms = mDefaultDatumTransformTreeWidget->topLevelItemCount();
for ( int i = 0; i < nDefaultTransforms; ++i )
{
QTreeWidgetItem* item = mDefaultDatumTransformTreeWidget->topLevelItem( i );
QString srcAuthId = item->text( 0 );
QString destAuthId = item->text( 1 );
if ( srcAuthId.isEmpty() || destAuthId.isEmpty() )
{
continue;
}

bool conversionOk;
int srcDatumTransform = item->text( 2 ).toInt( &conversionOk );
if ( conversionOk )
{
s.setValue( srcAuthId + "//" + destAuthId + "_srcTransform" , srcDatumTransform );
}
int destDatumTransform = item->text( 3 ).toInt( &conversionOk );
if ( conversionOk )
{
s.setValue( srcAuthId + "//" + destAuthId + "_destTransform" , destDatumTransform );
}
}

s.endGroup();
}

5 changes: 5 additions & 0 deletions src/app/qgsoptions.h
Expand Up @@ -227,6 +227,9 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
*/
void saveGdalDriverList();

void on_mRemoveDefaultTransformButton_clicked();
void on_mAddDefaultTransformButton_clicked();

private:
QStringList i18nList();
void initContrastEnhancement( QComboBox *cbox, QString name, QString defaultVal );
Expand All @@ -240,6 +243,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
*/
void addCustomEnvVarRow( QString varName, QString varVal, QString varApply = QString() );

void saveDefaultDatumTransformations();

protected:
QgisAppStyleSheet* mStyleSheetBuilder;
QMap<QString, QVariant> mStyleSheetNewOpts;
Expand Down
130 changes: 101 additions & 29 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>848</width>
<height>578</height>
<height>705</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -267,7 +267,7 @@
<x>0</x>
<y>0</y>
<width>687</width>
<height>523</height>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
Expand Down Expand Up @@ -1249,7 +1249,7 @@
<x>0</x>
<y>0</y>
<width>687</width>
<height>523</height>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
Expand Down Expand Up @@ -1577,8 +1577,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>572</width>
<height>611</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_29">
Expand Down Expand Up @@ -2092,8 +2092,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>441</width>
<height>281</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
Expand Down Expand Up @@ -2438,8 +2438,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>494</width>
<height>619</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_30">
Expand Down Expand Up @@ -2852,8 +2852,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>551</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_31">
Expand Down Expand Up @@ -3354,7 +3354,7 @@
<x>0</x>
<y>0</y>
<width>687</width>
<height>523</height>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
Expand Down Expand Up @@ -3494,10 +3494,23 @@
<x>0</x>
<y>0</y>
<width>687</width>
<height>523</height>
<height>650</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="grpProjectionBehaviour">
<property name="title">
Expand Down Expand Up @@ -3574,19 +3587,6 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="grpOtfTransform">
<property name="title">
Expand Down Expand Up @@ -3644,6 +3644,78 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QGroupBox" name="mDefaultDatumTransformGroupBox">
<property name="title">
<string>Default datum transformations</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="mAddDefaultTransformButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.png</normaloff>:/images/themes/default/symbologyAdd.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mRemoveDefaultTransformButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_38">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>568</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QTreeWidget" name="mDefaultDatumTransformTreeWidget">
<column>
<property name="text">
<string>Source CRS</string>
</property>
</column>
<column>
<property name="text">
<string>Destination CRS</string>
</property>
</column>
<column>
<property name="text">
<string>Source datum transform</string>
</property>
</column>
<column>
<property name="text">
<string>Destination datum transform</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down Expand Up @@ -3678,7 +3750,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>265</width>
<width>216</width>
<height>197</height>
</rect>
</property>
Expand Down Expand Up @@ -3778,8 +3850,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>469</width>
<height>556</height>
<width>687</width>
<height>650</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">
Expand Down

9 comments on commit bc73b4e

@gioman
Copy link
Contributor

@gioman gioman commented on bc73b4e Nov 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Marco, I'm trying to add a Datum Transformation in the general options, but after clicking "ok" and reopening the dialog the line I added does not show. When adding a line it is not clear (at least on my Linux Desktop) that the line was added and ready to be filled.

Another suggestion would be to use the standard QGIS dialog to allow select the source/destination CRS.

Another thing is about the datum transformation parameters, how do they have to be written for ntv2 grids?

thanks in advance!

@mhugent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The datum transformation itself has to be added to srs.db (see the entries for the Swiss and NZ grid shift as examples). I know, it would be cool to have a dialog to add it graphically, but maybe it will come in the future.

The option page is only for the default datum transformations (to avoid popping up the dialog every time). And the main purpose here is to delete entries easily (without editing the conf file in a text editor).

@gioman
Copy link
Contributor

@gioman gioman commented on bc73b4e Nov 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it. Here is a first list of transformations from Datum 73, Datum Lisboa and ETRS89-PTTM06. They seems repeated but are not. There are the official NTV2 grids (http://www.igeo.pt/produtos/geodesia/Grelhas_NTv2.htm) and other grids that are widely used (http://www.fc.up.pt/pessoas/jagoncal/coordenadas/). I guess that the users will have to put manually the grids inside the /proj folder, right?

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100003,
27493,
3763,
9615,
'pt73_e89.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100004,
20790,
3763,
9615,
'ptLX_e89.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100005,
20791,
3763,
9615,
'ptLX_e89.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100006,
27493,
3763,
9615,
'D73_ETRS89_geo.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100007,
20790,
3763,
9615,
'DLX_ETRS89_geo.gsb'
);

INSERT INTO tbl_datum_transform (
coord_op_code,
source_crs_code,
target_crs_code,
coord_op_method_code,
p1
)
VALUES (
100008,
20791,
3763,
9615,
'DLX_ETRS89_geo.gsb'
);

@mhugent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Giovanni, will apply those soon.
Yes, the user needs to put the files into the proj-dir manually. In case PROJ_LIB env var is set (usually the case on win), the datum transform dialog checks if the .gsb is really there (and grays out the entry if not)

@gioman
Copy link
Contributor

@gioman gioman commented on bc73b4e Nov 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Marco, thanks to you.

I have seen the datum transformation dialog pop out also when adding geometryless tables (CSV), maybe this is not wanted(?).

Cheers!

@gioman
Copy link
Contributor

@gioman gioman commented on bc73b4e Nov 21, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Marco, should I make a pull request instead of a comment in this commit?

@mhugent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQL is applied to srs.db. Thanks, Giovanni!

@gioman
Copy link
Contributor

@gioman gioman commented on bc73b4e Nov 21, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Marco! I will start test them asap.

Do you want me to file a ticket about the fact that the datum transformation dialog shows also when adding geometryless layers? Or may be it was already fixed? Cheers!

@mhugent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please fill a ticket.

Please sign in to comment.