[QGIS Commit] r14399 - in trunk/qgis: resources src/app src/core
src/ui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Oct 18 15:41:38 EDT 2010
Author: jef
Date: 2010-10-18 12:41:37 -0700 (Mon, 18 Oct 2010)
New Revision: 14399
Modified:
trunk/qgis/resources/srs.db
trunk/qgis/src/app/qgsoptions.cpp
trunk/qgis/src/app/qgsoptions.h
trunk/qgis/src/core/qgscoordinatereferencesystem.cpp
trunk/qgis/src/core/qgscoordinatetransform.cpp
trunk/qgis/src/core/qgscoordinatetransform.h
trunk/qgis/src/ui/qgsoptionsbase.ui
Log:
[FEATURE] allow user specific PROJ.4 search paths and update srs.db to include grid reference (fixes #3099)
Modified: trunk/qgis/resources/srs.db
===================================================================
(Binary files differ)
Modified: trunk/qgis/src/app/qgsoptions.cpp
===================================================================
--- trunk/qgis/src/app/qgsoptions.cpp 2010-10-18 18:59:52 UTC (rev 14398)
+++ trunk/qgis/src/app/qgsoptions.cpp 2010-10-18 19:41:37 UTC (rev 14399)
@@ -85,6 +85,15 @@
}
}
+ //local directories to search when looking for an PROJ.4 file with a given basename
+ foreach( QString path, settings.value( "projSearchPaths" ).toStringList() )
+ {
+ QListWidgetItem* newItem = new QListWidgetItem( mListProjPaths );
+ newItem->setText( path );
+ newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
+ mListProjPaths->addItem( newItem );
+ }
+
//Network timeout
mNetworkTimeoutSpinBox->setValue( settings.value( "/qgis/networkAndProxy/networkTimeout", "60000" ).toInt() );
@@ -464,6 +473,13 @@
}
settings.setValue( "svg/searchPathsForSVG", myPaths );
+ QStringList paths;
+ for ( int i = 0; i < mListProjPaths->count(); ++i )
+ {
+ paths << mListProjPaths->item( i )->text();
+ }
+ settings.setValue( "projSearchPaths", paths );
+
//Network timeout
settings.setValue( "/qgis/networkAndProxy/networkTimeout", mNetworkTimeoutSpinBox->value() );
@@ -872,6 +888,33 @@
delete itemToRemove;
}
+void QgsOptions::on_mBtnAddProjPath_clicked()
+{
+ QString myDir = QFileDialog::getExistingDirectory(
+ this,
+ tr( "Choose a directory" ),
+ QDir::toNativeSeparators( QDir::homePath() ),
+ QFileDialog::ShowDirsOnly
+ );
+
+ if ( ! myDir.isEmpty() )
+ {
+ QListWidgetItem* newItem = new QListWidgetItem( mListProjPaths );
+ newItem->setText( myDir );
+ newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
+ mListProjPaths->addItem( newItem );
+ mListProjPaths->setCurrentItem( newItem );
+ }
+}
+
+void QgsOptions::on_mBtnRemoveProjPath_clicked()
+{
+ int currentRow = mListProjPaths->currentRow();
+ QListWidgetItem* itemToRemove = mListProjPaths->takeItem( currentRow );
+ delete itemToRemove;
+}
+
+
void QgsOptions::on_mAddUrlPushButton_clicked()
{
QListWidgetItem* newItem = new QListWidgetItem( mExcludeUrlListWidget );
Modified: trunk/qgis/src/app/qgsoptions.h
===================================================================
--- trunk/qgis/src/app/qgsoptions.h 2010-10-18 18:59:52 UTC (rev 14398)
+++ trunk/qgis/src/app/qgsoptions.h 2010-10-18 19:41:37 UTC (rev 14399)
@@ -101,6 +101,12 @@
*/
void on_mBtnRemoveSVGPath_clicked();
+ /* Let the user add a path to the list of search paths used for finding PROJ.4 files. */
+ void on_mBtnAddProjPath_clicked();
+
+ /* Let the user remove a path to the list of search paths for finding PROJ.4 files. */
+ void on_mBtnRemoveProjPath_clicked();
+
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
void on_mBrowseCacheDirectory_clicked();
Modified: trunk/qgis/src/core/qgscoordinatereferencesystem.cpp
===================================================================
--- trunk/qgis/src/core/qgscoordinatereferencesystem.cpp 2010-10-18 18:59:52 UTC (rev 14398)
+++ trunk/qgis/src/core/qgscoordinatereferencesystem.cpp 2010-10-18 19:41:37 UTC (rev 14399)
@@ -1161,9 +1161,10 @@
// ... unfortunately it happens on Windows
QgsMessageOutput* output = QgsMessageOutput::createMessageOutput();
output->setTitle( "Error" );
- output->setMessage( "Could not open CRS database " + path +
- "<br>Error(" + QString::number( myResult ) + "): " +
- QString( sqlite3_errmsg( *db ) ), QgsMessageOutput::MessageText );
+ output->setMessage( QObject::tr( "Could not open CRS database %1<br>Error(%2): %3" )
+ .arg( path )
+ .arg( myResult )
+ .arg( sqlite3_errmsg( *db ) ), QgsMessageOutput::MessageText );
output->showMessage();
}
return myResult;
Modified: trunk/qgis/src/core/qgscoordinatetransform.cpp
===================================================================
--- trunk/qgis/src/core/qgscoordinatetransform.cpp 2010-10-18 18:59:52 UTC (rev 14398)
+++ trunk/qgis/src/core/qgscoordinatetransform.cpp 2010-10-18 19:41:37 UTC (rev 14399)
@@ -15,15 +15,18 @@
* *
***************************************************************************/
/* $Id$ */
-#include <cassert>
#include "qgscoordinatetransform.h"
+#include "qgsmessageoutput.h"
#include "qgslogger.h"
//qt includes
#include <QDomNode>
#include <QDomElement>
#include <QApplication>
-#include "qgslogger.h"
+#include <QSettings>
+#include <QStringList>
+#include <QFileInfo>
+#include <QSet>
extern "C"
{
@@ -33,10 +36,7 @@
// if defined shows all information about transform to stdout
// #define COORDINATE_TRANSFORM_VERBOSE
-
-
QgsCoordinateTransform::QgsCoordinateTransform( ) : QObject(), mSourceCRS(), mDestCRS()
-
{
setFinder();
}
@@ -45,6 +45,7 @@
const QgsCoordinateReferenceSystem& dest )
{
setFinder();
+
mSourceCRS = source;
mDestCRS = dest;
initialise();
@@ -315,7 +316,7 @@
if ( mShortCircuit || !mInitialisedFlag )
return;
- assert( x.size() == y.size() );
+ Q_ASSERT( x.size() == y.size() );
// Apparently, if one has a std::vector, it is valid to use the
// address of the first element in the vector as a pointer to an
@@ -457,8 +458,8 @@
}
else
{
- assert( mSourceProjection != 0 );
- assert( mDestinationProjection != 0 );
+ Q_ASSERT( mSourceProjection != 0 );
+ Q_ASSERT( mDestinationProjection != 0 );
projResult = pj_transform( mSourceProjection, mDestinationProjection, numPoints, 0, x, y, z );
dir = tr( "forward transform" );
}
@@ -531,7 +532,6 @@
bool QgsCoordinateTransform::writeXML( QDomNode & theNode, QDomDocument & theDoc )
{
-
QDomElement myNodeElement = theNode.toElement();
QDomElement myTransformElement = theDoc.createElement( "coordinatetransform" );
@@ -548,29 +548,51 @@
return true;
}
-const char *finder( const char *name )
+void QgsCoordinateTransform::setFinder()
{
- QString proj;
-#ifdef WIN32
- proj = QApplication::applicationDirPath()
- + "/share/proj/" + QString( name );
-#endif
- return proj.toUtf8();
+ pj_set_finder( finder );
}
-void QgsCoordinateTransform::setFinder()
+const char *QgsCoordinateTransform::finder( const char *name )
{
+ QSettings settings;
+ QStringList paths = settings.value( "projSearchPaths" ).toStringList();
+
+ if ( getenv( "PROJ_LIB" ) )
+ {
+ paths << getenv( "PROJ_LIB" );
+ }
+
#ifdef WIN32
- // Attention! It should be possible to set PROJ_LIB
- // but it can happen that it was previously set by installer
- // (version 0.7) and the old installation was deleted
+ paths << QApplication::applicationDirPath() + "/share/proj";
+#endif
- // Another problem: PROJ checks if pj_finder was set before
- // PROJ_LIB environment variable. pj_finder is probably set in
- // GRASS gproj library when plugin is loaded, consequently
- // PROJ_LIB is ignored
+ foreach( QString path, paths )
+ {
+ QFileInfo fi( QString( "%1/%2" ).arg( path ).arg( name ) );
+ if ( fi.exists() )
+ return fi.canonicalFilePath().toUtf8();
+ }
- pj_set_finder( finder );
-#endif
+ if ( QString( name ).endsWith( ".gsb", Qt::CaseInsensitive ) )
+ {
+ static QSet<QString> missing;
+
+ if ( !missing.contains( name ) )
+ {
+ QgsMessageOutput *output = QgsMessageOutput::createMessageOutput();
+ output->setTitle( "Grid transformation missing" );
+ output->setMessage( tr( "PROJ.4 file %1 not found in any of these directories:\n\n"
+ "%2\n\n"
+ "Note: This message won't reappear for this file in this session." )
+ .arg( name )
+ .arg( paths.join( "\n" ) ),
+ QgsMessageOutput::MessageText );
+ output->showMessage();
+ }
+
+ missing << name;
+ }
+
+ return name;
}
-
Modified: trunk/qgis/src/core/qgscoordinatetransform.h
===================================================================
--- trunk/qgis/src/core/qgscoordinatetransform.h 2010-10-18 18:59:52 UTC (rev 14398)
+++ trunk/qgis/src/core/qgscoordinatetransform.h 2010-10-18 19:41:37 UTC (rev 14399)
@@ -256,9 +256,14 @@
projPJ mDestinationProjection;
/*!
+ * Set finder for PROJ grid files.
+ */
+ void setFinder();
+
+ /*!
* Finder for PROJ grid files.
*/
- void setFinder();
+ static const char *finder( const char *name );
};
//! Output stream operator
@@ -271,45 +276,47 @@
{
//do nothing this is a dummy
}
- /*
- if (r.isInitialised())
- {
- mySummary += "Yes";
- }
- else
- {
- mySummary += "No" ;
- }
- mySummary += "\n\tShort Circuit? : " ;
- if (r.isShortCircuited())
- {
- mySummary += "Yes";
- }
- else
- {
- mySummary += "No" ;
- }
- mySummary += "\n\tSource Spatial Ref Sys : ";
- if (r.sourceCrs())
- {
- mySummary << r.sourceCrs();
- }
- else
- {
- mySummary += "Undefined" ;
- }
+#if 0
+ if ( r.isInitialised() )
+ {
+ mySummary += "Yes";
+ }
+ else
+ {
+ mySummary += "No" ;
+ }
+ mySummary += "\n\tShort Circuit? : " ;
+ if ( r.isShortCircuited() )
+ {
+ mySummary += "Yes";
+ }
+ else
+ {
+ mySummary += "No" ;
+ }
- mySummary += "\n\tDest Spatial Ref Sys : " ;
- if (r.destCRS())
- {
- mySummary << r.destCRS();
- }
- else
- {
- mySummary += "Undefined" ;
- }
- */
+ mySummary += "\n\tSource Spatial Ref Sys : ";
+ if ( r.sourceCrs() )
+ {
+ mySummary << r.sourceCrs();
+ }
+ else
+ {
+ mySummary += "Undefined" ;
+ }
+
+ mySummary += "\n\tDest Spatial Ref Sys : " ;
+ if ( r.destCRS() )
+ {
+ mySummary << r.destCRS();
+ }
+ else
+ {
+ mySummary += "Undefined" ;
+ }
+#endif
+
mySummary += ( "\nCoordinate Transform def ends \n%%%%%%%%%%%%%%%%%%%%%%%%\n" );
return os << mySummary.toLocal8Bit().data() << std::endl;
}
Modified: trunk/qgis/src/ui/qgsoptionsbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsoptionsbase.ui 2010-10-18 18:59:52 UTC (rev 14398)
+++ trunk/qgis/src/ui/qgsoptionsbase.ui 2010-10-18 19:41:37 UTC (rev 14399)
@@ -212,6 +212,16 @@
</item>
</widget>
</item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
<item row="0" column="1">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
@@ -624,6 +634,52 @@
</layout>
</widget>
</item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_4">
+ <property name="title">
+ <string>PROJ.4 search paths</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_4">
+ <item row="4" column="0" colspan="4">
+ <widget class="QListWidget" name="mListProjPaths"/>
+ </item>
+ <item row="3" column="1">
+ <spacer name="spacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>31</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="3" column="2">
+ <widget class="QPushButton" name="mBtnAddProjPath">
+ <property name="text">
+ <string>Add</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="3">
+ <widget class="QPushButton" name="mBtnRemoveProjPath">
+ <property name="text">
+ <string>Remove</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="mProjLabel">
+ <property name="text">
+ <string>Path(s) to search for PROJ.4 files</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
</layout>
</widget>
<widget class="QWidget" name="stackedWidgetPage3">
@@ -1599,16 +1655,6 @@
</widget>
</widget>
</item>
- <item row="1" column="0" colspan="2">
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
More information about the QGIS-commit
mailing list