Skip to content

Commit

Permalink
Merge branch 'customCRS' of https://github.com/leyan/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed May 12, 2013
2 parents 8012065 + 6e3e89b commit 9dd8b2f
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 888 deletions.
953 changes: 256 additions & 697 deletions src/app/qgscustomprojectiondialog.cpp

Large diffs are not rendered by default.

63 changes: 30 additions & 33 deletions src/app/qgscustomprojectiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "ui_qgscustomprojectiondialogbase.h"
#include "qgscontexthelp.h"
#include "qgscoordinatereferencesystem.h"

class QDir;

Expand All @@ -34,45 +35,41 @@ class QgsCustomProjectionDialog : public QDialog, private Ui::QgsCustomProjectio
public:
QgsCustomProjectionDialog( QWidget *parent = 0, Qt::WFlags fl = 0 );
~QgsCustomProjectionDialog();
//a recursive function to make a directory and its ancestors

public slots:
void on_pbnCalculate_clicked();
void on_pbnDelete_clicked();
//
// Database navigation controles
//
long getRecordCount();
void on_pbnFirst_clicked();
void on_pbnPrevious_clicked();
void on_pbnNext_clicked();
void on_pbnLast_clicked();
void on_pbnNew_clicked();
void on_pbnSave_clicked();
void on_pbnAdd_clicked();
void on_pbnRemove_clicked();
void on_pbnCopyCRS_clicked();
void on_leNameList_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev );

void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }

//
// Control population
//
/* These two methods will be deprecated
void getProjList();
void getEllipsoidList();
*/
QString getProjectionFamilyName( QString theProjectionFamilyAcronym );
QString getEllipsoidName( QString theEllipsoidAcronym );
QString getProjectionFamilyAcronym( QString theProjectionFamilyName );
QString getEllipsoidAcronym( QString theEllipsoidName );
void on_buttonBox_accepted();

private:
QString getProjFromParameters();
QString getEllipseFromParameters();

QString mCurrentRecordId;
long mCurrentRecordLong;
//the record previous to starting an insert operation
//so that we can return to it if the record insert is aborted
long mLastRecordLong;
long mRecordCountLong;

//helper functions
void populateList();
QString quotedValue( QString value );
bool deleteCRS( QString id );
bool saveCRS( QgsCoordinateReferenceSystem myParameters, QString myName, QString myId, bool newEntry );
void insertProjection( QString myProjectionAcronym );

//These two QMap store the values as they are on the database when loading
QMap <QString, QString> existingCRSparameters;
QMap <QString, QString> existingCRSnames;

//These three vectors store the value updated with the current modifications
std::vector<QString> customCRSnames;
std::vector<QString> customCRSids;
std::vector<QString> customCRSparameters;

//vector saving the CRS to be deleted
std::vector<QString> deletedCRSs;

//Columns in the tree widget
enum columns { QGIS_CRS_NAME_COLUMN, QGIS_CRS_ID_COLUMN, QGIS_CRS_PARAMETERS_COLUMN };
};


#endif
26 changes: 24 additions & 2 deletions src/core/qgscoordinatereferencesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QRegExp>
#include <QTextStream>
#include <QFile>
#include <QSettings>

#include "qgsapplication.h"
#include "qgscrscache.h"
Expand Down Expand Up @@ -662,6 +663,7 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
if ( !mIsValidFlag )
{
QgsDebugMsg( "Projection is not found in databases." );
//setProj4String will set mIsValidFlag to true if there is no issue
setProj4String( myProj4String );
}

Expand Down Expand Up @@ -1472,8 +1474,28 @@ bool QgsCoordinateReferenceSystem::saveAsUserCRS( QString name )

QgsMessageLog::logMessage( QObject::tr( "Saved user CRS [%1]" ).arg( toProj4() ), QObject::tr( "CRS" ) );

// XXX Need to free memory from the error msg if one is set
return myResult == SQLITE_OK;
int return_id;
if(myResult == SQLITE_OK)
{
return_id = sqlite3_last_insert_rowid( myDatabase );
setInternalId(return_id);

//We add the just created user CRS to the list of recently used CRS
QSettings settings;
//QStringList recentProjections = settings.value( "/UI/recentProjections" ).toStringList();
QStringList projectionsProj4 = settings.value( "/UI/recentProjectionsProj4" ).toStringList();
QStringList projectionsAuthId = settings.value( "/UI/recentProjectionsAuthId" ).toStringList();
//recentProjections.append();
//settings.setValue( "/UI/recentProjections", recentProjections );
projectionsProj4.append(toProj4());
projectionsAuthId.append(authid());
settings.setValue( "/UI/recentProjectionsProj4", projectionsProj4 );
settings.setValue( "/UI/recentProjectionsAuthId", projectionsAuthId );

}
else
return_id = -1;
return return_id;
}

long QgsCoordinateReferenceSystem::getRecordCount()
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgscoordinatereferencesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
* in the parameters member. The reason for this is so that we
* can easily present the user with 'natural language' representation
* of the projection and ellipsoid by looking them up in the srs.bs sqlite
* database. Also having the ellpse and proj elements stripped out
* database. Also having the ellipse and proj elements stripped out
* is helpful to speed up globbing queries (see below).
*
* We try to match the proj string to and srsid using the following logic:
Expand Down Expand Up @@ -444,7 +444,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
long mSRID;
//!If available the authority identifier for this srs
QString mAuthId;
//! Wehter this srs is properly defined and valid
//! Wheter this srs is properly defined and valid
bool mIsValidFlag;

//! Work out the projection units and set the appropriate local variable
Expand Down
17 changes: 4 additions & 13 deletions src/gui/qgsprojectionselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,10 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name,
// No? Skip this entry
continue;
}
else
//If the CRS can be created but do not correspond to a CRS in the database, skip it (for example a deleted custom CRS)
if ( crs.srsid() == 0 )
{
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if ( crs.srsid() == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( crs.toProj4() );
crs.saveAsUserCRS( myName );
}
continue;
}
}
mRecentProjections << QString::number( crs.srsid() );
Expand Down Expand Up @@ -277,7 +268,7 @@ void QgsProjectionSelector::applySelection( int column, QString value )
}
else
{
QgsDebugMsg( "nothing found" );
QgsDebugMsg( QString("nothing found for %1,%2" ).arg( column ).arg( value ) );
// unselect the selected item to avoid confusing the user
lstCoordinateSystems->clearSelection();
lstRecent->clearSelection();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wcs/qgswcsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
// It may happen (Geoserver) that if requested BBOX is larger than coverage
// extent, the returned data cover intersection of requested BBOX and coverage
// extent scaled to requested WIDTH/HEIGHT => check extent
// Unfortunately if received raster does not hac CRS, the extent is raster size
// Unfortunately if the received raster does not have a CRS, the extent is the raster size
// and in that case it cannot be used to verify extent
QgsCoordinateReferenceSystem cacheCrs;
if ( !cacheCrs.createFromWkt( GDALGetProjectionRef( mCachedGdalDataset ) ) &&
Expand Down
Loading

0 comments on commit 9dd8b2f

Please sign in to comment.