** Merged Projections_Branch into HEAD

Problems:
      Polygon outlines are not drawn. This was checked twice and no cause
      was found.

      Projections do not work in all circumstances

      Note that both the proj4 library and sqlite3 are now required. The
      build system has not been modified to test for these yet.

      Qt 3.3.x is required to build this source tree.

      Make sure to increment the EXTRA_VERSION in configure.in when
      committing changes.

      Make sure to update the Changelog with each commit


git-svn-id: http://svn.osgeo.org/qgis/trunk@3112 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
gsherman 2005-04-10 07:04:07 +00:00
parent 3bbf810f64
commit 8c64ebf684
80 changed files with 11078 additions and 6674 deletions

View File

@ -1,20 +1,39 @@
QGIS Change Log
2005-01-29 [gsherman] 0.6.0devel5
** Applied patches from M. Loskot for a build error and missing Q_OBJECT
macros in qgsspit.h and qgsattributetable.h
2005-01-01 [larsl] 0.6.0devel4
2005-03-13 [jobi] 0.6.0devel6
- fix for building on 64bit architecture
- fixed dependencies of designer-plugin/stuff
2005-01-01 [larsl] 0.6.0devel4
** Fixed a bug that crashed QGIS when loading rasters from a project file, pt 2
QGIS Change Log
2005-01-01 [larsl] 0.6.0devel3
** Fixed a bug that crashed QGIS when loading rasters from a project file
QGIS Change Log
/* ChangeLog,v 1.214 2004/11/12 00:42:21 gsherman Exp */
------------------------------------------------------------------------------
Version 0.6 'Simon' .... development version
QGIS Change Log
2005-04-09 [ges] 0.6.0devel7
** Merged Projections_Branch into HEAD
Problems:
Polygon outlines are not drawn. This was checked twice and no cause
was found.
Projections do not work in all circumstances
Note that both the proj4 library and sqlite3 are now required. The
build system has not been modified to test for these yet.
Qt 3.3.x is required to build this source tree.
Make sure to increment the EXTRA_VERSION in configure.in when
committing changes.
Make sure to update the Changelog with each commit
2005-03-13 [jobi] 0.6.0devel6
- fix for building on 64bit architecture
- fixed dependencies of designer-plugin/stuff
2005-01-29 [gsherman] 0.6.0devel5
** Applied patches from M. Loskot for a build error and missing Q_OBJECT
macros in qgsspit.h and qgsattributetable.h
2005-01-01 [larsl] 0.6.0devel4
** Fixed a bug that crashed QGIS when loading rasters from a project file, pt 2
2005-01-01 [larsl] 0.6.0devel3
** Fixed a bug that crashed QGIS when loading rasters from a project file
QGIS Change Log
2004-12-30 [mcoletti] 0.6.0devel2
*** Re-factored endian-handling in data providers

View File

@ -31,8 +31,7 @@ docdatadir = $(datadir)/$(PACKAGE)/doc
docdata_DATA = AUTHORS
SUBDIRS = src providers plugins doc tools i18n
SUBDIRS = src widgets providers plugins doc tools i18n designer_plugins
pkginclude_HEADERS = qgsconfig.h
UIcheck:

View File

@ -26,7 +26,7 @@ dnl ---------------------------------------------------------------------------
MAJOR_VERSION=0
MINOR_VERSION=6
MICRO_VERSION=0
EXTRA_VERSION=6
EXTRA_VERSION=7
if test $EXTRA_VERSION -eq 0; then
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}
else
@ -314,6 +314,8 @@ AC_CONFIG_FILES([
plugins/north_arrow/Makefile
plugins/copyright_label/Makefile
plugins/scale_bar/Makefile
widgets/Makefile
widgets/projectionselector/Makefile
designer_plugins/Makefile
plugins/community_reg_plugin/Makefile
])

View File

@ -17,15 +17,20 @@ plugindir = ${pkglibdir}/designer
$(MOC) -o $@ $<
# name of the designer plugin
plugin_LTLIBRARIES = qgsdesignerwidgets.la
plugin_LTLIBRARIES = qgisdesignerwidgets.la
plugin_MOC = qgsdesignerwidgets.moc.cpp
plugin_MOC = qgsprojectionselectorplugin.moc.cpp
qgsdesignerwidgets_la_SOURCES = qgsdesignerwidgets.cpp \
qgisdesignerwidgets_la_SOURCES = qgsprojectionselectorplugin.cpp \
$(plugin_MOC)
BUILT_SOURCES = $(plugin_MOC)
qgsdesignerwidgets_la_LIBADD = $(QT_LDADD) ../src/libqgis.la $(GDAL_LDADD)
qgsdesignerwidgets_la_LDFLAGS = -avoid-version -module
qgsdesignerwidgets_la_CXXFLAGS = $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(DEBUG_QGIS) -I../src/
#projectionselector_la_LIBADD = ../src/libqgis.la $(QT_LDADD)
qgisdesignerwidgets_la_LIBADD = $(QT_LDADD) ../widgets/projectionselector/libqgsprojectionselector.la
qgisdesignerwidgets_la_LDFLAGS = -avoid-version -module
qgisdesignerwidgets_la_CXXFLAGS = $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(DEBUG_QGIS) -I../src/
EXTRA_DIST = $(plugin_UIC)

View File

@ -0,0 +1,95 @@
#include "qgsprojectionselectorplugin.h"
#include "../widgets/projectionselector/qgsprojectionselector.h"
static const char *projectionselector_pixmap[] = {
"22 22 8 1",
" c Gray100",
". c Gray97",
"X c #4f504f",
"o c #00007f",
"O c Gray0",
"+ c none",
"@ c Gray0",
"# c Gray0",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"+OOOOOOOOOOOOOOOOOOOO+",
"OOXXXXXXXXXXXXXXXXXXOO",
"OXX. O",
"OX. ooooooooo O",
"OX. o o .O",
"OX o o O",
"OX o o O",
"O o o O",
"OX o o o O",
"OX o o o O",
"OX o o O",
"OX ooooooooo o O",
"OO..................OO",
"+OOOOOOOOOOOOOOOOOOOO+",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"++++++++++++++++++++++"
};
QgsProjectionSelectorPlugin::QgsProjectionSelectorPlugin()
{
}
QStringList QgsProjectionSelectorPlugin::keys() const
{
QStringList list;
list << "QgsProjectionSelector";
return list;
}
QWidget* QgsProjectionSelectorPlugin::create( const QString &key, QWidget* parent, const char* name )
{
if ( key == "QgsProjectionSelector" )
return new QgsProjectionSelector( parent, name );
return 0;
}
QString QgsProjectionSelectorPlugin::group( const QString& feature ) const
{
if ( feature == "QgsProjectionSelector" )
return "QGIS";
return QString::null;
}
QIconSet QgsProjectionSelectorPlugin::iconSet( const QString& ) const
{
return QIconSet( QPixmap( projectionselector_pixmap ) );
}
QString QgsProjectionSelectorPlugin::includeFile( const QString& feature ) const
{
if ( feature == "QgsProjectionSelector" )
return "qgsprojectionselector.h";
return QString::null;
}
QString QgsProjectionSelectorPlugin::toolTip( const QString& feature ) const
{
if ( feature == "QgsProjectionSelector" )
return "QGIS Projection Selector Widget";
return QString::null;
}
QString QgsProjectionSelectorPlugin::whatsThis( const QString& feature ) const
{
if ( feature == "QgsProjectionSelector" )
return "A widget to choose a projection name from a list";
return QString::null;
}
bool QgsProjectionSelectorPlugin::isContainer( const QString& ) const
{
return FALSE;
}
Q_EXPORT_PLUGIN( QgsProjectionSelectorPlugin )

View File

@ -0,0 +1,17 @@
#include <qwidgetplugin.h>
class QgsProjectionSelectorPlugin : public QWidgetPlugin
{
Q_OBJECT
public:
QgsProjectionSelectorPlugin();
QStringList keys() const;
QWidget* create( const QString &classname, QWidget* parent = 0, const char* name = 0 );
QString group( const QString& ) const;
QIconSet iconSet( const QString& ) const;
QString includeFile( const QString& ) const;
QString toolTip( const QString& ) const;
QString whatsThis( const QString& ) const;
bool isContainer( const QString& ) const;
};

View File

@ -10,5 +10,5 @@
# Set software group
# The package maintainer (.deb)
checkinstall --default --pkgname=qgis --pkgversion=0.7.0pre --pkggroup=GIS --maintainer=tim@linfiniti.com
checkinstall --exclude ~/.ccache/stats --default --pkgname=qgis --pkgversion=0.7.0pre --pkggroup=GIS --maintainer=tim@linfiniti.com

View File

@ -17,6 +17,7 @@ nodist_i18n_DATA = \
qgis_fr.qm \
qgis_it.qm \
qgis_nl.qm \
qgis_pl_PL.qm \
qgis_pt_BR.qm \
qgis_ru.qm \
qgis_se.qm \
@ -28,6 +29,7 @@ i18n_SOURCES = \
qgis_fr.ts \
qgis_it.ts \
qgis_nl.ts \
qgis_pl_PL.ts \
qgis_pt_BR.ts \
qgis_ru.ts \
qgis_se.ts \

View File

@ -81,4 +81,6 @@ EXTRA_DIST = $(plugin_UIC) icon.xpm \
qgsgpsdevicedialog.h
endif

View File

@ -133,39 +133,55 @@ void GraticuleCreator::generateGraticule(DBFHandle theDbfHandle,
//create the arrays for storing the coordinates
double * myXArrayDouble;
double * myYArrayDouble;
myXArrayDouble = (double *)malloc(2 * sizeof(double)); //2=no vertices
myYArrayDouble = (double *)malloc(2 * sizeof(double));
//we want out graticule to be made of short line segments rather tban
//long ones that imply span xmin <-> xmax
//so that when reprojecting the graticule will warp properly
//so first we need to work out how many intersections there are...
//
long myXIntersectionCount = ((theXEndPointDouble - theXOriginDouble) / theXIntervalDouble)+1;
long myYIntersectionCount = ((theYEndPointDouble - theYOriginDouble) / theYIntervalDouble)+1;
//
//Longitude loop
//
myXArrayDouble = (double *)malloc(myYIntersectionCount * sizeof(double));
myYArrayDouble = (double *)malloc(myYIntersectionCount * sizeof(double));
for (double myXDouble = theXOriginDouble;myXDouble <=theXEndPointDouble;myXDouble+=theXIntervalDouble)
{
myXArrayDouble[0]=myXDouble;
myXArrayDouble[1]=myXDouble;
myYArrayDouble[0]=theYOriginDouble;
myYArrayDouble[1]=theYEndPointDouble;
long myVertexNo=0;
for (double myYDouble=theYOriginDouble;myYDouble<=theYEndPointDouble;myYDouble+=theYIntervalDouble)
{
myXArrayDouble[myVertexNo]=myXDouble;
myYArrayDouble[myVertexNo]=myYDouble;
++myVertexNo;
}
writeDbfRecord(theDbfHandle,myRecordInt,"testing");
writeLine(theShapeHandle, myRecordInt, 2, myXArrayDouble, myYArrayDouble); //2=no vertices
writeLine(theShapeHandle, myRecordInt, myYIntersectionCount, myXArrayDouble, myYArrayDouble);
++myRecordInt;
}
delete myXArrayDouble;
delete myYArrayDouble;
//
//Latitude loop
//
myXArrayDouble = (double *)malloc(myXIntersectionCount * sizeof(double));
myYArrayDouble = (double *)malloc(myXIntersectionCount * sizeof(double));
for (double myYDouble=theYOriginDouble;myYDouble<=theYEndPointDouble;myYDouble+=theYIntervalDouble)
{
myXArrayDouble[0]=theXOriginDouble;
myXArrayDouble[1]=theXEndPointDouble;
myYArrayDouble[0]=myYDouble;
myYArrayDouble[1]=myYDouble;
long myVertexNo=0;
for (double myXDouble=theXOriginDouble;myXDouble<=theXEndPointDouble;myXDouble+=theXIntervalDouble)
{
myXArrayDouble[myVertexNo]=myXDouble;
myYArrayDouble[myVertexNo]=myYDouble;
++myVertexNo;
}
writeDbfRecord(theDbfHandle,myRecordInt,"testing");
writeLine(theShapeHandle, myRecordInt, 2, myXArrayDouble, myYArrayDouble); //2=no vertices
writeLine(theShapeHandle, myRecordInt,myXIntersectionCount, myXArrayDouble, myYArrayDouble);
++myRecordInt;
}

View File

@ -215,6 +215,15 @@ public:
{
return 0;
};
/** The delimited text provider does not do its own transforms so we return
* false for the following three functions to indicate that transforms
* should be handled by the QgsCoordinateTransform object. See the
* documentation on QgsVectorDataProvider for details on these functions.
*/
bool supportsNativeTransform(){return false;}
bool usesSrid(){return false;}
bool usesWKT(){return false;}
private:
/** get the next feature, if any

View File

@ -421,6 +421,8 @@ public:
/** get data source uri (not implemented) */
QgsDataSourceURI * getURI(){ return 0;};
private:
// Layer type (layerType)
enum TYPE { // layer name:

View File

@ -173,6 +173,12 @@ QString QgsOgrProvider::getProjectionWKT()
// morph it
mySpatialRefSys->morphFromESRI();
}
// get the proj4 text
char * ppszProj4;
mySpatialRefSys->exportToProj4 ( &ppszProj4 );
std::cout << "vvvvvvvvvvvvvvvvv PROJ4 TEXT vvvvvvvvvvvvvvv" << std::endl;
std::cout << ppszProj4 << std::endl;
std::cout << "^^^^^^^^^^^^^^^^^ PROJ4 TEXT ^^^^^^^^^^^^^^^" << std::endl;
char *pszWKT = NULL;
mySpatialRefSys->exportToWkt( &pszWKT );
QString myWKTString = QString(pszWKT);

View File

@ -594,12 +594,12 @@ void QgsPostgresProvider::select(QgsRect * rect, bool useIntersect)
// Contributed by #qgis irc "creeping"
// This version actually invokes PostGIS's use of spatial indexes
declare += " where " + geometryColumn;
declare += " && GeometryFromText('BOX3D(" + rect->stringRep();
declare += " && setsrid('BOX3D(" + rect->stringRep();
declare += ")'::box3d,";
declare += srid;
declare += ")";
declare += " and intersects(" + geometryColumn;
declare += ", GeometryFromText('BOX3D(" + rect->stringRep();
declare += ", setsrid('BOX3D(" + rect->stringRep();
declare += ")'::box3d,";
declare += srid;
declare += "))";
@ -623,7 +623,7 @@ void QgsPostgresProvider::select(QgsRect * rect, bool useIntersect)
PQexec(connection, "end work");
}
PQexec(connection,"begin work");
PQexec(connection, (const char *)declare);
PQexec(connection, (const char *)(declare.utf8()));
}
/**
@ -718,12 +718,12 @@ int QgsPostgresProvider::fieldCount() const
*/
void QgsPostgresProvider::getFeatureAttributes(int key, QgsFeature *f){
QString sql = QString("select * from \"%1\" where %2 = %3").arg(tableName).arg(primaryKey).arg(key);
QString sql = QString("select * from %1 where %2 = %3").arg(tableName).arg(primaryKey).arg(key);
#ifdef QGISDEBUG
// std::cerr << "getFeatureAttributes using: " << sql << std::endl;
#endif
PGresult *attr = PQexec(connection, (const char *)sql);
PGresult *attr = PQexec(connection, (const char *)(sql.utf8()));
for (int i = 0; i < fieldCount(); i++) {
QString fld = PQfname(attr, i);
@ -731,7 +731,7 @@ void QgsPostgresProvider::getFeatureAttributes(int key, QgsFeature *f){
// results
if(fld != geometryColumn){
// Add the attribute to the feature
QString val = PQgetvalue(attr,0, i);
QString val = QString::fromUtf8(PQgetvalue(attr,0, i));
f->addAttribute(fld, val);
}
}
@ -752,14 +752,14 @@ void QgsPostgresProvider::getFeatureAttributes(int key,
.arg(tableName)
.arg(primaryKey)
.arg(key);//todo: only query one attribute
PGresult *attr = PQexec(connection, (const char *)sql);
PGresult *attr = PQexec(connection, (const char *)(sql.utf8()));
QString fld = PQfname(attr, 0);
// Dont add the WKT representation of the geometry column to the identify
// results
if(fld != geometryColumn)
{
// Add the attribute to the feature
QString val = PQgetvalue(attr,0, i);
QString val = QString::fromUtf8(PQgetvalue(attr,0, i));
//qWarning(val);
f->addAttribute(fld, val);
}
@ -791,7 +791,7 @@ void QgsPostgresProvider::reset()
PQexec(connection,"end work");
PQexec(connection,"begin work");
PQexec(connection, (const char *)declare);
PQexec(connection, (const char *)(declare.utf8()));
//--std::cout << "Error: " << PQerrorMessage(connection) << std::endl;
ready = true;
}
@ -854,9 +854,8 @@ QString QgsPostgresProvider::getPrimaryKey()
#ifdef QGISDEBUG
std::cerr << "Getting primary key using '" << sql << "'\n";
#endif
PGresult *pk = PQexec(connection,(const char *)sql);
// XXX Do we need the utf8 here ?? Couldn't tell when doing the merge... -ges
PGresult *pk = PQexec(connection,(const char *)(sql.utf8()));
#ifdef QGISDEBUG
std::cerr << "Got " << PQntuples(pk) << " rows.\n";
#endif
@ -1412,7 +1411,7 @@ QString QgsPostgresProvider::minValue(int position){
{
sql = QString("select min(%1) from \"%2\"").arg(fld.name()).arg(tableName)+" where "+sqlWhereClause;
}
PGresult *rmin = PQexec(connection,(const char *)sql);
PGresult *rmin = PQexec(connection,(const char *)(sql.utf8()));
QString minValue = PQgetvalue(rmin,0,0);
PQclear(rmin);
return minValue;
@ -1432,7 +1431,7 @@ QString QgsPostgresProvider::maxValue(int position){
{
sql = QString("select max(%1) from \"%2\"").arg(fld.name()).arg(tableName)+" where "+sqlWhereClause;
}
PGresult *rmax = PQexec(connection,(const char *)sql);
PGresult *rmax = PQexec(connection,(const char *)(sql.utf8()));
QString maxValue = PQgetvalue(rmax,0,0);
PQclear(rmax);
return maxValue;
@ -1522,7 +1521,7 @@ bool QgsPostgresProvider::addFeature(QgsFeature* f)
#endif
//send INSERT statement and do error handling
PGresult* result=PQexec(connection, (const char *)insert);
PGresult* result=PQexec(connection, (const char *)(insert.utf8()));
if(result==0)
{
QMessageBox::information(0,"INSERT error","An error occured during feature insertion",QMessageBox::Ok);
@ -1553,7 +1552,7 @@ bool QgsPostgresProvider::deleteFeature(int id)
#endif
//send DELETE statement and do error handling
PGresult* result=PQexec(connection, (const char *)sql);
PGresult* result=PQexec(connection, (const char *)(sql.utf8()));
if(result==0)
{
QMessageBox::information(0,"DELETE error","An error occured during deletion from disk",QMessageBox::Ok);
@ -1730,7 +1729,7 @@ bool QgsPostgresProvider::changeAttributeValues(std::map<int,std::map<QString,QS
#endif
//send sql statement and do error handling
PGresult* result=PQexec(connection, (const char *)sql);
PGresult* result=PQexec(connection, (const char *)(sql.utf8()));
if(result==0)
{
returnvalue=false;

View File

@ -257,6 +257,22 @@ public:
/**Returns a bitmask containing the supported capabilities*/
int capabilities() const;
/** The Postgres provider does its own transforms so we return
* true for the following three functions to indicate that transforms
* should not be handled by the QgsCoordinateTransform object. See the
* documentation on QgsVectorDataProvider for details on these functions.
*/
// XXX For now we have disabled native transforms in the PG provider since
// it appears there are problems with some of the projection definitions
bool supportsNativeTransform(){return false;}
bool usesSrid(){return true;}
bool usesWKT(){return false;}
/*! Set the SRID of the target (map canvas) SRS.
* @parm srid SRID of the map canvas SRS
*/
void setTargetSrid(int srid);
signals:
/**

View File

@ -1,27 +1,26 @@
<?xml version = '1.0'?>
<kdevelop>
<general>
<author>The QGIS Team</author>
<email>qgis-developer@lists.sourceforge.net</email>
<author>Gary Sherman</author>
<email>gsherman at mrcc dot com</email>
<version>$VERSION$</version>
<projectmanagement>KDevAutoProject</projectmanagement>
<primarylanguage>C++</primarylanguage>
<ignoreparts/>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
<description/>
<secondaryLanguages/>
<description></description>
</general>
<kdevautoproject>
<general>
<activetarget>src/qgis</activetarget>
<useconfiguration>default</useconfiguration>
<useconfiguration>debug</useconfiguration>
</general>
<run>
<mainprogram>/home/aps02ts/bin/qgis</mainprogram>
<mainprogram>/home/gsherman/development/qgis07_dev/debug/src/qgis</mainprogram>
<directoryradio>custom</directoryradio>
<customdirectory>/home/aps02ts/bin/</customdirectory>
<programargs/>
<customdirectory>/</customdirectory>
<programargs></programargs>
<terminal>false</terminal>
<autocompile>true</autocompile>
<envvars/>
@ -35,60 +34,43 @@
<cxxflags>-O2 -g0</cxxflags>
</optimized>
<debug>
<configargs>--enable-debug=full --prefix=$HOME</configargs>
<configargs>--enable-debug=full --prefix=/home/gsherman/qgis07_head --with-grass=/usr/local/grass-5.7.0_org</configargs>
<builddir>debug</builddir>
<ccompiler>kdevgccoptions</ccompiler>
<cxxcompiler>kdevgppoptions</cxxcompiler>
<f77compiler>kdevpgf77options</f77compiler>
<cxxflags>-O0 -g3</cxxflags>
<envvars/>
<topsourcedir/>
<cppflags/>
<ldflags/>
<ccompilerbinary/>
<cxxcompilerbinary/>
<f77compilerbinary/>
<cflags/>
<f77flags/>
<topsourcedir></topsourcedir>
<cppflags></cppflags>
<ldflags></ldflags>
<ccompilerbinary></ccompilerbinary>
<cxxcompilerbinary></cxxcompilerbinary>
<f77compilerbinary></f77compilerbinary>
<cflags></cflags>
<f77flags></f77flags>
</debug>
<default>
<envvars/>
<configargs>--prefix=$HOME --enable-debug</configargs>
<builddir/>
<topsourcedir/>
<cppflags/>
<ldflags/>
<ccompiler>kdevgccoptions</ccompiler>
<cxxcompiler>kdevgppoptions</cxxcompiler>
<f77compiler>kdevpgf77options</f77compiler>
<ccompilerbinary/>
<cxxcompilerbinary/>
<f77compilerbinary/>
<cflags/>
<cxxflags/>
<f77flags/>
</default>
</configurations>
<make>
<envvars>
<envvar value="1" name="WANT_AUTOCONF_2_5" />
<envvar value="1" name="WANT_AUTOMAKE_1_6" />
</envvars>
<abortonerror>false</abortonerror>
<abortonerror>true</abortonerror>
<numberofjobs>1</numberofjobs>
<dontact>false</dontact>
<makebin/>
<makebin></makebin>
<prio>0</prio>
</make>
</kdevautoproject>
<kdevdebugger>
<general>
<dbgshell>libtool</dbgshell>
<programargs/>
<gdbpath/>
<configGdbScript/>
<runShellScript/>
<runGdbScript/>
<programargs></programargs>
<gdbpath></gdbpath>
<configGdbScript></configGdbScript>
<runShellScript></runShellScript>
<runGdbScript></runGdbScript>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
@ -172,31 +154,26 @@
<argumentsHintDelay>400</argumentsHintDelay>
<headerCompletionDelay>250</headerCompletionDelay>
</codecompletion>
<references/>
<creategettersetter>
<prefixGet></prefixGet>
<prefixSet>set</prefixSet>
<prefixVariable>m_,_</prefixVariable>
<parameterName>theValue</parameterName>
<inlineGet>true</inlineGet>
<inlineSet>true</inlineSet>
</creategettersetter>
<references>
<pcs>Qt</pcs>
</references>
</kdevcppsupport>
<kdevdocumentation>
<projectdoc>
<docsystem/>
<docurl/>
<usermanualurl/>
</projectdoc>
</kdevdocumentation>
<kdevfileview>
<groups>
<hidenonprojectfiles>false</hidenonprojectfiles>
<hidenonlocation>false</hidenonlocation>
</groups>
<tree>
<showvcsfields>false</showvcsfields>
<hidenonprojectfiles>false</hidenonprojectfiles>
<hidepatterns>*.o,*.lo,CVS</hidepatterns>
<hidenonprojectfiles>false</hidenonprojectfiles>
</tree>
</kdevfileview>
<kdevcvsservice>
<recursivewhenupdate>true</recursivewhenupdate>
<prunedirswhenupdate>true</prunedirswhenupdate>
<createdirswhenupdate>true</createdirswhenupdate>
<recursivewhencommitremove>true</recursivewhencommitremove>
<revertoptions>-C</revertoptions>
</kdevcvsservice>
</kdevelop>

View File

@ -13,7 +13,7 @@ SUBDIRS = svg images themes resources
PREFIX=-DPREFIX=\"$(prefix)\"
PLUGINPATH=-DPLUGINPATH=\"$(pkglibdir)\"
PKGDATAPATH=-DPKGDATAPATH=\"$(pkgdatadir)\"
WIDGETPATH=../widgets
%.moc.cpp: %.h
$(MOC) -o $@ $<
@ -41,6 +41,7 @@ headers = qgisapp.h \
qgsacetatelines.h \
qgsacetateobject.h \
qgsacetaterectangle.h \
qgsaddattrdialog.h \
qgsattributeaction.h \
qgsattributeactiondialog.h \
qgsattributedialog.h \
@ -125,6 +126,8 @@ headers = qgisapp.h \
qgssimarenderer.h \
qgssinglesymrenderer.h \
qgssisydialog.h \
qgsspatialrefsys.h \
qgsspatialreferences.h \
qgssvgcache.h \
qgsmarkercatalogue.h \
qgssymbol.h \
@ -136,6 +139,9 @@ headers = qgisapp.h \
qgsvectordataprovider.h \
qgsvectorfilewriter.h \
qgsvectorlayer.h \
splashscreen.h \
qgslayerprojectionselector.h \
$(WIDGETPATH)/projectionselector/qgsprojectionselector.h \
qgspointstylewidget.h \
qgslinestylewidget.h \
qgsfillstylewidget.h \
@ -181,6 +187,8 @@ qgis_UIC = qgisappbase.ui \
qgssimadialogbase.ui \
qgssisydialogbase.ui \
qgsuvaldialogbase.ui \
qgslayerprojectionselectorbase.ui \
$(WIDGETPATH)/projectionselector/qgsprojectionselectorbase.ui \
qgsuvalmadialogbase.ui \
qgspointstylewidgetbase.ui \
qgsfillstylewidgetbase.ui \
@ -204,6 +212,7 @@ qgis_UIH = qgisappbase.ui.h \
qgsoptionsbase.ui.h \
qgsrasterlayerpropertiesbase.ui.h \
qgslabeldialogbase.ui.h \
qgslayerprojectionselectorbase.ui.h \
qgsprojectpropertiesbase.ui.h
## these generated files need MOC files, too
@ -217,21 +226,22 @@ qgis_MOC = qgisapp.moc.cpp \
qgsaddattrdialog.moc.cpp \
qgsattributeactiondialog.moc.cpp \
qgsattributedialog.moc.cpp \
qgsattributetable.moc.cpp \
qgscomposer.moc.cpp \
qgscomposition.moc.cpp \
qgscomposermap.moc.cpp \
qgscomposervectorlegend.moc.cpp \
qgscomposerlabel.moc.cpp \
qgscomposerscalebar.moc.cpp \
qgscomposerview.moc.cpp \
qgsattributetabledisplay.moc.cpp \
qgscoordinatetransform.moc.cpp \
qgsattributetable.moc.cpp \
qgscomposerlabel.moc.cpp \
qgscomposermap.moc.cpp \
qgscomposer.moc.cpp \
qgscomposerscalebar.moc.cpp \
qgscomposervectorlegend.moc.cpp \
qgscomposerview.moc.cpp \
qgscomposition.moc.cpp \
qgscontcoldialog.moc.cpp \
qgscoordinatetransform.moc.cpp \
qgsdataprovider.moc.cpp \
qgsdelattrdialog.moc.cpp \
qgsdlgvectorlayerproperties.moc.cpp \
qgsencodingfiledialog.moc.cpp \
qgsfillstylewidget.moc.cpp \
qgsgeomtypedialog.moc.cpp \
qgsgramadialog.moc.cpp \
qgsgramaextensionwidget.moc.cpp \
@ -239,7 +249,10 @@ qgis_MOC = qgisapp.moc.cpp \
qgshelpviewer.moc.cpp \
qgsidentifyresults.moc.cpp \
qgslabeldialog.moc.cpp \
qgslayerprojectionselector.moc.cpp \
qgslegend.moc.cpp \
qgslinestyledialog.moc.cpp \
qgslinestylewidget.moc.cpp \
qgsludialog.moc.cpp \
qgsmapcanvas.moc.cpp \
qgsmaplayerinterface.moc.cpp \
@ -251,6 +264,7 @@ qgis_MOC = qgisapp.moc.cpp \
qgsoptions.moc.cpp \
qgspatterndialog.moc.cpp \
qgspluginmanager.moc.cpp \
qgspointstylewidget.moc.cpp \
qgsprojectproperties.moc.cpp \
qgsrasterlayer.moc.cpp \
qgsrasterlayerproperties.moc.cpp \
@ -259,12 +273,10 @@ qgis_MOC = qgisapp.moc.cpp \
qgssisydialog.moc.cpp \
qgsuvaldialog.moc.cpp \
qgsuvalmadialog.moc.cpp \
qgsvectorlayer.moc.cpp \
qgsvectordataprovider.moc.cpp \
qgspointstylewidget.moc.cpp \
qgsfillstylewidget.moc.cpp \
qgslinestylewidget.moc.cpp \
splashscreen.moc.cpp
qgsvectorlayer.moc.cpp \
splashscreen.moc.cpp \
$(WIDGETPATH)/projectionselector/qgsprojectionselector.moc.cpp
# qgsvectorsymbologywidget.moc.cpp
@ -284,27 +296,26 @@ qgis_SOURCES = main.cpp \
qgsclipper.cpp \
qgscolortable.cpp \
qgscomposer.cpp \
qgscomposition.cpp \
qgscomposeritem.cpp \
qgscomposermap.cpp \
qgscomposervectorlegend.cpp \
qgscomposerlabel.cpp \
qgscomposermap.cpp \
qgscomposerscalebar.cpp \
qgscomposervectorlegend.cpp \
qgscomposerview.cpp \
qgscomposition.cpp \
qgscontcoldialog.cpp \
qgscontinuouscolrenderer.cpp \
qgscoordinatetransform.cpp \
qgsencodingfiledialog.cpp \
qgsmaptopixel.cpp \
qgscustomsymbol.cpp \
qgsdatasource.cpp \
qgsdelattrdialog.cpp \
qgsdlgvectorlayerproperties.cpp \
qgsencodingfiledialog.cpp \
qgsfeatureattribute.cpp \
qgsfeature.cpp \
qgsfield.cpp \
qgsfillstylewidget.cpp \
qgsgeomtypedialog.cpp \
qgsrenderer.cpp \
qgsgraduatedmarenderer.cpp \
qgsgraduatedsymrenderer.cpp \
qgsgramadialog.cpp \
@ -315,14 +326,20 @@ qgis_SOURCES = main.cpp \
qgslabelattributes.cpp \
qgslabel.cpp \
qgslabeldialog.cpp \
qgslayerprojectionselector.cpp \
qgslegend.cpp \
qgslegenditem.cpp \
qgsline.cpp \
qgslinestyledialog.cpp \
qgslinestylewidget.cpp \
qgslinesymbol.cpp \
qgsludialog.cpp \
qgsmapcanvas.cpp \
qgsmaplayer.cpp \
qgsmaplayerregistry.cpp \
qgsmapserverexport.cpp \
qgsmaptopixel.cpp \
qgsmarkercatalogue.cpp \
qgsmarkerdialog.cpp \
qgsmarkersymbol.cpp \
qgsmeasure.cpp \
@ -333,6 +350,7 @@ qgis_SOURCES = main.cpp \
qgspluginmetadata.cpp \
qgspluginregistry.cpp \
qgspoint.cpp \
qgspointstylewidget.cpp \
qgspolygonsymbol.cpp \
qgsproject.cpp \
qgsprojectproperties.cpp \
@ -345,6 +363,7 @@ qgis_SOURCES = main.cpp \
qgsrasterlayer.cpp \
qgsrasterlayerproperties.cpp \
qgsrect.cpp \
qgsrenderer.cpp \
qgsrenderitem.cpp \
qgsrunprocess.cpp \
qgsscalecalculator.cpp \
@ -352,8 +371,9 @@ qgis_SOURCES = main.cpp \
qgssimarenderer.cpp \
qgssinglesymrenderer.cpp \
qgssisydialog.cpp \
qgsspatialreferences.cpp \
qgsspatialrefsys.cpp \
qgssvgcache.cpp \
qgsmarkercatalogue.cpp \
qgssymbol.cpp \
qgssymbologyutils.cpp \
qgsuniquevalrenderer.cpp \
@ -363,10 +383,8 @@ qgis_SOURCES = main.cpp \
qgsvectordataprovider.cpp \
qgsvectorfilewriter.cpp \
qgsvectorlayer.cpp \
qgspointstylewidget.cpp \
qgslinestylewidget.cpp \
qgsfillstylewidget.cpp \
splashscreen.cpp
splashscreen.cpp \
$(WIDGETPATH)/projectionselector/qgsprojectionselector.cpp
# qgsvectorsymbologywidget.cpp
@ -406,61 +424,69 @@ BUILT_SOURCES = $(qgis_MOC) $(qgis_UIMOC) $(qgis_UIHEADERS) $(qgis_UISOURCES) \
$(postgresMOC) $(postgresUIMOC) $(postgresUIHEADERS) $(postgresUISOURCES)
qgis_LDADD = $(LDADD) $(QT_LDADD) $(GDAL_LDADD) $(PG_LIB) $(GEOS_LDADD) libqgis.la
qgis_LDADD = $(LDADD) $(QT_LDADD) $(GDAL_LDADD) $(PG_LIB) $(GEOS_LDADD) -lproj -lsqlite3 libqgis.la
qgis_LDFLAGS = -rdynamic
qgis_CXXFLAGS = $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) -I$(PG_INC) $(DEBUG_QGIS) $(GEOS_CFLAGS)
qgis_CXXFLAGS = $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) -I$(PG_INC) $(DEBUG_QGIS) $(GEOS_CFLAGS) -I../widgets/projectionselector/
libqgis_la_SOURCES = \
qgisapp.cpp \
qgisapp.moc.cpp \
qgisappbase.moc.uic.cpp \
qgisappbase.uic.cpp \
qgisapp.cpp \
qgisapp.moc.cpp \
qgsacetateobject.cpp \
qgsacetaterectangle.cpp \
qgsattributeaction.cpp \
qgsclipper.cpp \
qgscolortable.cpp \
qgscomposer.cpp \
qgscomposer.moc.cpp \
qgscomposerbase.uic.cpp \
qgscomposerbase.moc.uic.cpp \
qgscomposerbase.uic.cpp \
qgscomposer.cpp \
qgscomposeritem.cpp \
qgscomposerlabelbase.moc.uic.cpp \
qgscomposerlabelbase.uic.cpp \
qgscomposerlabel.cpp \
qgscomposerlabel.moc.cpp \
qgscomposerlabelbase.uic.cpp \
qgscomposerlabelbase.moc.uic.cpp \
qgscomposerscalebar.cpp \
qgscomposerscalebar.moc.cpp \
qgscomposerscalebarbase.uic.cpp \
qgscomposerscalebarbase.moc.uic.cpp \
qgscomposermapbase.moc.uic.cpp \
qgscomposermapbase.uic.cpp \
qgscomposermap.cpp \
qgscomposermap.moc.cpp \
qgscomposermapbase.uic.cpp \
qgscomposermapbase.moc.uic.cpp \
qgscompositionbase.uic.cpp \
qgscompositionbase.moc.uic.cpp \
qgscomposer.moc.cpp \
qgscomposerscalebarbase.moc.uic.cpp \
qgscomposerscalebarbase.uic.cpp \
qgscomposerscalebar.cpp \
qgscomposerscalebar.moc.cpp \
qgscomposervectorlegendbase.moc.uic.cpp \
qgscomposervectorlegendbase.uic.cpp \
qgscomposervectorlegend.cpp \
qgscomposervectorlegend.moc.cpp \
qgscomposervectorlegendbase.uic.cpp \
qgscomposervectorlegendbase.moc.uic.cpp \
qgscomposerview.moc.cpp \
qgscomposerview.cpp \
qgscomposerview.moc.cpp \
qgscompositionbase.moc.uic.cpp \
qgscompositionbase.uic.cpp \
qgscomposition.cpp \
qgscomposition.moc.cpp \
qgscontinuouscolrenderer.cpp \
qgscoordinatetransform.cpp \
qgscoordinatetransform.moc.cpp \
qgsdataprovider.moc.cpp \
qgsfeature.cpp \
qgsfeatureattribute.cpp \
qgsfeature.cpp \
qgsfield.cpp \
qgsfillstylewidgetbase.moc.uic.cpp \
qgsfillstylewidgetbase.uic.cpp \
qgsfillstylewidget.cpp \
qgsfillstylewidget.moc.cpp
qgsgraduatedmarenderer.cpp \
qgsgraduatedsymrenderer.cpp \
qgslabel.cpp \
qgslegend.cpp \
qgslegend.moc.cpp \
qgslegenditem.cpp \
qgslegenditem.moc.cpp \
qgslegend.moc.cpp \
qgslinestylewidgetbase.moc.uic.cpp \
qgslinestylewidgetbase.uic.cpp \
qgslinestylewidget.cpp \
qgslinestylewidget.moc.cpp \
qgsmapcanvas.cpp \
qgsmapcanvas.moc.cpp \
qgsmaplayer.cpp \
@ -468,9 +494,15 @@ libqgis_la_SOURCES = \
qgsmaplayerregistry.cpp \
qgsmaplayerregistry.moc.cpp \
qgsmaptopixel.cpp \
qgsmarkercatalogue.cpp \
qgsmarkersymbol.cpp \
qgspoint.cpp \
qgspoint.moc.cpp \
qgspointstylewidgetbase.moc.uic.cpp \
qgspointstylewidgetbase.uic.cpp \
qgspointstylewidget.cpp \
qgspointstylewidget.moc.cpp \
qgsprojectproperty.cpp \
qgsprojectproperty.cpp \
qgsprovidercountcalcevent.cpp \
qgsproviderextentcalcevent.cpp \
@ -480,13 +512,15 @@ libqgis_la_SOURCES = \
qgsrasterlayer.moc.cpp \
qgsrect.cpp \
qgsrenderer.cpp \
qgsrenderer.cpp \
qgsrenderitem.cpp \
qgsrunprocess.cpp \
qgsrunprocess.moc.cpp \
qgsscalecalculator.cpp \
qgssimarenderer.cpp \
qgssinglesymrenderer.cpp \
qgsmarkercatalogue.cpp \
qgsspatialreferences.cpp \
qgsspatialrefsys.cpp \
qgssymbol.cpp \
qgsuniquevalrenderer.cpp \
qgsuvalmarenderer.cpp \
@ -494,29 +528,16 @@ libqgis_la_SOURCES = \
qgsvectordataprovider.moc.cpp \
qgsvectorfilewriter.cpp \
qgsvectorlayer.cpp \
qgsvectorlayer.moc.cpp \
qgspointstylewidgetbase.uic.cpp \
qgspointstylewidgetbase.moc.uic.cpp \
qgslinestylewidgetbase.uic.cpp \
qgslinestylewidgetbase.moc.uic.cpp \
qgsfillstylewidgetbase.uic.cpp \
qgsfillstylewidgetbase.moc.uic.cpp \
qgspointstylewidget.cpp \
qgspointstylewidget.moc.cpp \
qgslinestylewidget.cpp \
qgslinestylewidget.moc.cpp \
qgsfillstylewidget.cpp \
qgsfillstylewidget.moc.cpp
qgsvectorlayer.moc.cpp
if HAVE_POSTGRESQL
libqgis_la_SOURCES += $(postgresLIBSOURCES)
endif
libqgis_la_LIBFLAGS = $(QT_LDADD) $(GEOS_LDADD)
libqgis_la_LDFLAGS = -version-info $(INTERFACE_VERSION)
libqgis_la_CXXFLAGS = $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) -I$(PG_INC) $(DEBUG_QGIS) $(GEOS_CFLAGS)
libqgis_la_LIBFLAGS = $(QT_LDADD) $(GEOS_LDADD) $(GDAL_LDADD)
libqgis_la_LDFLAGS = -version-info $(INTERFACE_VERSION) $(QT_LDADD) $(GDAL_LDADD) -lsqlite3
libqgis_la_CXXFLAGS = $(PREFIX) $(PLUGINPATH) $(PKGDATAPATH) $(GDAL_CFLAGS) $(CXXFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) -I$(PG_INC) $(DEBUG_QGIS) $(GEOS_CFLAGS) -I../widgets/projectionselector/
## for installing headers in $(includedir)/qgis
pkginclude_HEADERS = $(headers) $(qgis_UIHEADERS) $(qgis_UIH) $(postgresHEADERS) $(postgresUIH)

View File

@ -109,4 +109,12 @@ namespace QGis
};
}
//! Structure for storing a spatial_ref_sys item
typedef struct{
QString srid; // spatial reference id (ala PostGIS)
QString auth_name; // name of the author for this SRS
QString auth_srid; // srid used by the author
QString srtext; // WKT of the coordinate system
QString proj4text; // Proj4 parameter string
} SPATIAL_REF_SYS;
#endif

View File

@ -2350,6 +2350,7 @@ void QgisApp::stopZoom()
}
}
void QgisApp::attributeTable()
{
QListViewItem *li = mMapLegend->currentItem();
@ -2705,7 +2706,11 @@ void QgisApp::zoomToLayerExtent()
// get the selected item
QListViewItem *li = mMapLegend->currentItem();
QgsMapLayer *layer = ((QgsLegendItem *) li)->layer();
mMapCanvas->setExtent(layer->extent());
// the layer extent has to be transformed to the map canvas
// coordinate system
QgsCoordinateTransform *ct = layer->coordinateTransform();
QgsRect transformedExtent = ct->transform(layer->extent());
mMapCanvas->setExtent(transformedExtent);
mMapCanvas->clear();
mMapCanvas->render();
@ -3797,23 +3802,42 @@ void QgisApp::showStatusMessage(QString theMessage)
void QgisApp::projectProperties()
{
/* Display the property sheet for the Project */
// set wait cursor since construction of the project properties
// dialog results in the construction of the spatial reference
// system QMap
QApplication::setOverrideCursor(Qt::WaitCursor);
QgsProjectProperties *pp = new QgsProjectProperties(this);
qApp->processEvents();
// Be told if the mouse display precision may have changed by the user
// changing things in the project properties dialog box
connect(pp, SIGNAL(displayPrecisionChanged()), this, SLOT(updateMouseCoordinatePrecision()));
connect(pp, SIGNAL(displayPrecisionChanged()), this,
SLOT(updateMouseCoordinatePrecision()));
QApplication::restoreOverrideCursor();
//pass any refresg signals off to canvases
connect (pp,SIGNAL(refresh()), mMapCanvas, SLOT(refresh()));
connect (pp,SIGNAL(refresh()), mOverviewCanvas, SLOT(refresh()));
// Display the modal dialog box.
pp->exec();
// set the map units for the project if they have changed
if (mMapCanvas->mapUnits() != pp->mapUnits())
{
mMapCanvas->setMapUnits(pp->mapUnits());
}
// If the canvas is projected, we need to recalculate the extents in the
// new coordinate system
if(pp->isProjected())
{
mMapCanvas->recalculateExtents();
}
// Set the window title. No way to do a comparison like for the map
// units above, so redo it everytime.
setTitleBarText_( *this );
// delete the property sheet object
delete pp;
} // QgisApp::projectProperties
@ -4357,5 +4381,10 @@ void QgisApp::keyPressEvent ( QKeyEvent * e )
std::cout << e->ascii() << " (keypress recevied)" << std::endl;
emit keyPressed (e);
}
// Debug hook - used to output diagnostic messages when evoked (usually from the menu)
void QgisApp::debugHook()
{
std::cout << "Hello from debug hook" << std::endl;
// show the map canvas extent
std::cout << mMapCanvas->extent() << std::endl;
}

View File

@ -360,6 +360,7 @@ public slots:
void setLayerOverviewStatus(QString theLayerId, bool theVisibilityFlag);
void drawExtentRectangle(QPainter *);
void updateMouseCoordinatePrecision();
void debugHook();
void stopZoom();
signals:

View File

@ -107,6 +107,9 @@
<separator/>
<action name="actionHelpAbout"/>
</item>
<item text="Debug" name="Debug">
<action name="actionDebugHook"/>
</item>
</menubar>
<toolbars>
<toolbar dock="2">
@ -1105,6 +1108,17 @@
<string>New Vectorlayer</string>
</property>
</action>
<action>
<property name="name">
<cstring>actionDebugHook</cstring>
</property>
<property name="text">
<string>DebugHook</string>
</property>
<property name="toolTip">
<string>DebugHook to which random stuff can be attached</string>
</property>
</action>
</actions>
<images>
<image name="image0">
@ -1493,6 +1507,12 @@
<receiver>QgisAppBase</receiver>
<slot>measure()</slot>
</connection>
<connection>
<sender>actionDebugHook</sender>
<signal>activated()</signal>
<receiver>QgisAppBase</receiver>
<slot>debugHook()</slot>
</connection>
</connections>
<includes>
<include location="global" impldecl="in implementation">iostream</include>
@ -1548,6 +1568,7 @@
<slot>deleteSelected()</slot>
<slot>zoomToLayer()</slot>
<slot>zoomToLayerExtent()</slot>
<slot>debugHook()</slot>
<slot>measure()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>

View File

@ -303,6 +303,12 @@ void QgisAppBase::zoomToLayerExtent()
}
void QgisAppBase::debugHook()
{
}
void QgisAppBase::measure()

View File

@ -76,12 +76,15 @@ class QgsRect;
class QgsMapToPixel;
class QgsComposition;
class QgsComposerMap;
class QgsComposerItem;
/** \class QgsComposerVectorLegend
* \brief Object representing map window.
*/
// NOTE: QgsComposerVectorLegendBase must be first, otherwise does not compile
class QgsComposerVectorLegend : public QgsComposerVectorLegendBase, public QCanvasRectangle, public QgsComposerItem
class QgsComposerVectorLegend : public QgsComposerVectorLegendBase,
public QCanvasRectangle,
public QgsComposerItem
{
Q_OBJECT

View File

@ -40,14 +40,15 @@
#include "qgscomposerscalebar.h"
QgsCompositionPaper::QgsCompositionPaper ( QString name, int w, int h, bool c)
:mName(name), mWidth(w), mHeight(h), mCustom(c)
{
mName = name; mWidth = w; mHeight = h; mCustom = c;
}
QgsCompositionPaper::~QgsCompositionPaper ( )
{
}
QgsComposition::QgsComposition( QgsComposer *c, int id )
{
#ifdef QGISDEBUG

View File

@ -15,21 +15,23 @@
* *
***************************************************************************/
/* $Id$ */
#include <cassert>
#include "qgscoordinatetransform.h"
#include "qgsspatialreferences.h"
QgsCoordinateTransform::QgsCoordinateTransform( QString theSourceWKT, QString theDestWKT ) : QObject()
QgsCoordinateTransform::QgsCoordinateTransform( QString theSourceWKT, QString theDestWKT ) : QObject(),
mSourceWKT(theSourceWKT), mDestWKT(theDestWKT)
{
mSourceWKT = theSourceWKT;
mDestWKT = theDestWKT;
// initialize the coordinate system data structures
//XXX Who spells initialize initialise?
//XXX A: Its the queen's english....
//XXX : Long live the queen! Lets get on with the initialisation...
initialise();
}
QgsCoordinateTransform::~QgsCoordinateTransform()
{
delete mSourceToDestXForm;
delete mDestToSourceXForm;
}
void QgsCoordinateTransform::setSourceWKT(QString theWKT)
@ -45,45 +47,47 @@ void QgsCoordinateTransform::setDestWKT(QString theWKT)
mDestWKT = theWKT;
initialise();
}
// XXX This whole function is full of multiple return statements!!!
void QgsCoordinateTransform::initialise()
{
mInitialisedFlag=false; //guilty until proven innocent...
//default to geo / wgs84 for now .... later we will make this user configurable
QString myGeoWKT = "GEOGCS[\"WGS 84\", "
" DATUM[\"WGS_1984\", "
" SPHEROID[\"WGS 84\",6378137,298.257223563, "
" AUTHORITY[\"EPSG\",7030]], "
" TOWGS84[0,0,0,0,0,0,0], "
" AUTHORITY[\"EPSG\",6326]], "
" PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",8901]], "
" UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",9108]], "
" AXIS[\"Lat\",NORTH], "
" AXIS[\"Long\",EAST], "
" AUTHORITY[\"EPSG\",4326]]";
// Default to geo / wgs84 for now ....
// Later we will make this user configurable
// SRID 4326 is geographic wgs84 - use the SRS singleton to fetch
// the WKT for the coordinate system
QString defaultWkt = QgsSpatialReferences::instance()->getSrsBySrid("4326")->srText();
//default input projection to geo wgs84
// XXX Warning - multiple return paths in this block!!
if (mSourceWKT.isEmpty())
{
mSourceWKT = myGeoWKT;
//mSourceWKT = defaultWkt;
// Pass through with no projection since we have no idea what the layer
// coordinates are and projecting them may not be appropriate
mShortCircuit = true;
return;
}
//but default output projection to be the same as input proj
//whatever that may be...
if (mDestWKT.isEmpty())
{
//No destination projection is set so we set the default output projection to
//be the same as input proj. This only happens on the first layer loaded
//whatever that may be...
mDestWKT = mSourceWKT;
}
if (mSourceWKT == mDestWKT)
{
// If the source and destination projection are the same, set the short
// circuit flag (no transform takes place)
mShortCircuit=true;
return;
}
else
{
// Transform must take place
mShortCircuit=false;
}
OGRSpatialReference myInputSpatialRefSys, myOutputSpatialRefSys;
//this is really ugly but we need to get a QString to a char**
char *mySourceCharArrayPointer = (char *)mSourceWKT.ascii();
char *myDestCharArrayPointer = (char *)mDestWKT.ascii();
@ -100,7 +104,7 @@ void QgsCoordinateTransform::initialise()
#define OGRERR_FAILURE 6
#define OGRERR_UNSUPPORTED_SRS 7 */
OGRErr myInputResult = myInputSpatialRefSys.importFromWkt( & mySourceCharArrayPointer );
OGRErr myInputResult = mSourceOgrSpatialRef.importFromWkt( & mySourceCharArrayPointer );
if (myInputResult != OGRERR_NONE)
{
std::cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"<< std::endl;
@ -109,8 +113,10 @@ void QgsCoordinateTransform::initialise()
std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << std::endl;
return;
}
// always morph from esri as it doesn't hurt anything
mSourceOgrSpatialRef.morphFromESRI();
OGRErr myOutputResult = myOutputSpatialRefSys.importFromWkt( & myDestCharArrayPointer );
OGRErr myOutputResult = mDestOgrSpatialRef.importFromWkt( & myDestCharArrayPointer );
if (myOutputResult != OGRERR_NONE)
{
std::cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"<< std::endl;
@ -119,13 +125,27 @@ void QgsCoordinateTransform::initialise()
std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << std::endl;
return;
}
mSourceToDestXForm = OGRCreateCoordinateTransformation( &myInputSpatialRefSys, &myOutputSpatialRefSys );
mDestToSourceXForm = OGRCreateCoordinateTransformation( &myOutputSpatialRefSys, &myInputSpatialRefSys );
if ( ! mSourceToDestXForm || ! mDestToSourceXForm)
// always morph from esri as it doesn't hurt anything
mDestOgrSpatialRef.morphFromESRI();
#ifdef QGISDEBUG
OGRErr sourceValid = mSourceOgrSpatialRef.Validate();
OGRErr destValid = mDestOgrSpatialRef.Validate();
#endif
// One last test to see if they SRS are the same, despite slightly different
// WKT specs
// XXX This doesn't seem to work very well -- which means we are going to be
// XXX attempting to transform coordinates that are in the same SRS.
// XXX What to do? What to do?....
if( mSourceOgrSpatialRef.IsSame(&mDestOgrSpatialRef))
{
mShortCircuit = true;
}
// Validate the spaital reference systems
if ( (mSourceOgrSpatialRef.Validate() != OGRERR_NONE) || (mDestOgrSpatialRef.Validate() != OGRERR_NONE))
{
std::cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"<< std::endl;
std::cout << "The OGR Coordinate transformation for this layer could *** NOT *** be set " << std::endl;
std::cout << "The OGR Coordinate transformation for this layer could *** NOT *** be set "
<< std::endl;
std::cout << "INPUT: " << std::endl << mSourceWKT << std::endl;
std::cout << "OUTPUT: " << std::endl << mDestWKT << std::endl;
std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << std::endl;
@ -134,23 +154,181 @@ void QgsCoordinateTransform::initialise()
else
{
mInitialisedFlag = true;
// Create the coordinate transform objects so we don't have to
// create them each pass through when projecting points
forwardTransform = OGRCreateCoordinateTransformation( &mSourceOgrSpatialRef, &mDestOgrSpatialRef);
inverseTransform = OGRCreateCoordinateTransformation( &mDestOgrSpatialRef, &mSourceOgrSpatialRef );
std::cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"<< std::endl;
std::cout << "The OGR Coordinate transformation for this layer was set to" << std::endl;
std::cout << "INPUT: " << std::endl << mSourceWKT << std::endl;
char *proj4src;
myInputSpatialRefSys.exportToProj4(&proj4src);
std::cout << "PROJ4: " << std::endl << proj4src << std::endl;
// std::cout << "PROJ4: " << std::endl << mProj4SrcParms << std::endl;
std::cout << "OUTPUT: " << std::endl << mDestWKT << std::endl;
char *proj4dest;
myOutputSpatialRefSys.exportToProj4(&proj4dest);
std::cout << "PROJ4: " << std::endl << proj4dest << std::endl;
// std::cout << "PROJ4: " << std::endl << mProj4DestParms << std::endl;
std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << std::endl;
}
//just a test to see if inverse
//inverseTransform(10.0,10.0);
// Deactivate GDAL error messages.
//CPLSetErrorHandler( errorHandler );
// Guess if the source o dest CS is in degrees.
//Searchf for this phrase in each wkt: "unit[\"degree\""
}
//
//
// TRANSFORMERS BELOW THIS POINT .........
//
//
//
QgsPoint QgsCoordinateTransform::transform(const QgsPoint thePoint,TransformDirection direction) const
{
if (mShortCircuit || !mInitialisedFlag) return thePoint;
// transform x
double x = thePoint.x();
double y = thePoint.y();
double z = 0.0;
try
{
transformCoords(1, x, y, z, direction );
}
catch(QgsCsException &cse)
{
//something bad happened....
// rethrow the exception
throw cse;
}
#ifdef QGISDEBUG
//std::cout << "Point projection...X : " << thePoint.x() << "-->" << x << ", Y: " << thePoint.y() << " -->" << y << std::endl;
#endif
return QgsPoint(x, y);
}
QgsPoint QgsCoordinateTransform::transform(const double theX, const double theY=0,TransformDirection direction) const
{
transform(QgsPoint(theX, theY), direction);
}
QgsRect QgsCoordinateTransform::transform(const QgsRect theRect,TransformDirection direction) const
{
if (mShortCircuit || !mInitialisedFlag) return theRect;
// transform x
double x1 = theRect.xMin();
double y1 = theRect.yMin();
double x2 = theRect.xMax();
double y2 = theRect.yMax();
#ifdef QGISDEBUG
std::cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"<< std::endl;
std::cout << "Rect projection..." << std::endl;
std::cout << "INPUT: " << std::endl << mSourceWKT << std::endl;
//std::cout << "PROJ4: " << std::endl << mProj4SrcParms << std::endl;
std::cout << "OUTPUT: " << std::endl << mDestWKT << std::endl;
//std::cout << "PROJ4: " << std::endl << mProj4DestParms << std::endl;
std::cout << "INPUT RECT: " << std::endl << x1 << "," << y1 << ":" << x2 << "," << y2 << std::endl;
std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << std::endl;
#endif
// Number of points to reproject------+
// |
// V
try{
double z = 0.0;
transformCoords(1, x1, y1, z, direction);
transformCoords(1, x2, y2, z, direction);
}
catch(QgsCsException &cse)
{
// rethrow the exception
throw cse;
}
#ifdef QGISDEBUG
std::cout << "Rect projection..."
<< "Xmin : "
<< theRect.xMin()
<< "-->" << x1
<< ", Ymin: "
<< theRect.yMin()
<< " -->" << y1
<< "Xmax : "
<< theRect.xMax()
<< "-->" << x2
<< ", Ymax: "
<< theRect.yMax()
<< " -->" << y2
<< std::endl;
#endif
return QgsRect(x1, y1, x2 , y2);
}
void QgsCoordinateTransform::transformCoords( const int& numPoints, double& x, double& y, double& z,TransformDirection direction) const
{
// use OGR to do the transform
if(direction == INVERSE)
{
// transform from destination (map canvas/project) to layer CS
inverseTransform->Transform(numPoints, &x, &y);
}
else
{
// transform from source layer CS to destination (map canvas/project)
forwardTransform->Transform(numPoints, &x, &y);
}
}
/* XXX THIS IS BASED ON DIRECT USE OF PROJ4
* XXX preserved for future use if we need it
*/
/*
void QgsCoordinateTransform::transformCoords( const int& numPoints, double& x, double& y, double& z,TransformDirection direction) const
{
assert(mProj4DestParms.length() > 0);
assert(mProj4SrcParms.length() > 0);
// use proj4 to do the transform
QString dir;
// if the source/destination projection is lat/long, convert the points to radians
// prior to transforming
if((pj_is_latlong(mDestinationProjection) && (direction == INVERSE))
|| (pj_is_latlong(mSourceProjection) && (direction == FORWARD)))
{
x *= DEG_TO_RAD;
y *= DEG_TO_RAD;
z *= DEG_TO_RAD;
}
int projResult;
if(direction == INVERSE)
{
// std::cout << "!!!! INVERSE TRANSFORM !!!!" << std::endl;
projResult = pj_transform(mDestinationProjection, mSourceProjection , numPoints, 0, &x, &y, &z);
dir = "inverse";
}
else
{
// std::cout << "!!!! FORWARD TRANSFORM !!!!" << std::endl;
projResult = pj_transform(mSourceProjection, mDestinationProjection, numPoints, 0, &x, &y, &z);
dir = "forward";
}
if (projResult != 0)
{
//something bad happened....
QString msg;
QTextOStream pjErr(&msg);
pjErr << tr("Failed") << " " << dir << " " << tr("transform of") << x << ", " << y
<< pj_strerrno(projResult) << "\n";
throw QgsCsException(msg);
}
// if the result is lat/long, convert the results from radians back
// to degrees
if((pj_is_latlong(mDestinationProjection) && (direction == FORWARD))
|| (pj_is_latlong(mSourceProjection) && (direction == INVERSE)))
{
x *= RAD_TO_DEG;
y *= RAD_TO_DEG;
z *= RAD_TO_DEG;
}
}
*/

View File

@ -34,85 +34,110 @@
//non qt includes
#include <iostream>
extern "C"{
#include <proj_api.h>
}
class QString;
/*! \class QgsCoordinateTransform
* \brief Class for doing transforms between two map coordinate systems.
*
* This class can convert map coordinates to a different spatial reference system.
* It is normally associated with a map layer and is used to transform between the
* layer's coordinate system and the coordinate system of the map canvas, although
* it can be used in a more general sense to transform coordinates.
*
* All references to source and destination coordinate systems refer to
* layer and map canvas respectively. All operations are from the perspective
* of the layer. For example, a forward transformation transforms coordinates from the
* layers coordinate system to the map canvas.
*/
class QgsCoordinateTransform: public QObject
{
Q_OBJECT
public:
/*!
* Constructs a QgsCoordinateTransform using the Well Known Text representation
* of the layer and map canvas coordinate systems
* @param theSourceWKT WKT of the layer's coordinate system
* @param theSourceWKT WKT of the map canvas coordinate system
*/
QgsCoordinateTransform(QString theSourceWKT, QString theDestWKT );
//! destructor
~QgsCoordinateTransform();
//! Enum used to indicate the direction (forward or inverse) of the transform
enum TransformDirection{
FORWARD,
INVERSE
};
/*!
* Set the source (layer) WKT
* @param theWKT WKT representation of the layer's coordinate system
*/
void setSourceWKT(QString theWKT);
/*!
* Get the WKT representation of the layer's coordinate system
* @return WKT of the layer's coordinate system
*/
QString sourceWKT() const {return mSourceWKT;};
/*!
* Get the WKT representation of the map canvas coordinate system
* @return WKT of the map canvas coordinate system
*/
QString destWKT() const {return mDestWKT;};
/*!
* Flag to indicate whether the coordinate systems have been initialised
* @return true if initialised, otherwise false
*/
bool isInitialised() {return mInitialisedFlag;};
/*! Transform the point from Source Coordinate System to Destination Coordinate System
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
* otherwise points are transformed from map canvas CS to layerCS.
* @param p Point to transform
* @param direction TransformDirection (defaults to FORWARD)
* @return QgsPoint in Destination Coordinate System
*/
QgsPoint transform(QgsPoint p);
QgsPoint transform(const QgsPoint p,TransformDirection direction=FORWARD) const;
/*! Transform the point specified by x,y from Source Coordinate System to Destination Coordinate System
* @param x x cordinate o point to transform
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
* otherwise points are transformed from map canvas CS to layerCS.
* @param x x cordinate of point to transform
* @param y y coordinate of point to transform
* @param direction TransformDirection (defaults to FORWARD)
* @return QgsPoint in Destination Coordinate System
*/
QgsPoint transform(double x, double y);
QgsPoint transform(double x, double y,TransformDirection direction=FORWARD) const ;
/*! Transform a QgsRect to the dest Coordinate system
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
* otherwise points are transformed from map canvas CS to layerCS.
* @param QgsRect rect to transform
* @param direction TransformDirection (defaults to FORWARD)
* @return QgsRect in Destination Coordinate System
*/
QgsRect transform(QgsRect theRect);
QgsRect transform(const QgsRect theRect,TransformDirection direction=FORWARD) const;
/*! Transform a QgsRect pointer to the dest Coordinate system
* @param QgsRect * rect to transform
/*! Transform an array of coordinates to a different Coordinate System
* If the direction is FORWARD then coordinates are transformed from layer CS --> map canvas CS,
* otherwise points are transformed from map canvas CS to layerCS.
* @param x x cordinate of point to transform
* @param y y coordinate of point to transform
* @param direction TransformDirection (defaults to FORWARD)
* @return QgsRect in Destination Coordinate System
*/
QgsRect transform(QgsRect * theRect);
void transformCoords( const int &numPoint, double &x, double &y, double &z,TransformDirection direction=FORWARD) const;
/*! Inverse Transform the point from Dest Coordinate System to Source Coordinate System
* @param p Point to transform (in destination coord system)
* @return QgsPoint in Source Coordinate System
*/
QgsPoint inverseTransform(QgsPoint p);
/*! Inverse Transform the point specified by x,y from Dest Coordinate System to Source Coordinate System
* @param x x cordinate of point to transform (in dest coord sys)
* @param y y coordinate of point to transform (in dest coord sys)
* @return QgsPoint in Source Coordinate System
*/
QgsPoint inverseTransform(double x, double y);
/*! Inverse Transform a QgsRect to the source Coordinate system
* @param QgsRect rect to transform (in dest coord sys)
* @return QgsRect in Source Coordinate System
*/
QgsRect inverseTransform(QgsRect theRect);
/*! Inverse Transform a QgsRect pointer to the source Coordinate system
* @param QgsRect * rect to transform (in dest coord sys)
* @return QgsRect in Source Coordinate System
*/
QgsRect inverseTransform(QgsRect * theRect);
QString showParameters();
//! Accessor and mutator for source WKT
void setSourceWKT(QString theWKT);
QString sourceWKT() const {return mSourceWKT;};
//! Accessor for dest WKT
QString destWKT() const {return mDestWKT;};
//! Accessor for whether this transoform is properly initialised
bool isInitialised() {return mInitialisedFlag;};
public slots:
/** mutator for dest WKT - slot will usually be fired if proj props change and
user selects a different coordinate system */
/*!
* Mutator for dest WKT - This slot will usually be called if the
* project properties change and a different coordinate system is
* selected.
* @param WKT of the destination coordinate system
*/
void setDestWKT(QString theWKT);
private:
@ -120,304 +145,42 @@ class QgsCoordinateTransform: public QObject
void initialise();
//! flag to show whether the transform is properly initialised or not
bool mInitialisedFlag;
/** Used for forward transform */
OGRCoordinateTransformation * mSourceToDestXForm;
/** Used for reverse transform */
OGRCoordinateTransformation * mDestToSourceXForm;
/** Transform definitionsin WKT format */
QString mSourceWKT,mDestWKT;
/** Dunno if we need this - XXXXX Delete if unused */
/*!
* WKT of the source (layer) coordinate system
*/
QString mSourceWKT;
/*!
* WKT of the destination (map canvas) coordinate system
*/
QString mDestWKT;
/** Dunno if we need this - XXX Delete if unused */
bool mInputIsDegrees;
//set to true if src cs == dest cs
/*!
* Flag to indicate that the source and destination coordinate systems are
* equal and not transformation needs to be done
*/
bool mShortCircuit;
OGRSpatialReference mSourceOgrSpatialRef;
OGRSpatialReference mDestOgrSpatialRef;
OGRCoordinateTransformation *forwardTransform;
OGRCoordinateTransformation *inverseTransform;
/*!
* Proj4 parameters for the source (layer) coordinate system
*/
QString mProj4SrcParms;
/*!
* Proj4 parameters for the destination (map canvas) coordinate system
*/
QString mProj4DestParms;
/*!
* Proj4 data structure of the source projection (layer coordinate system)
*/
projPJ mSourceProjection;
/*!
* Proj4 data structure of the destination projection (map canvas coordinate system)
*/
projPJ mDestinationProjection;
};
//--------------------------------------------------------
// Inlined method implementations for best performance
//--------------------------------------------------------
// ------------------------------------------------------------------
//
//
// --------------- FORWARD PROJECTIONS ------------------------------
//
//
// ------------------------------------------------------------------
inline QgsPoint QgsCoordinateTransform::transform(QgsPoint thePoint)
{
if (mShortCircuit || !mInitialisedFlag) return thePoint;
// transform x
double x = thePoint.x();
double y = thePoint.y();
// Number of points to reproject------+
// |
// V
if ( ! mSourceToDestXForm->Transform( 1, &x, &y ) )
{
//something bad happened....
throw QgsCsException(QString("Coordinate transform failed"));
}
else
{
#ifdef QGISDEBUG
//std::cout << "Point projection...X : " << thePoint.x() << "-->" << x << ", Y: " << thePoint.y() << " -->" << y << std::endl;
#endif
return QgsPoint(x, y);
}
}
inline QgsRect QgsCoordinateTransform::transform(QgsRect theRect)
{
if (mShortCircuit || !mInitialisedFlag) return theRect;
// transform x
double x1 = theRect.xMin();
double y1 = theRect.yMin();
double x2 = theRect.xMax();
double y2 = theRect.yMax();
// Number of points to reproject------+
// |
// V
if ( ! mSourceToDestXForm->Transform( 1, &x1, &y1 ) || ! mSourceToDestXForm->Transform( 1, &x2, &y2 ) )
{
//something bad happened....
throw QgsCsException(QString("Coordinate transform failed"));
}
else
{
#ifdef QGISDEBUG
std::cout << "Rect projection..."
<< "Xmin : "
<< theRect.xMin()
<< "-->" << x1
<< ", Ymin: "
<< theRect.yMin()
<< " -->" << y1
<< "Xmax : "
<< theRect.xMax()
<< "-->" << x2
<< ", Ymax: "
<< theRect.yMax()
<< " -->" << y2
<< std::endl;
#endif
return QgsRect(x1, y1, x2 , y2);
}
}
inline QgsRect QgsCoordinateTransform::transform(QgsRect * theRect)
{
if (mShortCircuit || !mInitialisedFlag) return QgsRect(theRect->xMin(),theRect->yMin(),theRect->xMax(),theRect->yMax());
// transform x
double x1 = theRect->xMin();
double y1 = theRect->yMin();
double x2 = theRect->xMax();
double y2 = theRect->yMax();
// Number of points to reproject------+
// |
// V
if ( ! mSourceToDestXForm->Transform( 1, &x1, &y1 ) || ! mSourceToDestXForm->Transform( 1, &x2, &y2 ) )
{
//something bad happened....
throw QgsCsException(QString("Coordinate transform failed"));
}
else
{
#ifdef QGISDEBUG
std::cout << "Rect projection..."
<< "Xmin : "
<< theRect->xMin()
<< "-->" << x1
<< ", Ymin: "
<< theRect->yMin()
<< " -->" << y1
<< "Xmax : "
<< theRect->xMax()
<< "-->" << x2
<< ", Ymax: "
<< theRect->yMax()
<< " -->" << y2
<< std::endl;
#endif
return QgsRect(x1, y1, x2 , y2);
}
}
inline QgsPoint QgsCoordinateTransform::transform(double theX, double theY)
{
if (mShortCircuit || !mInitialisedFlag) return QgsPoint(theX,theY);
// transform x
double x = theX;
double y = theY;
if ( ! mSourceToDestXForm->Transform( 1, &x, &y ) )
{
//something bad happened....
throw QgsCsException(QString("Coordinate transform failed"));
}
else
{
#ifdef QGISDEBUG
//std::cout << "Point projection...X : " << theX << "-->" << x << ", Y: " << theY << " -->" << y << std::endl;
#endif
return QgsPoint(x, y);
}
}
// ------------------------------------------------------------------
//
//
// --------------- INVERSE PROJECTIONS ------------------------------
//
//
// ------------------------------------------------------------------
inline QgsPoint QgsCoordinateTransform::inverseTransform(QgsPoint thePoint)
{
if (mShortCircuit || !mInitialisedFlag) return thePoint;
// transform x
double x = thePoint.x();
double y = thePoint.y();
// Number of points to reproject------+
// |
// V
if ( ! mDestToSourceXForm->Transform( 1, &x, &y ) )
{
//something bad happened....
throw QgsCsException(QString("Coordinate inverse transform failed"));
}
else
{
#ifdef QGISDEBUG
//std::cout << "Point inverse projection...X : " << thePoint.x() << "-->" << x << ", Y: " << thePoint.y() << " -->" << y << std::endl;
#endif
return QgsPoint(x, y);
}
}
inline QgsRect QgsCoordinateTransform::inverseTransform(QgsRect theRect)
{
if (mShortCircuit || !mInitialisedFlag) return theRect;
// transform x
double x1 = theRect.xMin();
double y1 = theRect.yMin();
double x2 = theRect.xMax();
double y2 = theRect.yMax();
#ifdef QGISDEBUG
std::cout << "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"<< std::endl;
std::cout << "Rect inverse projection..." << std::endl;
std::cout << "INPUT: " << std::endl << mSourceWKT << std::endl;
// show proj parms too
OGRSpatialReference sr(mSourceWKT);
char *proj4src;
sr.exportToProj4(&proj4src);
std::cout << "PROJ4: " << std::endl << proj4src << std::endl;
std::cout << "OUTPUT: " << std::endl << mDestWKT << std::endl;
char *proj4out;
char *pWkt = (char *)mDestWKT.ascii();
sr.importFromWkt(&pWkt);
sr.exportToProj4(&proj4src);
std::cout << "PROJ4: " << std::endl << proj4src << std::endl;
std::cout << "INPUT RECT: " << std::endl << x1 << "," << y1 << ":" << x2 << "," << y2 << std::endl;
std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << std::endl;
#endif
//CPLPushErrorHandler( CPLQuietErrorHandler );
// Number of points to reproject---------------+
// |
// V
int myResult1 = mDestToSourceXForm->Transform( 1, &x1, &y1 );
//int myResult2 = mDestToSourceXForm->Transform( 1, &x2, &y2 );
//CPLPopErrorHandler();
if ( ! myResult1) // || ! myResult2 )
{
//something bad happened....
throw QgsCsException(QString("Coordinate inverse transform failed"));
}
else
{
#ifdef QGISDEBUG
std::cout << "Xmin : "
<< theRect.xMin()
<< "-->" << x1
<< ", Ymin: "
<< theRect.yMin()
<< " -->" << y1
<< "Xmax : "
<< theRect.xMax()
<< "-->" << x2
<< ", Ymax: "
<< theRect.yMax()
<< " -->" << y2
<< std::endl;
#endif
return QgsRect(x1, y1, x2 , y2);
}
}
inline QgsRect QgsCoordinateTransform::inverseTransform(QgsRect * theRect)
{
if (mShortCircuit || !mInitialisedFlag) return QgsRect(theRect->xMin(),theRect->yMin(),theRect->xMax(),theRect->yMax());
// transform x
double x1 = theRect->xMin();
double y1 = theRect->yMin();
double x2 = theRect->xMax();
double y2 = theRect->yMax();
// Number of points to reproject------+
// |
// V
if ( ! mDestToSourceXForm->Transform( 1, &x1, &y1 ) || ! mDestToSourceXForm->Transform( 1, &x2, &y2 ) )
{
//something bad happened....
throw QgsCsException(QString("Inverse Coordinate transform failed"));
}
else
{
#ifdef QGISDEBUG
std::cout << "Rect pointer inverse projection..."
<< "Xmin : "
<< theRect->xMin()
<< "-->" << x1
<< ", Ymin: "
<< theRect->yMin()
<< " -->" << y1
<< "Xmax : "
<< theRect->xMax()
<< "-->" << x2
<< ", Ymax: "
<< theRect->yMax()
<< " -->" << y2
<< std::endl;
#endif
return QgsRect(x1, y1, x2 , y2);
}
}
inline QgsPoint QgsCoordinateTransform::inverseTransform(double theX, double theY)
{
if (mShortCircuit || !mInitialisedFlag) return QgsPoint(theX,theY);
// transform x
double x = theX;
double y = theY;
if ( ! mDestToSourceXForm->Transform( 1, &x, &y ) )
{
//something bad happened....
throw QgsCsException(QString("Coordinate inverseTransform failed"));
}
else
{
#ifdef QGISDEBUG
//std::cout << "Point inverse projection...X : " << theX << "-->" << x << ", Y: " << theY << " -->" << y << std::endl;
#endif
return QgsPoint(x, y);
}
}
#endif // QGSCOORDINATETRANSFORM_H

View File

@ -75,80 +75,7 @@ bufferRenderer(layer->
renderer())
{
// populate the general information
QString source = layer->source();
source = source.left(source.find("password"));
lblSource->setText(source);
txtDisplayName->setText(layer->name());
// set whats this stuff
QWhatsThis::add(lblSource, tr("The source of the data (path name or database connection information)"));
QWhatsThis::add(pbnQueryBuilder, tr("This button opens the PostgreSQL query builder and allows you to create a subset of features to display on the map canvas rather than displaying all features in the layer"));
QWhatsThis::add(txtSubsetSQL, tr("The query used to limit the features in the layer is shown here. This is currently only supported for PostgreSQL layers. To enter or modify the query, click on the Query Builder button"));
//we are dealing with a pg layer here so that we can enable the sql box
QgsVectorDataProvider *dp = dynamic_cast<QgsVectorDataProvider *>(layer->getDataProvider());
//see if we are dealing with a pg layer here
if(layer->providerType() == "postgres")
{
grpSubset->setEnabled(true);
txtSubsetSQL->setText(layer->subsetString());
// if the user is allowed to type an adhoc query, the app will crash if the query
// is bad. For this reason, the sql box is disabled and the query must be built
// using the query builder, either by typing it in by hand or using the buttons, etc
// on the builder. If the ability to enter a query directly into the box is required,
// a mechanism to check it must be implemented.
txtSubsetSQL->setEnabled(false);
pbnQueryBuilder->setEnabled(true);
}
else
{
grpSubset->setEnabled(false);
}
//get field list for display field combo
std::vector<QgsField> myFields = dp->fields();
for (int i = 0; i < myFields.size(); i++)
{
QgsField myField = myFields[i];
displayFieldComboBox->insertItem( myField.name() );
}
// set up the scale based layer visibility stuff....
chkUseScaleDependentRendering->setChecked(lyr->scaleBasedVisibility());
spinMinimumScale->setValue(lyr->minScale());
spinMaximumScale->setValue(lyr->maxScale());
// symbology initialization
legendtypecombobox->insertItem(tr("Single Symbol"));
legendtypecombobox->insertItem(tr("Graduated Symbol"));
legendtypecombobox->insertItem(tr("Continuous Color"));
legendtypecombobox->insertItem(tr("Unique Value"));
if( layer->vectorType()==QGis::Point )
{
legendtypecombobox->insertItem(tr("Single Marker"));
legendtypecombobox->insertItem(tr("Graduated Marker"));
legendtypecombobox->insertItem(tr("Unique Value Marker"));
}
QVBoxLayout *layout = new QVBoxLayout( labelOptionsFrame );
labelDialog = new QgsLabelDialog ( layer->label(),labelOptionsFrame);
layout->addWidget( labelDialog );
QGridLayout *actionLayout = new QGridLayout( actionOptionsFrame );
std::vector<QgsField> fields = dp->fields();
actionDialog = new QgsAttributeActionDialog ( layer->actions(), fields,
actionOptionsFrame );
actionLayout->addWidget( actionDialog,0,0 );
QObject::connect(legendtypecombobox, SIGNAL(activated(const QString &)), this, SLOT(alterLayerDialog(const QString &)));
//insert the renderer dialog of the vector layer into the widget stack
widgetStackRenderers->addWidget(bufferDialog);
widgetStackRenderers->raiseWidget(bufferDialog);
//set the metadata contents
teMetadata->setText(getMetadata());
reset();
}
QgsDlgVectorLayerProperties::~QgsDlgVectorLayerProperties()
@ -260,8 +187,82 @@ void QgsDlgVectorLayerProperties::setDisplayField(QString name)
displayFieldComboBox->setCurrentText(name);
}
//! @note in raster props, this metho d is called sync()
void QgsDlgVectorLayerProperties::reset( void )
{
// populate the general information
QString source = layer->source();
source = source.left(source.find("password"));
lblSource->setText(source);
txtDisplayName->setText(layer->name());
// set whats this stuff
QWhatsThis::add(lblSource, tr("The source of the data (path name or database connection information)"));
QWhatsThis::add(pbnQueryBuilder, tr("This button opens the PostgreSQL query builder and allows you to create a subset of features to display on the map canvas rather than displaying all features in the layer"));
QWhatsThis::add(txtSubsetSQL, tr("The query used to limit the features in the layer is shown here. This is currently only supported for PostgreSQL layers. To enter or modify the query, click on the Query Builder button"));
//we are dealing with a pg layer here so that we can enable the sql box
QgsVectorDataProvider *dp = dynamic_cast<QgsVectorDataProvider *>(layer->getDataProvider());
//see if we are dealing with a pg layer here
if(layer->providerType() == "postgres")
{
grpSubset->setEnabled(true);
txtSubsetSQL->setText(layer->subsetString());
// if the user is allowed to type an adhoc query, the app will crash if the query
// is bad. For this reason, the sql box is disabled and the query must be built
// using the query builder, either by typing it in by hand or using the buttons, etc
// on the builder. If the ability to enter a query directly into the box is required,
// a mechanism to check it must be implemented.
txtSubsetSQL->setEnabled(false);
pbnQueryBuilder->setEnabled(true);
}
else
{
grpSubset->setEnabled(false);
}
//get field list for display field combo
std::vector<QgsField> myFields = dp->fields();
for (int i = 0; i < myFields.size(); i++)
{
QgsField myField = myFields[i];
displayFieldComboBox->insertItem( myField.name() );
}
// set up the scale based layer visibility stuff....
chkUseScaleDependentRendering->setChecked(layer->scaleBasedVisibility());
spinMinimumScale->setValue(layer->minScale());
spinMaximumScale->setValue(layer->maxScale());
// symbology initialization
legendtypecombobox->insertItem(tr("Single Symbol"));
legendtypecombobox->insertItem(tr("Graduated Symbol"));
legendtypecombobox->insertItem(tr("Continuous Color"));
legendtypecombobox->insertItem(tr("Unique Value"));
if( layer->vectorType()==QGis::Point )
{
legendtypecombobox->insertItem(tr("Single Marker"));
legendtypecombobox->insertItem(tr("Graduated Marker"));
legendtypecombobox->insertItem(tr("Unique Value Marker"));
}
QVBoxLayout *layout = new QVBoxLayout( labelOptionsFrame );
labelDialog = new QgsLabelDialog ( layer->label(),labelOptionsFrame);
layout->addWidget( labelDialog );
QGridLayout *actionLayout = new QGridLayout( actionOptionsFrame );
std::vector<QgsField> fields = dp->fields();
actionDialog = new QgsAttributeActionDialog ( layer->actions(), fields,
actionOptionsFrame );
actionLayout->addWidget( actionDialog,0,0 );
QObject::connect(legendtypecombobox, SIGNAL(activated(const QString &)), this, SLOT(alterLayerDialog(const QString &)));
//insert the renderer dialog of the vector layer into the widget stack
widgetStackRenderers->addWidget(bufferDialog);
widgetStackRenderers->raiseWidget(bufferDialog);
//set the metadata contents
teMetadata->setText(getMetadata());
actionDialog->init();
labelDialog->init();
labelCheckBox->setChecked(layer->labelOn());

View File

@ -0,0 +1,49 @@
/***************************************************************************
qgslayerprojectionselector.cpp
Set user layerprojectionselector and preferences
-------------------
begin : May 28, 2004
copyright : (C) 2004 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#include "qgslayerprojectionselector.h"
#include "qgsprojectionselector.h"
#include <qapplication.h>
/**
* \class QgsLayerProjectionSelector - Set user layerprojectionselector and preferences
* Constructor
*/
QgsLayerProjectionSelector::QgsLayerProjectionSelector()
{
qApp->restoreOverrideCursor();
}
//! Destructor
QgsLayerProjectionSelector::~QgsLayerProjectionSelector()
{}
void QgsLayerProjectionSelector::pbnOK_clicked()
{
accept();
}
void QgsLayerProjectionSelector::setSelectedWKT(QString theWKTName)
{
projectionSelector->setSelectedWKT(theWKTName);
}
QString QgsLayerProjectionSelector::getCurrentWKT()
{
//@NOTE dont use getSelectedWKT as that just returns the name part!
return projectionSelector->getCurrentWKT();
}

View File

@ -0,0 +1,47 @@
/***************************************************************************
qgslayerprojectionselector.h
Set user layerprojectionselector and preferences
-------------------
begin : May 28, 2004
copyright : (C) 2004 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#ifndef QGSLAYERPROJECTIONSELECTOR_H
#define QGSLAYERPROJECTIONSELECTOR_H
class QString;
#ifdef WIN32
#include "qgslayerprojectionselectorbase.h"
#else
#include "qgslayerprojectionselectorbase.uic.h"
#endif
/**
* \class QgsLayerProjectionSelector
* \brief Set Projection system for a layer
*/
class QgsLayerProjectionSelector :public QgsLayerProjectionSelectorBase{
Q_OBJECT;
public:
/**
* Constructor
*/
QgsLayerProjectionSelector();
//! Destructor
~QgsLayerProjectionSelector();
public slots:
void pbnOK_clicked();
QString getCurrentWKT();
void setSelectedWKT(QString theWKTName);
};
#endif // #ifndef QGSLAYERPROJECTIONSELECTOR_H

View File

@ -0,0 +1,95 @@
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>QgsLayerProjectionSelectorBase</class>
<widget class="QDialog">
<property name="name">
<cstring>QgsLayerProjectionSelectorBase</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>605</width>
<height>563</height>
</rect>
</property>
<property name="caption">
<string>Layer Projection Selector</string>
</property>
<property name="icon">
<pixmap>image0</pixmap>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QPushButton" row="2" column="1">
<property name="name">
<cstring>pbnOK</cstring>
</property>
<property name="text">
<string>OK</string>
</property>
</widget>
<spacer row="2" column="0">
<property name="name">
<cstring>spacer1</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>221</width>
<height>21</height>
</size>
</property>
</spacer>
<widget class="QgsProjectionSelector" row="1" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>projectionSelector</cstring>
</property>
</widget>
<widget class="QTextEdit" row="0" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>textEdit1</cstring>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name="qrichtext" content="1" /&gt;&lt;/head&gt;&lt;body style="font-size:12pt;font-family:Bitstream Vera Sans"&gt;
&lt;p style="margin-top:16px"&gt;&lt;span style="font-size:18pt;font-weight:600"&gt;Define this layer's projection:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This layer appears to have no projection specification. By default, this layer will now have its projection set to that of the project, but you may override this by selecting a different projection below.&lt;/p&gt;
&lt;/body&gt;&lt;/html&gt;
</string>
</property>
<property name="wordWrap">
<enum>WidgetWidth</enum>
</property>
</widget>
</grid>
</widget>
<images>
<image name="image0">
<data format="PNG" length="727">89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000029e49444154388d95925b48530118c7ff3b3bd3b9a6392f9b97b42413a7b912b1de7ab10cc44c3408c5348d0a0c347b29848c2233d0613d1651122a09f950a1f83012ba4b379b28a37969a6a6e7ecd2e6e639673b971e62656e41fddfbeefe3fffbe0ff7dc07f28e63cb2355d7848666277b047fc8b31ba05a99a4edc966b3121aca0849f86189c91e10c2b2b3d09b1b152cd946572879c64f977b639aaa97fb888d049a440830260ffeb3686e92be105a3e3f148b95713a7aca93ba93ffad25a21a61849497d1cdf22f6e205007558f3eaea1d4340b8c6cc398e4975a7b24700a8c80c90fa4ef5bcae8d949a2f1aa623b5f20200f2b0192895dfdb299f55e95b0b60d6ea790380511d41f3b2e84d3b149189fafaeced8d0d79fb81df19fc020c0d9d51f132ba98e1fcf07302a815c6a66e849e88c7d52c2a61ed74e54ea8a31548cf509701880c01e4e64a495cc01311acfd82109027a147a4c11ed6e9879393370100542a790a005508c06c76ba7970120010840c5b8a34e70e64e71516713983b5d5056332990c0060a73916801402282b7be0b2bb58330044a9481c346ccd8f18152d4d5539a5b189e4155e14c171023ebca52700f8c28528be7e4e75b10c0f829061d2b2e4ecbf35599b911ed7ed62a8287f40c0ab67cb6ba6e1857b00fc2100721b88b366d352e7a38f0e3bcda0aa2c8b34ec4a746be33591003035e10cdcb86e36badddc684747d59f678caa8442598c768146efe0a7cf71272e3ffd3231ee98696ddb333063631b045184d7cbfb9c76a18f65efb6aeb1f60684910280565581fb91fbd08d9fdf96f6c4547ac14a554b56aa5a72f95afcbd03e5768582280c9ae4eb0022009f221f0b220d088b1803e059fcca8c7bdcfe54dbec6acce0a065fea6f1fd258fdb6fc2ba67da2842aec3e60d3d128006400c00d9fac10f3d4b18bb5f2121880000000049454e44ae426082</data>
</image>
</images>
<connections>
<connection>
<sender>pbnOK</sender>
<signal>clicked()</signal>
<receiver>QgsLayerProjectionSelectorBase</receiver>
<slot>pbnOK_clicked()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">qgslayerprojectionselectorbase.ui.h</include>
</includes>
<slots>
<slot>pbnOK_clicked()</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
<includehints>
<includehint>qgsprojectionselector.h</includehint>
</includehints>
</UI>

View File

@ -0,0 +1,17 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#include "../widgets/projectionselector/qgsprojectionselector.h"
void QgsLayerProjectionSelectorBase::pbnOK_clicked()
{
}

View File

@ -497,16 +497,36 @@ void QgsMapCanvas::addLayer(QgsMapLayer * lyr)
// update extent if warranted
if (mCanvasProperties->layers.size() == 1)
{
// if only 1 layer, set the full extent to its extent
// the layer extent must be projected to the same coordinate
// system as the map canvas prior to updating the canvas extents
if(projectionsEnabled())
{
QgsRect tRect = lyr->coordinateTransform()->transform(lyr->extent());
mCanvasProperties->fullExtent = tRect;
}
else
{
mCanvasProperties->fullExtent = lyr->extent();
mCanvasProperties->fullExtent.scale(1.1);
}
// XXX why magic number of 1.1? - TO GET SOME WHITESPACE AT THE EDGES OF THE MAP
mCanvasProperties->currentExtent = mCanvasProperties->fullExtent;
}
else
{
if(projectionsEnabled())
{
// project the layer extent and pass it off to update the full extent
updateFullExtent(lyr->coordinateTransform()->transform(lyr->extent()));
}
else
{
updateFullExtent(lyr->extent());
}
}
mCanvasProperties->zOrder.push_back(lyr->getLayerID());
@ -825,12 +845,16 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
//we need to find out the extent of the canvas in the layer's
//native coordinate system :. inverseProjection of the extent
//must be done....
// XXX this works as long as the canvas extents are in the canvas
// XXX coordinate system -- which is not working at present
//
QgsRect myProjectedRect;
try
{
std::cout << "Getting extent of canvas in layers CS. Canvas is " << mCanvasProperties->currentExtent.stringRep() << std::endl;
myProjectedRect =
ml->coordinateTransform()->inverseTransform(
mCanvasProperties->currentExtent);
ml->coordinateTransform()->transform(
mCanvasProperties->currentExtent, QgsCoordinateTransform::INVERSE);
}
catch (QgsCsException &e)
@ -1511,7 +1535,7 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
QgsPoint lastpoint = mCanvasProperties->coordXForm->transform(it->x(),it->y());
QgsPoint endpoint = mCanvasProperties->coordXForm->transform(digitisedpoint.x(),digitisedpoint.y());
paint.drawLine(static_cast<int>(lastpoint.x()),static_cast<int>(lastpoint.y()),
endpoint.x(),endpoint.y());
static_cast<int>(endpoint.x()),static_cast<int>(endpoint.y()));
//draw it to an acetate layer
QgsLine digitline(*it,digitisedpoint);
QgsAcetateLines* acetate=new QgsAcetateLines();
@ -2123,7 +2147,7 @@ void QgsMapCanvas::recalculateExtents()
std::cout << "Input extent: " << lyr->extent().stringRep() << std::endl;
try
{
std::cout << "Transformed extent" << lyr->coordinateTransform()->transform(lyr->extent()) << std::endl;
std::cout << "Transformed extent" << lyr->coordinateTransform()->transform(lyr->extent(), QgsCoordinateTransform::FORWARD) << std::endl;
}
catch (QgsCsException &e)
{

View File

@ -20,9 +20,14 @@
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qspinbox.h>
#include <qfiledialog.h>
#include <qradiobutton.h>
#include <qapplication.h>
#include <qtextbrowser.h>
#include "qgsoptions.h"
#include "qgisapp.h"
#include "qgssvgcache.h"
#include "qgslayerprojectionselector.h"
/**
* \class QgsOptions - Set user options and preferences
* Constructor
@ -50,7 +55,21 @@ QgsOptions::QgsOptions(QWidget *parent, const char *name) : QgsOptionsBase(paren
spbSVGOversampling->setValue(QgsSVGCache::instance().getOversampling());
// set the display update threshold
spinBoxUpdateThreshold->setValue(settings.readNumEntry("/qgis/map/updateThreshold"));
//set the default projection behaviour radio buttongs
if (settings.readEntry("/qgis/projections/defaultBehaviour")=="prompt")
{
radPromptForProjection->setChecked(true);
}
else if (settings.readEntry("/qgis/projections/defaultBehaviour")=="useProject")
{
radUseProjectProjection->setChecked(true);
}
else //useGlobal
{
radUseGlobalProjection->setChecked(true);
}
mGlobalWKT = settings.readEntry("/qgis/projections/defaultProjectionWKT");
txtGlobalWKT->setText(mGlobalWKT);
}
//! Destructor
QgsOptions::~QgsOptions(){}
@ -66,6 +85,110 @@ QString QgsOptions::theme()
// returns the current theme (as selected in the cmbTheme combo box)
return cmbTheme->currentText();
}
void QgsOptions::saveOptions()
{
QSettings settings;
settings.writeEntry("/qgis/browser", cmbBrowser->currentText());
settings.writeEntry("/qgis/map/identifyRadius", spinBoxIdentifyValue->value());
settings.writeEntry("/qgis/hideSplash",cbxHideSplash->isChecked());
settings.writeEntry("/qgis/new_layers_visible",!chkAddedVisibility->isChecked());
if(cmbTheme->currentText().length() == 0)
{
settings.writeEntry("/qgis/theme", "default");
}else{
settings.writeEntry("/qgis/theme",cmbTheme->currentText());
}
settings.writeEntry("/qgis/map/updateThreshold", spinBoxUpdateThreshold->value());
QgsSVGCache::instance().setOversampling(spbSVGOversampling->value());
settings.writeEntry("/qgis/svgoversampling", spbSVGOversampling->value());
//check behaviour so default projection when new layer is added with no
//projection defined...
if (radPromptForProjection->isChecked())
{
//
settings.writeEntry("/qgis/projections/defaultBehaviour", "prompt");
}
else if(radUseProjectProjection->isChecked())
{
//
settings.writeEntry("/qgis/projections/defaultBehaviour", "useProject");
}
else //assumes radUseGlobalProjection is checked
{
//
settings.writeEntry("/qgis/projections/defaultBehaviour", "useGlobal");
}
settings.writeEntry("/qgis/projections/defaultProjectionWKT",mGlobalWKT);
//all done
accept();
}
void QgsOptions::cbxHideSplash_toggled( bool )
{
}
void QgsOptions::addTheme(QString item)
{
cmbTheme->insertItem(item);
}
void QgsOptions::setCurrentTheme()
{
QSettings settings;
cmbTheme->setCurrentText(settings.readEntry("/qgis/theme","default"));
}
void QgsOptions::findBrowser()
{
QString filter;
#ifdef WIN32
filter = "Applications (*.exe)";
#else
filter = "All Files (*)";
#endif
QString browser = QFileDialog::getOpenFileName(
"./",
filter,
this,
"open file dialog",
"Choose a browser" );
if(browser.length() > 0)
{
cmbBrowser->setCurrentText(browser);
}
}
void QgsOptions::pbnSelectProjection_clicked()
{
QSettings settings;
QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector();
mySelector->setSelectedWKT(mGlobalWKT);
if(mySelector->exec())
{
#ifdef QGISDEBUG
std::cout << "------ Global Default Projection Selection Set ----------" << std::endl;
#endif
mGlobalWKT = mySelector->getCurrentWKT();
txtGlobalWKT->setText(mGlobalWKT);
#ifdef QGISDEBUG
std::cout << "------ Global Default Projection now set to ----------\n" << mGlobalWKT << std::endl;
#endif
}
else
{
#ifdef QGISDEBUG
std::cout << "------ Global Default Projection Selection change cancelled ----------" << std::endl;
#endif
QApplication::restoreOverrideCursor();
}
}
// Return state of the visibility flag for newly added layers. If
bool QgsOptions::newVisible()

View File

@ -44,20 +44,30 @@ class QgsOptions :public QgsOptionsBase{
* @return theme name (a directory name in the themes directory)
*/
QString theme();
public slots:
//! Slot to change the theme this is handled when the user
// activates or highlights a theme name in the drop-down list
void themeChanged(const QString &);
//! Slot called when user chooses to change the project wide projection.
void pbnSelectProjection_clicked();
void findBrowser();
void setCurrentTheme();
void addTheme(QString item);
void cbxHideSplash_toggled( bool );
void saveOptions();
/**
* Return the desired state of newly added layers. If a layer
* is to be drawn when added to the map, this function returns
* true.
*/
bool newVisible();
public slots:
//! Slot to change the theme this is handled when the user
// activates or highlights a theme name in the drop-down list
void themeChanged(const QString &);
private:
//! Pointer to our parent
QWidget *qparent;
//!Global default projection used for new layers added that have no projection
QString mGlobalWKT;
};
#endif // #ifndef QGSOPTIONS_H

File diff suppressed because one or more lines are too long

View File

@ -15,38 +15,9 @@
void QgsOptionsBase::init()
{
// read the current browser and set it
QSettings settings;
QString browser = settings.readEntry("/qgis/browser");
cmbBrowser->setCurrentText(browser);
int identifyValue = settings.readNumEntry("/qgis/map/identifyRadius");
spinBoxIdentifyValue->setValue(identifyValue);
bool hideSplashFlag = false;
if (settings.readEntry("/qgis/hideSplash")=="true")
{
hideSplashFlag =true;
}
cbxHideSplash->setChecked(hideSplashFlag);
// set the visibility flag for newly added layers
chkAddedVisibility->setChecked(!settings.readBoolEntry("/qgis/new_layers_visible", true));
}
void QgsOptionsBase::saveOptions()
{
QSettings settings;
settings.writeEntry("/qgis/browser", cmbBrowser->currentText());
settings.writeEntry("/qgis/map/identifyRadius", spinBoxIdentifyValue->value());
settings.writeEntry("/qgis/hideSplash",cbxHideSplash->isChecked());
settings.writeEntry("/qgis/new_layers_visible",!chkAddedVisibility->isChecked());
if(cmbTheme->currentText().length() == 0)
{
settings.writeEntry("/qgis/theme", "default");
}else{
settings.writeEntry("/qgis/theme",cmbTheme->currentText());
}
settings.writeEntry("/qgis/map/updateThreshold", spinBoxUpdateThreshold->value());
QgsSVGCache::instance().setOversampling(spbSVGOversampling->value());
settings.writeEntry("/qgis/svgoversampling", spbSVGOversampling->value());
accept();
}
@ -56,7 +27,6 @@ void QgsOptionsBase::cbxHideSplash_toggled( bool )
}
void QgsOptionsBase::addTheme(QString item)
{
cmbTheme->insertItem(item);
}
@ -67,26 +37,15 @@ void QgsOptionsBase::themeChanged(const QString & )
void QgsOptionsBase::setCurrentTheme()
{
QSettings settings;
cmbTheme->setCurrentText(settings.readEntry("/qgis/theme","default"));
}
void QgsOptionsBase::findBrowser()
{
QString filter;
#ifdef WIN32
filter = "Applications (*.exe)";
#else
filter = "All Files (*)";
#endif
QString browser = QFileDialog::getOpenFileName(
"./",
filter,
this,
"open file dialog",
"Choose a browser" );
if(browser.length() > 0)
}
void QgsOptionsBase::pbnSelectProjection_clicked()
{
cmbBrowser->setCurrentText(browser);
}
}

View File

@ -50,6 +50,8 @@ mUri(uri)
.arg(PQhost(mPgConnection))
.arg(PQuser(mPgConnection));
mOwnConnection = true; // we own this connection since we created it
// tell the DB that we want text encoded in UTF8
PQsetClientEncoding(mPgConnection, "UNICODE");
lblDataUri->setText(datasource);
populateFields();
}
@ -97,7 +99,7 @@ void QgsPgQueryBuilder::populateFields()
// Populate the field vector for this layer. The field vector contains
// field name, type, length, and precision (if numeric)
QString sql = "select * from " + mUri->schema + "." + mUri->table + " limit 1";
PGresult *result = PQexec(mPgConnection, (const char *) sql);
PGresult *result = PQexec(mPgConnection, (const char *) (sql.utf8()));
qWarning("Query executed: " + sql);
if (PQresultStatus(result) == PGRES_TUPLES_OK)
{
@ -111,22 +113,25 @@ void QgsPgQueryBuilder::populateFields()
int fieldModifier = PQfmod(result, i);
QString sql = "select typelem from pg_type where typelem = " + typOid + " and typlen = -1";
// //--std::cout << sql << std::endl;
PGresult *oidResult = PQexec(mPgConnection, (const char *) sql);
PGresult *oidResult = PQexec(mPgConnection,
(const char *) (sql.utf8()));
if (PQresultStatus(oidResult) == PGRES_TUPLES_OK)
std::cerr << "Ok fetching typelem using\n" << sql << std::endl;
// get the oid of the "real" type
QString poid = PQgetvalue(oidResult, 0, PQfnumber(oidResult, "typelem"));
QString poid = QString::fromUtf8(PQgetvalue(oidResult, 0,
PQfnumber(oidResult,
"typelem")));
std::cerr << "poid is: " << poid << std::endl;
PQclear(oidResult);
sql = "select typname, typlen from pg_type where oid = " + poid;
// //--std::cout << sql << std::endl;
oidResult = PQexec(mPgConnection, (const char *) sql);
oidResult = PQexec(mPgConnection, (const char *) (sql.utf8()));
if (PQresultStatus(oidResult) == PGRES_TUPLES_OK)
std::cerr << "Ok fetching typenam,etc\n";
QString fieldType = PQgetvalue(oidResult, 0, 0);
QString fieldSize = PQgetvalue(oidResult, 0, 1);
QString fieldType = QString::fromUtf8(PQgetvalue(oidResult, 0, 0));
QString fieldSize = QString::fromUtf8(PQgetvalue(oidResult, 0, 1));
PQclear(oidResult);
#ifdef QGISDEBUG
std::cerr << "Field parms: Name = " + fieldName
@ -155,14 +160,14 @@ void QgsPgQueryBuilder::getSampleValues()
// determine the field type
QgsField field = mFieldMap[lstFields->currentText()];
bool isCharField = field.type().find("char") > -1;
PGresult *result = PQexec(mPgConnection, (const char *) sql);
PGresult *result = PQexec(mPgConnection, (const char *) (sql.utf8()));
if (PQresultStatus(result) == PGRES_TUPLES_OK)
{
int rowCount = PQntuples(result);
for(int i=0; i < rowCount; i++)
{
QString value = PQgetvalue(result, i, 0);
QString value = QString::fromUtf8(PQgetvalue(result, i, 0));
if(isCharField)
{
lstValues->insertItem("'" + value + "'");
@ -191,14 +196,14 @@ void QgsPgQueryBuilder::getAllValues()
QgsField field = mFieldMap[lstFields->currentText()];
bool isCharField = field.type().find("char") > -1;
PGresult *result = PQexec(mPgConnection, (const char *) sql);
PGresult *result = PQexec(mPgConnection, (const char *) (sql.utf8()));
if (PQresultStatus(result) == PGRES_TUPLES_OK)
{
int rowCount = PQntuples(result);
for(int i=0; i < rowCount; i++)
{
QString value = PQgetvalue(result, i, 0);
QString value = QString::fromUtf8(PQgetvalue(result, i, 0));
if(isCharField)
{
@ -226,10 +231,10 @@ void QgsPgQueryBuilder::testSql()
QString numRows;
QString sql = "select count(*) from " + mUri->schema + "." + mUri->table
+ " where " + txtSQL->text();
PGresult *result = PQexec(mPgConnection, (const char *)sql);
PGresult *result = PQexec(mPgConnection, (const char *)(sql.utf8()));
if (PQresultStatus(result) == PGRES_TUPLES_OK)
{
numRows = PQgetvalue(result, 0, 0);
numRows = QString::fromUtf8(PQgetvalue(result, 0, 0));
QMessageBox::information(this, tr("Query Result"),
tr("The where clause returned ")
+ numRows + tr(" rows."));
@ -252,10 +257,10 @@ long QgsPgQueryBuilder::countRecords(QString where)
+ " where " + where;
long numRows;
PGresult *result = PQexec(mPgConnection, (const char *)sql);
PGresult *result = PQexec(mPgConnection, (const char *)(sql.utf8()));
if (PQresultStatus(result) == PGRES_TUPLES_OK)
{
QString rowCount = PQgetvalue(result, 0, 0);
QString rowCount = QString::fromUtf8(PQgetvalue(result, 0, 0));
numRows = rowCount.toLong();
}
else

View File

@ -45,8 +45,7 @@ using namespace std;
static const char *const ident_ =
"$Id$";
static const char *const ident_ = "$Id$";

View File

@ -18,6 +18,9 @@
/* $Id$ */
#include "qgsprojectproperties.h"
#include "qgsspatialreferences.h"
#include "qgscsexception.h"
#include "qgsprojectionselector.h"
//qgis includes
#include "qgsconfig.h"
@ -25,6 +28,7 @@
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsrenderer.h"
#include "qgis.h"
//qt includes
#include <qapplication.h>
@ -42,34 +46,17 @@
#include <qcheckbox.h>
#include <qregexp.h>
#include <qlistview.h>
#include <qprogressdialog.h>
#include <qapplication.h>
//stdc++ includes
#include <iostream>
#include <cstdlib>
const QString GEOWKT = "GEOGCS[\"WGS 84\", "
" DATUM[\"WGS_1984\", "
" SPHEROID[\"WGS 84\",6378137,298.257223563, "
" AUTHORITY[\"EPSG\",7030]], "
" TOWGS84[0,0,0,0,0,0,0], "
" AUTHORITY[\"EPSG\",6326]], "
" PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",8901]], "
" UNIT[\"DMSH\",0.0174532925199433,AUTHORITY[\"EPSG\",9108]], "
" AXIS[\"Lat\",NORTH], "
" AXIS[\"Long\",EAST], "
" AUTHORITY[\"EPSG\",4326]]";
// set the default coordinate system
//XXX this is not needed? : static const char* defaultWktKey = "Lat/Long - WGS 84";
QgsProjectProperties::QgsProjectProperties(QWidget *parent, const char *name)
: QgsProjectPropertiesBase(parent, name)
{
//for now we are disabling the use of projection related widgets until they are
//ready for production use
cbxProjectionEnabled->setEnabled(false);
lstCoordinateSystems->setEnabled(false);
teProjection->setEnabled(false);
// out with the old
// QgsProject::instance()->mapUnits( QgsScaleCalculator::METERS );
// in with the new...
@ -88,14 +75,21 @@ QgsProjectProperties::QgsProjectProperties(QWidget *parent, const char *name)
{
cbxProjectionEnabled->setChecked(true);
}
// set the default wkt to WGS 84
// QString defaultWkt = QgsSpatialReferences::instance()->getSrsBySrid(defaultWktKey)->srText();
// the /selectedWKT entry stores the wkt entry selected in the list of projections
QString srsWkt = QgsProject::instance()->readEntry("SpatialRefSys","/selectedWKT","WGS84");
getProjList();
projectionSelector->setSelectedWKT(srsWkt);
//if the user changes the projection for the project, we need to
//
// If the user changes the projection for the project, we need to
// fire a signal to each layer telling it to change its coordinateTransform
// member's output projection. These connects I'm setting up should be
// automatically cleaned up when this project props dialog closes
std::map<QString, QgsMapLayer *> myMapLayers = QgsMapLayerRegistry::instance()->mapLayers();
std::map<QString, QgsMapLayer *> myMapLayers
= QgsMapLayerRegistry::instance()->mapLayers();
std::map<QString, QgsMapLayer *>::iterator myMapIterator;
for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
{
@ -106,6 +100,12 @@ QgsProjectProperties::QgsProjectProperties(QWidget *parent, const char *name)
SLOT(setDestWKT(QString)));
}
setMapUnits(myUnit);
title(QgsProject::instance()->title());
// get the manner in which the number of decimal places in the mouse
// position display is set (manual or automatic)
bool automaticPrecision = QgsProject::instance()->readBoolEntry("PositionPrecision","/Automatic");
@ -139,14 +139,12 @@ QgsProjectProperties::QgsProjectProperties(QWidget *parent, const char *name)
myBlueInt = QgsProject::instance()->readNumEntry("Gui","/SelectionColorBluePart",0);
myColour = QColor(myRedInt,myGreenInt,myBlueInt);
pbnSelectionColour->setPaletteBackgroundColor (myColour);
}
QgsProjectProperties::~QgsProjectProperties()
{}
// return the map units
QgsScaleCalculator::units QgsProjectProperties::mapUnits() const
{
return QgsProject::instance()->mapUnits();
@ -182,10 +180,6 @@ void QgsProjectProperties::title( QString const & title )
QgsProject::instance()->title( title );
} // QgsProjectProperties::title( QString const & title )
QString QgsProjectProperties::projectionWKT()
{
return QgsProject::instance()->readEntry("SpatialRefSys","/WKT",GEOWKT);
}
//when user clicks apply button
@ -212,12 +206,32 @@ void QgsProjectProperties::apply()
{
QgsProject::instance()->writeEntry("SpatialRefSys","/ProjectionsEnabled",0);
}
//notify all layers the output projection has changed
//emit setDestWKT(mProjectionsMap[cboProjection->currentText()]);
emit setDestWKT(mProjectionsMap[lstCoordinateSystems->currentItem()->text(0)]);
//update the project props
//QgsProject::instance()->writeEntry("SpatialRefSys","/WKT",mProjectionsMap[cboProjection->currentText()]);
QgsProject::instance()->writeEntry("SpatialRefSys","/WKT",mProjectionsMap[lstCoordinateSystems->currentItem()->text(0)]);
// Only change the projection if there is a node in the tree
// selected that has an srid. This prevents error if the user
// selects a top-level node rather than an actual coordinate
// system
QString myWkt = projectionSelector->getCurrentWKT();
if (myWkt)
{
emit setDestWKT(myWkt);
// write the projection's wkt to the project settings rather
QgsProject::instance()->writeEntry("SpatialRefSys","/WKT",myWkt);
// write the currently selected projections name to project settings
QgsProject::instance()->writeEntry("SpatialRefSys","/selectedWKT",projectionSelector->getSelectedWKT());
// set the mouse display precision method and the
// number of decimal places for the manual option
// Note. Qt 3.2.3 and greater have a function selectedId() that
// can be used instead of the two part technique here
if (btnGrpPrecision->id(btnGrpPrecision->selected()) == 0)
QgsProject::instance()->writeEntry("PositionPrecision","/Automatic", true);
else
QgsProject::instance()->writeEntry("PositionPrecision","/Automatic", false);
QgsProject::instance()->writeEntry("PositionPrecision","/DecimalPlaces", spinBoxDP->value());
// Announce that we may have a new display precision setting
emit displayPrecisionChanged();
}
// set the mouse display precision method and the
// number of decimal places for the manual option
@ -250,6 +264,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry("Gui","/SelectionColorBluePart",myColour.blue());
QgsRenderer::mSelectionColor=myColour;
emit refresh();
}
//when user clicks ok
@ -258,273 +273,8 @@ void QgsProjectProperties::accept()
apply();
close();
}
void QgsProjectProperties::getProjList()
bool QgsProjectProperties::isProjected()
{
//first some hard coded options in case we cant open the wkt_defs file
mProjectionsMap["Lat/Long WGS84"] = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]";
mProjectionsMap["Lat/Long 1924 Brazil"] = "GEOGCS[\"1924 ellipsoid\", DATUM[\"Not_specified\", SPHEROID[\"International 1924\",6378388,297,AUTHORITY[\"EPSG\",\"7022\"]], AUTHORITY[\"EPSG","6022\"]], PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]], UNIT[\"degree\",0.0174532925199433, AUTHORITY[\"EPSG","9108\"]], AUTHORITY[\"EPSG","4022\"]]";
//...etc
std::cout << "Getting proj list " << std::endl;
#if defined(Q_OS_MACX) || defined(WIN32)
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
#endif
QString theFileNameQString = PKGDATAPATH;
theFileNameQString += "/resources/wkt_defs.txt";
QFile myQFile( theFileNameQString );
if ( myQFile.open( IO_ReadOnly ) )
{
//clear the existing entries in the taxon combo first
//cboCoordinateSystem->clear();
//now we parse the loc file, checking each line for its taxon
QTextStream myQTextStream( &myQFile );
QString myCurrentLineQString;
QStringList myQStringList;
// setup the nodes for the list view
geoList = new QListViewItem(lstCoordinateSystems,"Geographic Coordinate System");
projList = new QListViewItem(lstCoordinateSystems,"Projected Coordinate System");
// Read the QGIS-supplied CS file
while ( !myQTextStream.atEnd() )
{
myCurrentLineQString = myQTextStream.readLine(); // line of text excluding '\n'
#ifdef QGISDEBUG
//generates a lot of output to stdout!
//std::cout << " Match found:" << myCurrentLineQString.ascii() << std::endl;
#endif
//get the user friendly name for the WKT
QString myShortName = getWKTShortName(myCurrentLineQString);
if (!myShortName) continue;
mProjectionsMap[myShortName]=myCurrentLineQString;
}
myQFile.close();
// Read the users custom coordinate system (CS) file
// Get the user home dir. On Unix, this is $HOME. On Windows and MacOSX we
// will use the application directory.
//
// Note that the global cs file must exist or the user file will never
// be read.
//
// XXX Check to make sure this works on OSX
// construct the path to the users custom CS file
#if defined(WIN32) || defined(Q_OS_MACX)
customCsFile = PKGDATAPATH + "/share/qgis/user_defined_cs.txt";
#else
customCsFile = getenv("HOME");
customCsFile += "/.qgis/user_defined_cs.txt";
#endif
QFile csQFile( customCsFile );
if ( csQFile.open( IO_ReadOnly ) )
{
QTextStream userCsTextStream( &csQFile );
// Read the user-supplied CS file
while ( !userCsTextStream.atEnd() )
{
myCurrentLineQString = userCsTextStream.readLine(); // line of text excluding '\n'
//get the user friendly name for the WKT
QString myShortName = getWKTShortName(myCurrentLineQString);
mProjectionsMap[myShortName]=myCurrentLineQString;
}
csQFile.close();
}
// end of processing users custom CS file
//determine the current project projection so we can select the correct entry in the combo
QString myProjectionName = QgsProject::instance()->readEntry("SpatialRefSys","/WKT",GEOWKT);
QString mySelectedKey = getWKTShortName(myProjectionName);
QListViewItem * mySelectedItem = 0;
//make sure we dont allow duplicate entries into the combo
//cboProjection->setDuplicatesEnabled(false);
//no add each key to our list view
ProjectionWKTMap::Iterator myIterator;
QListViewItem *newItem;
for ( myIterator = mProjectionsMap.begin(); myIterator != mProjectionsMap.end(); ++myIterator )
{
//std::cout << "Widget map has: " <<myIterator.key().ascii() << std::endl;
//cboProjection->insertItem(myIterator.key());
//XXX Add to the tree view
if(myIterator.key().find("Lat/Long") > -1)
{
// this is a geographic coordinate system
// Add it to the tree
newItem = new QListViewItem(geoList, myIterator.key());
if (myIterator.key()==mySelectedKey)
{
// this is the selected item -- store it for future use
mySelectedItem = newItem;
}
}
else
{
// coordinate system is projected...
QListViewItem *node; // node that we will add this cs to...
// projected coordinate systems are stored by projection type
QStringList projectionInfo = QStringList::split(" - ", myIterator.key());
if(projectionInfo.size() == 2)
{
// Get the projection name and strip white space from it so we
// don't add empty nodes to the tree
QString projName = projectionInfo[1].stripWhiteSpace();
if(projName.length() == 0)
{
// If the projection name is blank, set the node to
// 0 so it won't be inserted
node = projList;
}
else
{
// Replace the underscores with blanks
projName = projName.replace('_', ' ');
// Get the node for this type and add the projection to it
// If the node doesn't exist, create it
node = lstCoordinateSystems->findItem(projName, 0);
if(node == 0)
{
// the node doesn't exist -- create it
node = new QListViewItem(projList, projName);
}
}
}
else
{
// No projection type is specified so add it to the top-level
// projection node
//XXX This should never happen
node = projList;
}
// now add the coordinate system to the appropriate node
newItem = new QListViewItem(node, myIterator.key());
if (myIterator.key()==mySelectedKey)
mySelectedItem = newItem;
}
} //else = proj coord sys
/**
//make sure all the loaded layer WKT's and the active project projection exist in the
//combo box too....
std::map<QString, QgsMapLayer *> myMapLayers = QgsMapLayerRegistry::instance()->mapLayers();
std::map<QString, QgsMapLayer *>::iterator myMapIterator;
for ( myMapIterator = myMapLayers.begin(); myMapIterator != myMapLayers.end(); ++myMapIterator )
{
QgsMapLayer * myMapLayer = myMapIterator->second;
QString myWKT = myMapLayer->getProjectionWKT();
QString myWKTShortName = getWKTShortName(myWKT);
//TODO add check here that CS is not already in the projections map
//and if not append to wkt_defs file
cboProjection->insertItem(myIterator.key());
mProjectionsMap[myWKTShortName]=myWKT;
}
//set the combo entry to the current entry for the project
cboProjection->setCurrentText(mySelectedKey);
*/
lstCoordinateSystems->setCurrentItem(mySelectedItem);
lstCoordinateSystems->ensureItemVisible(mySelectedItem);
}
else
{
QMessageBox::warning( this,tr("QGIS Error"),tr("The projections file is not readable. Check you have the neccessary file permissions and try again. Only a small list of projections is currently availiable."));
ProjectionWKTMap::Iterator myIterator;
for ( myIterator = mProjectionsMap.begin(); myIterator != mProjectionsMap.end(); ++myIterator )
{
//std::cout << "Widget map has: " <<myIterator.key().ascii() << std::endl;
//cboProjection->insertItem(myIterator.key());
if(myIterator.key().find("Lat/Long") > -1)
{
new QListViewItem(geoList, myIterator.key());
}
else
{
new QListViewItem(projList, myIterator.key());
}
}
}
}
void QgsProjectProperties::coordinateSystemSelected( QListViewItem * theItem)
{
//set the text box to show the full proection spec
std::cout << "Item selected : " << theItem->text(0) << std::endl;
std::cout << "Item selected full wkt : " << mProjectionsMap[theItem->text(0)] << std::endl;
QString myKey = mProjectionsMap[lstCoordinateSystems->currentItem()->text(0)];
if (!myKey.isEmpty())
{
QString myFullWKT = mProjectionsMap[theItem->text(0)];
if (!myFullWKT.isEmpty())
{
teProjection->setText(myFullWKT);
}
}
}
QString QgsProjectProperties::getWKTShortName(QString theWKT)
{
if (!theWKT) return NULL;
if (theWKT.isEmpty()) return NULL;
/* for example
PROJCS["Kertau / Singapore Grid",GEOGCS["Kertau",DATUM["Kertau",SPHEROID["Everest 1830 Modified",6377304.063,300.8017]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Cassini_Soldner"],PARAMETER["latitude_of_origin",1.28764666666667],PARAMETER["central_meridian",103.853002222222],PARAMETER["false_easting",30000],PARAMETER["false_northing",30000],UNIT["metre",1]]
We want to pull out
Kertau / Singapore Grid
and
Cassini_Soldner
*/
OGRSpatialReference mySpatialRefSys;
//this is really ugly but we need to get a QString to a char**
char * mySourceCharArrayPointer = (char*) theWKT.ascii();
/* Here are the possible OGR error codes :
typedef int OGRErr;
#define OGRERR_NONE 0
#define OGRERR_NOT_ENOUGH_DATA 1 --> not enough data to deserialize
#define OGRERR_NOT_ENOUGH_MEMORY 2
#define OGRERR_UNSUPPORTED_GEOMETRY_TYPE 3
#define OGRERR_UNSUPPORTED_OPERATION 4
#define OGRERR_CORRUPT_DATA 5
#define OGRERR_FAILURE 6
#define OGRERR_UNSUPPORTED_SRS 7 */
OGRErr myInputResult = mySpatialRefSys.importFromWkt( & mySourceCharArrayPointer );
if (myInputResult != OGRERR_NONE)
{
return NULL;
}
//std::cout << theWKT << std::endl;
//check if the coordinate system is projected or not
// if the spatial ref sys starts with GEOGCS, the coordinate
// system is not projected
QString myProjection,myDatum,myCoordinateSystem,myName;
if(theWKT.find(QRegExp("^GEOGCS")) == 0)
{
myProjection = "Lat/Long";
myCoordinateSystem = mySpatialRefSys.GetAttrValue("GEOGCS",0);
myName = myProjection + " - " + myCoordinateSystem.replace('_', ' ');
}
else
{
myProjection = mySpatialRefSys.GetAttrValue("PROJCS",0);
myCoordinateSystem = mySpatialRefSys.GetAttrValue("PROJECTION",0);
myName = myProjection + " - " + myCoordinateSystem.replace('_', ' ');
}
//std::cout << "Projection short name " << myName << std::endl;
return myName;
return cbxProjectionEnabled->isChecked();
}

View File

@ -25,8 +25,9 @@
#endif
#include <qgsscalecalculator.h>
#include "qgis.h"
/** Dialog to set project level properties
/*! Dialog to set project level properties
@note actual state is stored in QgsProject singleton instance
@ -41,61 +42,51 @@ public:
//! Destructor
~QgsProjectProperties();
/** Gets the currently select map units
/*! Gets the currently select map units
*/
QgsScaleCalculator::units mapUnits() const;
/**
/*!
* Set the map units
*/
void setMapUnits(QgsScaleCalculator::units);
/**
/*!
Every project has a title
*/
QString title() const;
void title( QString const & title );
/** Accessor for projection */
/*! Accessor for projection */
QString projectionWKT();
/** Get a short human readable name from a WKT */
QString getWKTShortName(QString theWKT);
/*! Indicates that the projection switch is on */
bool QgsProjectProperties::isProjected();
public slots:
/**
/*!
* Slot called when a new button (unit) is selected
* @param int specifying which button was selected. The button ids match the enum
* values in QgsScaleCalculator::units
*/
void mapUnitChange(int);
/**
/*!
* Slot called when apply button is pressed
*/
void apply();
/**
/*!
* Slot called when ok button pressed (inherits from gui base)
*/
void accept();
//! Populate the wkts map with projection names...
void getProjList();
//! Slot called when user selects a different item in the projections tree
void coordinateSystemSelected( QListViewItem * );
signals:
/** Used to notify all coordinateTransform objects to update their dest wkt because the project
output projection system is changed */
/*! This signal is used to notify all coordinateTransform objects to update
* their dest wkt because the project output projection system is changed
* @param SPATIAL_REF_SYS structure containing the parameters for the destination CS
*/
void setDestWKT(QString);
// Used to tell others that the mouse display precision may have changed
//! Signal used to inform listeners that the mouse display precision may have changed
void displayPrecisionChanged();
//! let listening canvases know to refresh
void refresh();
private:
typedef QMap<QString,QString> ProjectionWKTMap; //wkt = well known text (see gdal/ogr)
//stores a list of available projection definitions
ProjectionWKTMap mProjectionsMap;
//XXX List view items for the tree view of projections
QListViewItem *geoList;
QListViewItem *projList;
//! Users custom coordinate system file
QString customCsFile;
};

View File

@ -1,4 +1,4 @@
<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>QgsProjectPropertiesBase</class>
<widget class="QDialog">
<property name="name">
@ -8,13 +8,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>689</width>
<height>482</height>
<width>711</width>
<height>527</height>
</rect>
</property>
<property name="caption">
<string>Project Properties</string>
</property>
<property name="icon">
<pixmap>image0</pixmap>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
@ -111,43 +114,22 @@
</widget>
</hbox>
</widget>
<widget class="QSplitter" row="0" column="0">
<widget class="QTabWidget" row="0" column="0">
<property name="name">
<cstring>splitter1</cstring>
<cstring>tabWidget2</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<widget class="QLayoutWidget">
<widget class="QWidget">
<property name="name">
<cstring>layout8</cstring>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QGroupBox">
<property name="name">
<cstring>titleBox</cstring>
</property>
<property name="title">
<string>Project Title</string>
<cstring>tab</cstring>
</property>
<attribute name="title">
<string>General</string>
</attribute>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLineEdit" row="0" column="0">
<property name="name">
<cstring>titleEdit</cstring>
</property>
<property name="text">
<string>Default project title</string>
</property>
</widget>
</grid>
</widget>
<widget class="QButtonGroup">
<widget class="QButtonGroup" row="1" column="0">
<property name="name">
<cstring>btnGrpMapUnits</cstring>
</property>
@ -193,36 +175,137 @@
</widget>
</grid>
</widget>
<widget class="QGroupBox">
<widget class="QGroupBox" row="3" column="0">
<property name="name">
<cstring>groupBox2</cstring>
<cstring>groupBox2_2</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Map Appearance</string>
<string>Digitising Settings</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel" row="0" column="0">
<widget class="QLabel" row="1" column="0">
<property name="name">
<cstring>textLabel1</cstring>
<cstring>textLabel1_2_2</cstring>
</property>
<property name="text">
<string>Selection Color:</string>
<string>Line Width:</string>
</property>
</widget>
<widget class="QPushButton" row="0" column="1">
<widget class="QLineEdit" row="0" column="2">
<property name="name">
<cstring>pbnSelectionColour</cstring>
<cstring>leSnappingTolerance</cstring>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>32767</height>
</size>
</property>
</widget>
<widget class="QLabel" row="0" column="0">
<property name="name">
<cstring>textLabel1_2_2_2</cstring>
</property>
<property name="text">
<string>Snapping Tolerance:</string>
</property>
</widget>
<widget class="QSpinBox" row="1" column="2">
<property name="name">
<cstring>spinDigitisedLineWidth</cstring>
</property>
<property name="minValue">
<number>1</number>
</property>
</widget>
<widget class="QPushButton" row="2" column="2">
<property name="name">
<cstring>pbnDigitisedLineColour</cstring>
</property>
<property name="paletteBackgroundColor">
<color>
<red>111</red>
<green>244</green>
<blue>200</blue>
</color>
</property>
<property name="text">
<string></string>
</property>
</widget>
<spacer row="0" column="1">
<property name="name">
<cstring>spacer3</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>21</width>
<height>20</height>
</size>
</property>
</spacer>
<spacer row="1" column="1">
<property name="name">
<cstring>spacer4</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>31</width>
<height>20</height>
</size>
</property>
</spacer>
<spacer row="2" column="1">
<property name="name">
<cstring>spacer5</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>150</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="QLabel" row="2" column="0">
<property name="name">
<cstring>textLabel1_2</cstring>
</property>
<property name="text">
<string>Line Colour:</string>
</property>
</widget>
</grid>
</widget>
<widget class="QButtonGroup">
<widget class="QButtonGroup" row="2" column="0">
<property name="name">
<cstring>btnGrpPrecision</cstring>
</property>
@ -301,9 +384,28 @@
</widget>
</hbox>
</widget>
<widget class="QGroupBox">
<widget class="QGroupBox" row="4" column="0">
<property name="name">
<cstring>groupBox2_2</cstring>
<cstring>groupBox2</cstring>
</property>
<property name="title">
<string>Map Appearance</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel" row="0" column="0">
<property name="name">
<cstring>textLabel1</cstring>
</property>
<property name="text">
<string>Selection Color:</string>
</property>
</widget>
<widget class="QPushButton" row="0" column="2">
<property name="name">
<cstring>pbnSelectionColour</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
@ -313,119 +415,88 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Digitising Settings</string>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<widget class="QPushButton">
<property name="name">
<cstring>pbnDigitisedLineColour</cstring>
</property>
<property name="geometry">
<rect>
<x>157</x>
<y>82</y>
<width>177</width>
<height>30</height>
</rect>
</property>
<property name="paletteBackgroundColor">
<color>
<red>111</red>
<green>244</green>
<blue>200</blue>
</color>
<property name="maximumSize">
<size>
<width>120</width>
<height>32767</height>
</size>
</property>
<property name="text">
<string></string>
</property>
</widget>
<widget class="QLabel">
<spacer row="0" column="1">
<property name="name">
<cstring>textLabel1_2</cstring>
<cstring>spacer6</cstring>
</property>
<property name="geometry">
<rect>
<x>11</x>
<y>82</y>
<width>140</width>
<height>30</height>
</rect>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="text">
<string>Line Colour:</string>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>21</width>
<height>20</height>
</size>
</property>
</spacer>
</grid>
</widget>
<widget class="QSpinBox">
<widget class="QGroupBox" row="0" column="0">
<property name="name">
<cstring>spinDigitisedLineWidth</cstring>
<cstring>titleBox</cstring>
</property>
<property name="geometry">
<rect>
<x>157</x>
<y>53</y>
<width>177</width>
<height>23</height>
</rect>
<property name="title">
<string>Project Title</string>
</property>
<property name="minValue">
<number>1</number>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer6_2</cstring>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<property name="sizeType">
<enum>Fixed</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>9</height>
</size>
</property>
</spacer>
<widget class="QLineEdit">
<property name="name">
<cstring>leSnappingTolerance</cstring>
</property>
<property name="geometry">
<rect>
<x>157</x>
<y>23</y>
<width>177</width>
<height>24</height>
</rect>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1_2_2</cstring>
</property>
<property name="geometry">
<rect>
<x>11</x>
<y>53</y>
<width>140</width>
<height>23</height>
</rect>
<cstring>titleEdit</cstring>
</property>
<property name="text">
<string>Line Width:</string>
<string>Default project title</string>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1_2_2_2</cstring>
</property>
<property name="geometry">
<rect>
<x>11</x>
<y>23</y>
<width>140</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Snapping Tolerance:</string>
</property>
</widget>
</widget>
</vbox>
</widget>
<widget class="QButtonGroup">
</grid>
</widget>
<widget class="QWidget">
<property name="name">
<cstring>buttonGroup2</cstring>
<cstring>tab</cstring>
</property>
<property name="title">
<attribute name="title">
<string>Projection</string>
</property>
</attribute>
<grid>
<property name="name">
<cstring>unnamed</cstring>
@ -438,48 +509,9 @@
<string>Enable on the fly projection</string>
</property>
</widget>
<widget class="QListView" row="1" column="0">
<column>
<property name="text">
<string>Coordinate Systems</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<widget class="QgsProjectionSelector" row="1" column="0">
<property name="name">
<cstring>lstCoordinateSystems</cstring>
</property>
<property name="showSortIndicator">
<bool>true</bool>
</property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit" row="2" column="0">
<property name="name">
<cstring>teProjection</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>32767</width>
<height>76</height>
</size>
</property>
<property name="readOnly">
<bool>true</bool>
<cstring>projectionSelector</cstring>
</property>
</widget>
</grid>
@ -487,6 +519,11 @@
</widget>
</grid>
</widget>
<images>
<image name="image0">
<data format="PNG" length="593">89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000021849444154388d8d933f6853511487bf4886fb20e00b4478810e062a34e0f092adcfc988430382766bede29f0e5237c716858253079796ec2a594ad3c15a0721298a4fa72ab4f47590c6a1f0de10c8050befa00fae43882135959eed77ef39dfb9f777ef49f9becf79a3fac6332a07510dfc977e0a207daec275cfe00039d011f07db0776154c1c4f891999c3c3217331bc6c96d98d59b55d8571081ea0ce7fe0370dd2393bda479fbbec1b5ca1a4b2bdb142714ca15e880defb0fc0750f8c658584dd5d1a9b01ba23345a01739bdb70a2783056421dabb3019625843f03448420e8f616ef409808d57481fbf34516ee1587007f4d8c4f360c284820164177403d02958362c7e6c97c092b0385717b34a0381113ff8e914400452c1a350612c1f45889acd383abb48c0604fb9a92a35069458c509872c85eb15091e2ee4c1995eea213a1abcf30f146b58ed68224829581cad53caa050b3305f239858880c0e72fe16880effb297f2784a4a7db879a7a2da070d921941050345b21cd7711bedffb8543006fd6338ff75a2cadfb743bc2f4ad0225d7c1b62d0076bf45acad7c456be1d3c7553304a8bcf08c3dd5336c7bff0773cf9a047b5d1697cb44c7402288401881f9f51a918111a9fe30799e6700d46d4083ecf412b69a55caae8d24e064f234b6da3c9c6dd0fc706a98faf7aad63c23d1402f3e9d3595eb59b2399b83c380c67a1b49463c633ff42bc019e8e7cbf554ff74a79b01fc013633ebcd0e2d66c60000000049454e44ae426082</data>
</image>
</images>
<connections>
<connection>
<sender>buttonOk</sender>
@ -524,23 +561,18 @@
<receiver>QgsProjectPropertiesBase</receiver>
<slot>pbnDigitisedLineColour_clicked()</slot>
</connection>
<connection>
<sender>lstCoordinateSystems</sender>
<signal>currentChanged(QListViewItem*)</signal>
<receiver>QgsProjectPropertiesBase</receiver>
<slot>coordinateSystemSelected(QListViewItem*)</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">qgsprojectpropertiesbase.ui.h</include>
</includes>
<slots>
<slot>mapUnitChange( int )</slot>
<slot>projectionChanged( const QString &amp; )</slot>
<slot>apply()</slot>
<slot>pbnSelectionColour_clicked()</slot>
<slot>pbnDigitisedLineColour_clicked()</slot>
<slot>coordinateSystemSelected( QListViewItem * )</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
<includehints>
<includehint>qgsprojectionselector.h</includehint>
</includehints>
</UI>

View File

@ -1,3 +1,4 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
@ -6,6 +7,7 @@
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
#include "../widgets/projectionselector/qgsprojectionselector.h"
#include <qcolordialog.h>
void QgsProjectPropertiesBase::mapUnitChange( int )
{
@ -13,13 +15,6 @@ void QgsProjectPropertiesBase::mapUnitChange( int )
}
void QgsProjectPropertiesBase::projectionChanged( const QString & )
{
}
void QgsProjectPropertiesBase::apply()
{
@ -40,8 +35,4 @@ void QgsProjectPropertiesBase::pbnDigitisedLineColour_clicked()
}
void QgsProjectPropertiesBase::coordinateSystemSelected( QListViewItem * )
{
}

View File

@ -301,6 +301,16 @@ void QgsRasterLayer::buildSupportedRasterFileFilter(QString & theFileFiltersStri
theFileFiltersString += "JPEG 2000 (" + glob.lower() + " " + glob.upper() + ");;";
}
// A number of drivers support JPEG 2000. Add it in for those.
if ( myGdalDriverDescription.startsWith("MrSID")
|| myGdalDriverDescription.startsWith("ECW")
|| myGdalDriverDescription.startsWith("JPEG2000")
|| myGdalDriverDescription.startsWith("JP2KAK") )
{
QString glob = "*.jp2 *.j2k";
theFileFiltersString += "JPEG 2000 (" + glob.lower() + " " + glob.upper() + ");;";
}
myGdalDriverExtension = myGdalDriverLongName = ""; // reset for next driver
} // each loaded GDAL driver
@ -2367,7 +2377,6 @@ const RasterBandStats QgsRasterLayer::getRasterBandStats(int theBandNoInt)
#endif
CPLFree(myData);
myRasterBandStats.statsGatheredFlag = true;
#ifdef QGISDEBUG

View File

@ -903,7 +903,6 @@ void QgsRasterLayerProperties::sync()
} // QgsRasterLayerProperties::sync()
void QgsRasterLayerProperties::pbnHistRefresh_clicked()
{
#ifdef QGISDEBUG

View File

@ -1,4 +1,4 @@
<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>QgsRasterLayerPropertiesBase</class>
<widget class="QDialog">
<property name="name">

View File

@ -158,6 +158,75 @@ void QgsSingleSymRenderer::initializeSymbology(QgsVectorLayer * layer, QgsDlgVec
QgsRenderItem* ri = new QgsRenderItem(sy, "", "");
addItem(ri);
QgsSiSyDialog *dialog = new QgsSiSyDialog(layer);
if (toproperties)
{
mVectorType = layer->vectorType();
QgsSymbol* sy = new QgsSymbol();
sy->brush().setStyle(Qt::SolidPattern);
sy->pen().setStyle(Qt::SolidLine);
sy->pen().setWidth(1);//set width 1 as default instead of width 0
//random fill colors for points and polygons and pen colors for lines
int red = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
int green = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
int blue = 1 + (int) (255.0 * rand() / (RAND_MAX + 1.0));
//font tor the legend text
QFont f("arial", 10, QFont::Normal);
QFontMetrics fm(f);
QPixmap *pixmap;
if (toproperties)
{
pixmap = pr->getBufferPixmap();
}
else
{
pixmap = layer->legendPixmap();
}
QString name = layer->name();
int width = 40 + fm.width(layer->name());
int height = (fm.height() + 10 > 35) ? fm.height() + 10 : 35;
pixmap->resize(width, height);
pixmap->fill();
QPainter p(pixmap);
p.setPen(sy->pen());
if (layer->vectorType() == QGis::Line)
{
sy->pen().setColor(QColor(red, green, blue));
//paint the pixmap for the legend
p.setPen(sy->pen());
p.drawLine(10, pixmap->height() - 25, 25, pixmap->height() - 10);
}
else
{
sy->brush().setColor(QColor(red, green, blue));
sy->pen().setColor(QColor(0, 0, 0));
//paint the pixmap for the legend
p.setPen(sy->pen());
p.setBrush(sy->brush());
if (layer->vectorType() == QGis::Point)
{
//p.drawRect(20, pixmap->height() - 17, 5, 5);
QPixmap pm = sy->getPointSymbolAsPixmap();
p.drawPixmap ( (int) (17-pm.width()/2), (int) ((pixmap->height()-pm.height())/2), pm );
}
else //polygon
{
p.drawRect(10, pixmap->height() - 25, 20, 15);
}
}
p.setPen(Qt::black);
p.setFont(f);
p.drawText(35, pixmap->height() - 10, name);
QgsRenderItem* ri = new QgsRenderItem(sy, "", "");
addItem(ri);
QgsSiSyDialog *dialog = new QgsSiSyDialog(layer);
if (toproperties)
{
@ -171,6 +240,13 @@ void QgsSingleSymRenderer::initializeSymbology(QgsVectorLayer * layer, QgsDlgVec
}
}
else
{
layer->setRendererDialog(dialog);
QgsLegendItem *item;
layer->updateItemPixmap();
}
}
else
{
qWarning("Warning, null pointer in QgsSingleSymRenderer::initializeSymbology()");
}
@ -238,3 +314,4 @@ const std::list<QgsRenderItem*> QgsSingleSymRenderer::items() const
list.push_back(mItem);
return list;
}

View File

@ -0,0 +1,135 @@
/***************************************************************************
qgspatialreferences.cpp - Singleton class for
storing spatial reference systems
-------------------
begin : 2005-01-22
copyright : (C) 2005 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#include <iostream>
#include <qstring.h>
#include <qdir.h>
#include <qmap.h>
#include "qgsspatialreferences.h"
QgsSpatialReferences *QgsSpatialReferences::_instance = 0;
QgsSpatialReferences *QgsSpatialReferences::instance()
{
if (_instance == 0)
{
_instance = new QgsSpatialReferences();
}
return _instance;
}
QgsSpatialReferences::QgsSpatialReferences()
{
// read the spatial reference systems from disk and populate the map
#if defined(Q_OS_MACX) || defined(WIN32)
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
#endif
QString theFileNameQString = PKGDATAPATH;
theFileNameQString += "/resources/spatial_ref_sys.txt";
QFile myQFile( theFileNameQString );
if ( myQFile.open( IO_ReadOnly ) )
{
QTextStream myQTextStream( &myQFile );
QString myCurrentLineQString;
// Read the QGIS-supplied CS file which is actually taken from PostGIS spatial_ref_sys
// table. The schema for this table:
// Table "public.spatial_ref_sys"
// Column | Type | Modifiers
// -----------+-------------------------+-----------
// 0 srid | integer | not null
// 1 auth_name | character varying(256) |
// 2 auth_srid | integer |
// 3 srtext | character varying(2048) |
// 4 proj4text | character varying(2048) |
int wktCount = 0;
while ( !myQTextStream.atEnd() )
{
myCurrentLineQString = myQTextStream.readLine(); // line of text excluding '\n'
#ifdef QGISDEBUG
//generates a lot of output to stdout!
//std::cout << " Match found:" << myCurrentLineQString.ascii() << std::endl;
#endif
QStringList wktParts = QStringList::split(QRegExp("\t"), myCurrentLineQString, true);
// get the short name for the projection
QString wkt = wktParts[3];
QString name;
bool isGeo;
if(wkt.find(QRegExp("^GEOGCS")) == 0)
{
isGeo = true;
name = "Lat/Long - ";
// get the name
name += wkt.mid(8, wkt.find("\",") - 8);
// std::cout << name << std::endl;
}
else
{
isGeo = false;
// get the name and projection type
name = wkt.mid(8, wkt.find("\",") - 8) + " - ";
int start = wkt.find("PROJECTION[") + 12;
name += wkt.mid(start, wkt.find("\"]", start) - start);
// std::cout << name << std::endl;
}
// store the parts in a QgsSpatialRefSys object
QgsSpatialRefSys *srs = new QgsSpatialRefSys(
wktParts[0],
wktParts[1],
wktParts[2],
wktParts[3],
wktParts[4],
name);
srs->setGeographic(isGeo);
mSpatialReferences[wktParts[0]] = srs;
}
}
}
QgsSpatialRefSys * QgsSpatialReferences::getSrsBySrid(QString srid)
{
return mSpatialReferences[srid];
}
QgsSpatialRefSys * QgsSpatialReferences::getSrsByWkt(QString &wkt)
{
// find the srs by looking up the wkt in the map
projectionWKTMap_t::Iterator it;
QgsSpatialRefSys *srs;
for ( it = mSpatialReferences.begin(); it != mSpatialReferences.end(); ++it )
{
srs = *it;
if(srs->srText() == wkt)
{
return srs;
}
}
// if we don't find a match, return 0;
return 0;
}
projectionWKTMap_t QgsSpatialReferences::getMap()
{
return mSpatialReferences;
}

View File

@ -0,0 +1,67 @@
/***************************************************************************
qgsspatialreferencesystems.h - Singleton class for
Spatial reference systems
-------------------
begin : 2005-01-22
copyright : (C) 2005 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id$ */
#ifndef QGSSPATIALREFERENCESYSTEMS_H
#define QGSSPATIALREFERENCESYSTEMS_H
#include <qmap.h>
#include "qgsspatialrefsys.h"
class QString;
//! Typedef for map containing spatial reference system objects
typedef QMap<QString,QgsSpatialRefSys*> projectionWKTMap_t ; //wkt = well known text (see gdal/ogr)
/*!
* \class QgsSpatialReferences
* \brief Singleton class to manage spatial reference systems
*/
class QgsSpatialReferences
{
public:
/*!
* Function to return the instance pointer to the singleton QgsSpatialReferences
* class. On first call to instance(), the object is constructed and the spatial
* references read from the share/qgis/resources/spatial_ref_sys.txt
* @return Pointer to the one and only QgsSpatialReferences instance
*/
static QgsSpatialReferences* instance();
/*!
* Get a spatial reference system using its spatial reference id (SRID)
* @return Pointer to a spatial reference system matching the specified SRID
*/
QgsSpatialRefSys * getSrsBySrid(QString srid);
/*!
* Get a spatial reference system using its well known text (WKT) specification.
* @return Pointer to a spatial reference system matching the specified WKT
*/
QgsSpatialRefSys * getSrsByWkt(QString &wkt);
/*!
* Get the map containing the collection of spatial reference systems
* @return The map of spatial reference systems
*/
projectionWKTMap_t getMap();
protected:
//! Protected constructor
QgsSpatialReferences();
private:
//! Instance member pointer
static QgsSpatialReferences* _instance;
//! Map containing the spatial reference systems read from the spatial_ref_sys file
projectionWKTMap_t mSpatialReferences;
};
#endif // QGSSPATIALREFERENCESYSTEMS_H

64
src/qgsspatialrefsys.cpp Normal file
View File

@ -0,0 +1,64 @@
#include "qgsspatialrefsys.h"
QgsSpatialRefSys::QgsSpatialRefSys(){}
QgsSpatialRefSys::QgsSpatialRefSys(QString srid, QString authName, QString authSrid,
QString srtext, QString proj4Text, QString name):mSrid(srid), mAuthName(authName), mAuthSrid(authSrid), mSrtext(srtext), mProj4text(proj4Text), mName(name)
{
}
QString QgsSpatialRefSys::srid() const
{
return mSrid;
}
QString QgsSpatialRefSys::authName() const
{
return mAuthName;
}
QString QgsSpatialRefSys::authSrid() const
{
return mAuthSrid;
}
QString QgsSpatialRefSys::srText() const
{
return mSrtext;
}
QString QgsSpatialRefSys::proj4Text() const
{
return mProj4text;
}
QString QgsSpatialRefSys::name() const
{
return mName;
}
void QgsSpatialRefSys::setSrid(QString& srid)
{
mSrid = srid;
}
void QgsSpatialRefSys::setAuthName(QString &authname)
{
mAuthName = authname;
}
void QgsSpatialRefSys::setAuthSrid(QString &authsrid)
{
mAuthSrid = authsrid;
}
void QgsSpatialRefSys::setSrText(QString &srtext)
{
mSrtext = srtext;
}
void QgsSpatialRefSys::setProjText(QString &projtext)
{
mProj4text = projtext;
}
void QgsSpatialRefSys::setName(QString &shortname)
{
mName = shortname;
}
bool QgsSpatialRefSys::isGeographic()
{
return mGeographic;
}
void QgsSpatialRefSys::setGeographic(bool isGeogCS)
{
mGeographic = isGeogCS;
}

135
src/qgsspatialrefsys.h Normal file
View File

@ -0,0 +1,135 @@
#ifndef QGSSPATIALREFSYS_H
#define QGSSPATIALREFSYS_H
#include <ostream>
#include <istream>
#include <qstring.h>
#include <qstringlist.h>
#include <qregexp.h>
/*!
* \class QgsSpatialRefSys
* \brief Class for storing a spatial reference system (SRS)
*/
class QgsSpatialRefSys
{
public:
//! Default constructor
QgsSpatialRefSys();
/*!
* Constructs a SRS object from the five component parts
* @param srid Spatial reference id (SRID)
* @param authName Name of the authority for the SRS
* @param authSrid SRID of the SRS assigned by the authority
* @param srtext Well known text (WKT) of the SRS
* @param proj4text Proj4 parameter string
*/
QgsSpatialRefSys(QString srid, QString authName, QString authSrid, QString srtext, QString proj4text, QString name);
/*!
* Get the SRID
* @return SRID of the SRS
*/
QString srid() const;
/*!
* Get the authority name
* @return authority name of the SRS creator
*/
QString authName() const;
/*!
* Get the SRID assigned by the SRS creator
* @return SRID
*/
QString authSrid() const;
/*!
* Get the WKT of the SRS
* @return Well known text of the SRS
*/
QString srText() const;
/*!
* Get the proj4 parameter string for the SRS
* @return proj4 parameters
*/
QString proj4Text() const;
/*!
* Get the short name of the projection
* @return name including the projection system
*/
QString name() const;
/*!
* Test to see if the SRS is geographic
* @return true if geographic or false if the SRS is projected
*/
bool isGeographic();
/*!
* Set the flag to indicate if the SRS is geographic
* @param isGeo true if the SRS is geographic; false if its projected
*/
void setGeographic(bool isGeo);
/*!
* Set the SRID
* @param srid Spatial reference id to assign to the object
*/
void setSrid(QString &srid);
/*!
* Set the authority name
* @param authname Authority name
*/
void setAuthName(QString &authname);
/*!
* Set the authority assigned SRID
* @param authsrid Authority assigned SRID
*/
void setAuthSrid(QString &authsrid);
/*!
* Set the WKT
* @param srtext Well known text of the SRS
*/
void setSrText(QString &srtext);
/*!
* Set the Proj4 parameters
* @param projtext Proj4 parameter string
*/
void setProjText(QString &projtext);
/*!
* Set the short name
* @param shortname Short name of the SRS
*/
void setName(QString &shortname);
private:
//! SRID
QString mSrid;
//! Authority name
QString mAuthName;
//! Authority assigned SRID
QString mAuthSrid;
//! WKT for the SRS
QString mSrtext;
//! Proj4 paramters
QString mProj4text;
//! Short name
QString mName;
//! Flag to indicate if the SRS is geographic (unprojected)
bool mGeographic;
};
//! Output stream operator
inline std::ostream& operator << (std::ostream& os, const QgsSpatialRefSys &r)
{
return os << r.srid() << "\t" << r.authName() << "\t" << r.authSrid()
<< "\t" << r.srText() << "\t" << r.proj4Text() << "\t" << r.name() << std::endl;
}
//! Input stream operator
inline std::istream& operator>> (std::istream& str, QgsSpatialRefSys& r)
{
std::string s;
str >> s;
QString srs = s.c_str();
// split the string into the parts to created the object
QStringList parts = QStringList::split(QRegExp("\t"),srs);
r.setSrid(parts[0]);
r.setAuthName(parts[1]);
r.setAuthSrid(parts[2]);
r.setSrText(parts[3]);
r.setProjText(parts[4]);
r.setName(parts[5]);
return str;
}
#endif // QGSSPATIALREFSYS_H

View File

@ -181,6 +181,39 @@ class QgsVectorDataProvider : public QgsDataProvider
void setEncoding(const QString& e);
QString encoding() const;
/*! Indicates if the provider does its own coordinate transforms
* @return true if the provider transforms its coordinates, otherwise false
*/
virtual bool supportsNativeTransform(){return false;};
/*! Used to determine if the provider supports transformation using the
* SRID of the target SRS.
* @return true if SRID is used, otherwise false
*/
virtual bool usesSrid(){return false;};
/*! Used to determine if the provider supports transformation using the
* WKT of the target SRS.
* @return true if WKT is used, otherwise false
*/
virtual bool usesWKT(){return false;};
/*! Set the SRID of the target SRS.
* This is only implemented if the provider supports native
* transformation of its coordinates
* @param srid Spatial reference id of the target (map canvas)
*/
virtual void setSrid(int srid){};
/*! Get the SRID of the target SRS
* If the provider isn't capable of reporting the SRID of
* the projection, ti will return 0
*/
virtual int getSrid(){return 0;};
/*! Set the WKT of the target SRS.
* This is only implemented if the provider supports native
* transformation of its coordinates
*
* @param wkt Well known text of the target (map canvas) SRS
*/
virtual void setWKT(QString wkt){};
protected:
/**Encoding*/
@ -189,6 +222,17 @@ protected:
std::list<QString> mNonNumericalTypes;
/**List of type names for numerical types*/
std::list<QString> mNumericalTypes;
/** The spatial reference id of the map canvas. This is the
* SRID the provider should transform its coordinates to if
* supportsNativeTransform is true. Otherwise this member is unused.
*/
int mTargetSrid;
/** The WKT of the SRS of the map canvas. This is the
* SRS the provider should transform its coordinates to if
* supportsNativeTransform is true. Otherwise this member is unused.
* The provider may choose to support transformation using SRID or WKT.
*/
int mTargetWKT;
};
#endif

View File

@ -29,6 +29,7 @@
#include <sstream>
#include <memory>
#include <vector>
#include <cassert>
// for htonl
#ifdef WIN32
@ -82,6 +83,7 @@
#include "qgsattributedialog.h"
#include "qgsclipper.h"
#include "qgssvgcache.h"
#include "qgslayerprojectionselector.h"
//#include "wkbheader.h"
#ifdef TESTPROVIDERLIB
@ -115,6 +117,10 @@ QgsVectorLayer::QgsVectorLayer(QString vectorLayerPath,
{
setDataProvider( providerKey );
}
if(valid)
{
setCoordinateSystem();
}
// Default for the popup menu
popMenu = 0;
@ -184,6 +190,19 @@ bool QgsVectorLayer::projectionsEnabled()
return false;
}
}
int QgsVectorLayer::getProjectionSrid()
{
//delegate to the provider
if (valid)
{
return dataProvider->getSrid();
}
else
{
return 0;
}
}
QString QgsVectorLayer::getProjectionWKT()
{
//delegate to the provider
@ -497,7 +516,7 @@ QgsVectorLayer::endian_t QgsVectorLayer::endian()
void QgsVectorLayer::identify(QgsRect * r)
{
QApplication::setOverrideCursor(Qt::waitCursor);
QApplication::setOverrideCursor(Qt::WaitCursor);
dataProvider->select(r, true);
int featureCount = 0;
QgsFeature *fet;
@ -781,7 +800,7 @@ void QgsVectorLayer::select(int number)
void QgsVectorLayer::select(QgsRect * rect, bool lock)
{
QApplication::setOverrideCursor(Qt::waitCursor);
QApplication::setOverrideCursor(Qt::WaitCursor);
// normalize the rectangle
rect->normalize();
if (tabledisplay)
@ -1435,7 +1454,8 @@ void QgsVectorLayer::stopEditing()
if(mModified)
{
//commit or roll back?
int commit=QMessageBox::information(0,"Stop editing","Do you want to save the changes?",QMessageBox::Yes,QMessageBox::No);
int commit=QMessageBox::information(0,"Stop editing",
"Do you want to save the changes?",QMessageBox::Yes,QMessageBox::No);
if(commit==QMessageBox::Yes)
{
if(!commitChanges())
@ -1457,7 +1477,8 @@ void QgsVectorLayer::stopEditing()
{
if(!rollBack())
{
QMessageBox::information(0,"Error","Problems during roll back",QMessageBox::Ok);
QMessageBox::information(0,"Error",
"Problems during roll back",QMessageBox::Ok);
}
//hide and delete the table because it is not up to date any more
if (tabledisplay)
@ -1765,18 +1786,6 @@ QgsVectorLayer:: setDataProvider( QString const & provider )
// label
mLabel = new QgsLabel ( dataProvider->fields() );
mLabelOn = false;
//
// Get the layers project info and set up the QgsCoordinateTransform for this layer
//
QString mySourceWKT = getProjectionWKT();
//get the project projection, defaulting to this layer's projection
//if none exists....
QString myDestWKT = QgsProject::instance()->readEntry("SpatialRefSys","/WKT",mySourceWKT);
//set up the coordinat transform - in the case of raster this is mainly used to convert
//the inverese projection of the map extents of the canvas when zzooming in etc. so
//that they match the coordinate system of this layer
mCoordinateTransform = new QgsCoordinateTransform(mySourceWKT,myDestWKT);
}
}
else
@ -2497,6 +2506,170 @@ void QgsVectorLayer::saveAsShapefile()
dataProvider->saveAsShapefile();
// QMessageBox::information(0,"Save As Shapefile", "Someday...");
}
void QgsVectorLayer::setCoordinateSystem()
{
//
// Get the layers project info and set up the QgsCoordinateTransform
// for this layer
//
int srid = getProjectionSrid();
QString mySourceWKT;
if(srid == 0)
{
mySourceWKT = getProjectionWKT();
}
QSettings mySettings;
// if the provider supports native transforms, just create a passthrough
// object
if(dataProvider->supportsNativeTransform())
{
#ifdef QGISDEBUG
std::cout << "Provider supports native transform -- no projection of coordinates will occur"
<< std::endl;
#endif
QApplication::restoreOverrideCursor();
mCoordinateTransform = new QgsCoordinateTransform("", "");
dataProvider->setWKT(QgsProject::instance()->readEntry("SpatialRefSys","/selectedWKT","WGS84"));
return;
}
else
{
// if the wkt does not exist, then we can not set the projection
// Pass this through unprojected
// XXX Do we need to warn the user that this layer is unprojected?
// XXX Maybe a user option to choose if warning should be issued
if((srid == 0) && (mySourceWKT.isEmpty()))
{
//decide whether to use project default projection or to prompt for one
QString myDefaultProjectionOption =
mySettings.readEntry("/qgis/projections/defaultBehaviour");
if (myDefaultProjectionOption=="prompt")
{
//@note qgsvectorlayer is not a descendent of QWidget so we cant pass
//it in the ctor of the layer projection selector
QgsLayerProjectionSelector * mySelector = new QgsLayerProjectionSelector();
QString srsWkt =
QgsProject::instance()->readEntry("SpatialRefSys","/selectedWKT","WGS84");
mySelector->setSelectedWKT(srsWkt);
if(mySelector->exec())
{
#ifdef QGISDEBUG
std::cout << "------ Layer Projection Selection passed ----------" << std::endl;
#endif
mySourceWKT = mySelector->getCurrentWKT();
#ifdef QGISDEBUG
std::cout << "------ mySourceWKT ----------\n" << mySourceWKT << std::endl;
#endif
}
else
{
#ifdef QGISDEBUG
std::cout << "------ Layer Projection Selection FAILED ----------" << std::endl;
#endif
QApplication::restoreOverrideCursor();
mCoordinateTransform = new QgsCoordinateTransform("", "");
return;
}
}
else if (myDefaultProjectionOption=="useProject")
{
mySourceWKT = QgsProject::instance()->readEntry("SpatialRefSys","/selectedWKT","WGS84");
}
else ///qgis/projections/defaultBehaviour==useDefault
{
//shamelessly hard coded for now
//XXX TODO get this from options dlg
mySourceWKT = mySettings.readEntry("/qgis/projections/defaultProjectionWKT");
}
}
assert(!mySourceWKT.isEmpty());
//get the project projections WKT, defaulting to this layer's projection
//if none exists....
//First get the SRS for the default projection WGS 84
//QString defaultWkt = QgsSpatialReferences::instance()->getSrsBySrid("4326")->srText();
QString myDestWKT = QgsProject::instance()->readEntry("SpatialRefSys","/WKT","");
// try again with a morph from esri
// set up the spatial ref
OGRSpatialReference myInputSpatialRefSys;
char *pWkt = (char*)mySourceWKT.ascii();
myInputSpatialRefSys.importFromWkt(&pWkt);
myInputSpatialRefSys.morphFromESRI();
// set up the destination cs
OGRSpatialReference myOutputSpatialRefSys;
pWkt = (char *) myDestWKT.ascii();
myOutputSpatialRefSys.importFromWkt(&pWkt);
//
// Sort out what to do with this layer's coordinate system (CS). We have
// four possible scenarios:
// 1. Layer has no projection info and canvas is projected
// = set layer to canvas CS XXX does the user need a warning here?
// 2. Layer has no projection info and canvas is unprojected
// = leave both layer and canvas unprojected XXX is this appropriate?
// 3. Layer has projection info and canvas is unprojected
// = set canvas to layer's CS
// 4. Layer has projection info and canvas is projected
// = setup transform for layer to canvas CS
#ifdef QGISDEBUG
std::cout << ">>>>>>>>>>>> ----------------------------------------------------" << std::endl;
#endif
if(mySourceWKT.length() == 0)
{
#ifdef QGISDEBUG
std::cout << ">>>>>>>>>>>> layer has no CS..." ;
#endif
// layer has no CS
if(myDestWKT.length() > 0)
{
#ifdef QGISDEBUG
std::cout << "set layer CS to project CS" << std::endl;
#endif
// set layer CS to project CS
mySourceWKT = myDestWKT;
}
else
{
// leave layer with no CS
#ifdef QGISDEBUG
std::cout << "project CS also undefined....leaving both empty" << std::endl;
#endif
}
}
else
{
// layer has a CS
#ifdef QGISDEBUG
std::cout << ">>>>>>>>>>>> layer HAS a CS...." << std::endl;
#endif
if(myDestWKT.length() == 0)
{
// set project CS to layer CS
#ifdef QGISDEBUG
std::cout << ">>>>>>>>>>>> project CS was undefined so its now set to layer CS" << std::endl;
#endif
myDestWKT = mySourceWKT;
QgsProject::instance()->writeEntry("SpatialRefSys","/WKT", myDestWKT);
}
}
//set up the coordinate transform - in the case of raster this is
//mainly used to convert the inverese projection of the map extents
//of the canvas when zzooming in etc. so that they match the coordinate
//system of this layer
mCoordinateTransform = new QgsCoordinateTransform(mySourceWKT, myDestWKT);
#ifdef QGISDEBUG
std::cout << ">>>>>>>>>>>> Transform for layer created:" << std::endl;
std::cout << ">>>>>>>>>>>> LayerCS:\n" << mySourceWKT << std::endl;
std::cout << ">>>>>>>>>>>> ProjectCS:\n" << myDestWKT << std::endl;
std::cout << ">>>>>>>>>>>> ----------------------------------------------------" << std::endl;
#endif
}
}
bool QgsVectorLayer::commitAttributeChanges(const std::set<QString>& deleted,
const std::map<QString,QString>& added,

View File

@ -97,11 +97,18 @@ const QString displayField() const { return fieldIndex; }
*/
void setDataProvider( QString const & provider );
//! Setup the coordinate system tranformation for the layer
void setCoordinateSystem();
QgsVectorDataProvider * getDataProvider();
/** \brief Query data provider to find out the WKT projection string for this layer. This implements the virtual method of the same name defined in QgsMapLayer*/
QString getProjectionWKT();
/*!
* Gets the SRID of the layer by querying the underlying data provider
* @return The SRID if the provider is able to provide it, otherwise 0
*/
int getProjectionSrid();
QgsLabel *label();
QgsAttributeAction* actions() { return &mActions; }

View File

@ -12,7 +12,7 @@
resourcedir = ${pkgdatadir}/resources
resource_DATA = wkt_defs.txt
resource_DATA = spatial_ref_sys.txt srs.db
EXTRA_DIST = $(resource_DATA)

File diff suppressed because it is too large Load Diff

BIN
src/resources/srs.db Normal file

Binary file not shown.

View File

@ -42,10 +42,12 @@ class ProjectionCsHandlingTest : public CppUnit::TestCase {
&ProjectionCsHandlingTest::testAkAlbersExportToProj4NoMorph ) );
suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
"testAkAlbersExportToProj4Morph",
&ProjectionCsHandlingTest::testAkAlbersExportToProj4Morph ) );
suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
&ProjectionCsHandlingTest::testAkAlbersExportToProj4Morph ) ); suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
"testWktFromFile",
&ProjectionCsHandlingTest::testWktFromFile ) );
suiteOfTests->addTest( new CppUnit::TestCaller<ProjectionCsHandlingTest>(
"testOgrTransform",
&ProjectionCsHandlingTest::testOgrTransform ) );
return suiteOfTests;
}
//
@ -221,6 +223,7 @@ wktAkAlbers = "PROJCS[\"Alaska_Albers_Equal_Area_Conic\",GEOGCS[\"GCS_North_Amer
wktIn.getline(buf, 16384);
wktIn.close();
std::cout << "\n\nGetting proj4 parameters from wkt.txt" << std::endl;
std::cout << buf << std::endl;
// set up the spatial ref
OGRSpatialReference myInputSpatialRefSys;
CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&buf)== OGRERR_NONE);
@ -230,10 +233,47 @@ wktAkAlbers = "PROJCS[\"Alaska_Albers_Equal_Area_Conic\",GEOGCS[\"GCS_North_Amer
char *proj4src;
CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
std::cout << "\tPROJ4: " << proj4src << std::endl;
// morph it then spew it
myInputSpatialRefSys.morphFromESRI();
myInputSpatialRefSys.exportToProj4(&proj4src);
std::cout << "\tMorphed PROJ4: " << proj4src << std::endl;
CPPUNIT_ASSERT(QString(proj4src).find("datum") > -1);
}
void testOgrTransform()
{
std::cout << "\n\nTesting OGR transform of kodiak.prj to WGS 84 Geographic" << std::endl;
// set up the spatial ref
OGRSpatialReference myInputSpatialRefSys;
char *pWkt = (char*)wktAkAlbers.ascii();
CPPUNIT_ASSERT(myInputSpatialRefSys.importFromWkt(&pWkt)== OGRERR_NONE);
std::cout << "\tGetting proj4 paramters with morph to ESRI form" << std::endl;
CPPUNIT_ASSERT(myInputSpatialRefSys.morphFromESRI() == OGRERR_NONE);
OGRSpatialReference oTargetSRS;
char *pWgs84 = (char *)wkt.ascii();
oTargetSRS.importFromWkt(&pWgs84);
OGRCoordinateTransformation *poCT;
poCT = OGRCreateCoordinateTransformation( &myInputSpatialRefSys,
&oTargetSRS );
double x = 0.0;
double y = 0.0;
poCT->Transform(1, &x, &y);
std::cout << "Transformed 0,0 albers point = " << x << ", " << y << std::endl;
CPPUNIT_ASSERT((x == -154.0) || (y == 50.0));
// get the proj4 for the morphed projection
char *proj4src;
CPPUNIT_ASSERT(myInputSpatialRefSys.exportToProj4(&proj4src) == OGRERR_NONE);
std::cout << "\tPROJ4: " << proj4src << std::endl;
std::cout << "Testing inverse transform" << std::endl;
poCT = OGRCreateCoordinateTransformation( &oTargetSRS, &myInputSpatialRefSys);
x = -154.0;
y = 50.0;
poCT->Transform(1, &x, &y);
CPPUNIT_ASSERT((x == 0) || (y == 0));
std::cout << "Transformed -154,50 geographic point = " << x << ", " << y << std::endl;
}
private:
// WKT for default projection hardcoded in QgsCoordinateTransform class

View File

@ -12,7 +12,8 @@ CONFIG += debug
# get gdal info
GDAL_LIBS = $$system(gdal-config --libs)
GDAL_DEPS = $$system(gdal-config --dep-libs)
LIBS = $$GDAL_LIBS $$GDAL_DEPS -lcppunit -ldl
PG_LIBS = $$system(pg_config --libdir)
LIBS = $$GDAL_LIBS $$GDAL_DEPS -L$$PG_LIBS -lcppunit -ldl
# Input
HEADERS += projectioncshandlingtest.h
SOURCES += main.cpp

4
widgets/Makefile.am Normal file
View File

@ -0,0 +1,4 @@
## Makefile.in generated from automake
SUBDIRS = projectionselector

View File

@ -0,0 +1,51 @@
# Copyright (C) 2005 Tim Sutton <tim at linfiniti.com>
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# $Id$
plugindir = ${pkglibdir}
PKGDATAPATH=-DPKGDATAPATH=\"$(pkgdatadir)\"
%.moc.cpp: %.h
$(MOC) -o $@ $<
%.h: %.ui
$(UIC) -o $@ $<
%.cpp: %.ui
$(UIC) -o $@ -impl $*.h $<
# name of the qgis library widget
plugin_LTLIBRARIES = libqgsprojectionselector.la
plugin_MOC = qgsprojectionselector.moc.cpp \
qgsprojectionselectorbase.moc.cpp
plugin_UI = qgsprojectionselectorbase.h \
qgsprojectionselectorbase.cpp
plugin_UIC = qgsprojectionselectorbase.ui
libqgsprojectionselector_la_SOURCES = qgsprojectionselector.cpp \
$(plugin_UI) \
$(plugin_MOC)
BUILT_SOURCES = $(plugin_MOC) $(plugin_UI)
libqgsprojectionselector_la_LIBADD = ../../src/libqgis.la $(LDADD) $(QT_LDADD) $(GDAL_LDADD) -lsqlite3
libqgsprojectionselector_la_LDFLAGS = -avoid-version
libqgsprojectionselector_la_CXXFLAGS = $(PKGDATAPATH) $(CXXFLAGS) $(GDAL_CFLAGS) $(EXTRA_CXXFLAGS) $(QT_CXXFLAGS) $(DEBUG_QGIS) -I../../src/
EXTRA_DIST = $(plugin_UIC)

View File

@ -0,0 +1,343 @@
/***************************************************************************
* Copyright (C) 2005 by Tim Sutton *
* tim@linfiniti.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
/* $Id$ */
#include "qgsprojectionselector.h"
//standard includes
#include <iostream>
#include <cassert>
#include <sqlite3.h>
//qgis includes
#include "qgscsexception.h"
#include "qgsconfig.h"
//qt includes
#include <qapplication.h>
#include <qfile.h>
#include <qtextedit.h>
#include <qbuttongroup.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qregexp.h>
#include <qprogressdialog.h>
#include <qapplication.h>
//stdc++ includes
#include <iostream>
#include <cstdlib>
//gdal and ogr includes
// XXX DO WE NEED THESE?
#include <ogr_api.h>
#include <ogr_spatialref.h>
#include <cpl_error.h>
// set the default coordinate system
static const char* defaultWktKey = "4326";
QgsProjectionSelector::QgsProjectionSelector( QWidget* parent , const char* name , WFlags fl )
: QgsProjectionSelectorBase( parent, "Projection Selector", fl )
{
// Get the package data path and set the full path name to the sqlite3 spatial reference
// database.
#if defined(Q_OS_MACX) || defined(WIN32)
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
#endif
srsDatabaseFileName = PKGDATAPATH;
srsDatabaseFileName += "/resources/srs.db";
// Populate the projection list view
getProjList();
}
QgsProjectionSelector::~QgsProjectionSelector()
{
}
void QgsProjectionSelector::setSelectedWKT(QString theWKT)
{
//get the srid given the wkt so we can pick the correct list item
#ifdef QGISDEBUG
std::cout << "QgsProjectionSelector::setSelectedWKT called with \n" << theWKT << std::endl;
#endif
//now delegate off to the rest of the work
QListViewItemIterator myIterator (lstCoordinateSystems);
while (myIterator.current())
{
if (myIterator.current()->text(0)==theWKT)
{
lstCoordinateSystems->setCurrentItem(myIterator.current());
lstCoordinateSystems->ensureItemVisible(myIterator.current());
return;
}
++myIterator;
}
}
void QgsProjectionSelector::setSelectedSRID(QString theSRID)
{
QListViewItemIterator myIterator (lstCoordinateSystems);
while (myIterator.current())
{
if (myIterator.current()->text(1)==theSRID)
{
lstCoordinateSystems->setCurrentItem(myIterator.current());
lstCoordinateSystems->ensureItemVisible(myIterator.current());
return;
}
++myIterator;
}
}
//note this line just returns the projection name!
QString QgsProjectionSelector::getSelectedWKT()
{
// return the selected wkt name from the list view
QListViewItem *lvi = lstCoordinateSystems->currentItem();
if(lvi)
{
return lvi->text(0);
}
else
{
return QString::null;
}
}
// Returns the whole wkt for the selected projection node
QString QgsProjectionSelector::getCurrentWKT()
{
// Only return the projection if there is a node in the tree
// selected that has an srid. This prevents error if the user
// selects a top-level node rather than an actual coordinate
// system
//
// Get the selected node
QListViewItem *lvi = lstCoordinateSystems->currentItem();
if(lvi)
{
// Make sure the selected node is a srs and not a top-level projection node
std::cout << lvi->text(1) << std::endl;
if(lvi->text(1).length() > 0)
{
// set up the database
// XXX We could probabaly hold the database open for the life of this object,
// assuming that it will never be used anywhere else. Given the low overhead,
// opening it each time seems to be a reasonable approach at this time.
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open(srsDatabaseFileName, &db);
if(rc)
{
std::cout << "Can't open database: " << sqlite3_errmsg(db) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(rc == 0);
}
// prepare the sql statement
const char *pzTail;
sqlite3_stmt *ppStmt;
char *pzErrmsg;
QString sql = "select srtext from spatial_ref_sys where srid = ";
sql += lvi->text(1);
#ifdef QGISDEBUG
std::cout << "Finding selected wkt using : " << sql << std::endl;
#endif
rc = sqlite3_prepare(db, (const char *)sql, sql.length(), &ppStmt, &pzTail);
// XXX Need to free memory from the error msg if one is set
QString wkt;
if(rc == SQLITE_OK)
{
// get the first row of the result set
if(sqlite3_step(ppStmt) == SQLITE_ROW)
{
// get the wkt
wkt = (char*)sqlite3_column_text(ppStmt, 0);
}
}
// close the statement
sqlite3_finalize(ppStmt);
// close the database
sqlite3_close(db);
// return the srs wkt
return wkt;
}
}
else
{
// No node is selected, return null
return NULL;
}
}
QString QgsProjectionSelector::getCurrentSRID()
{
if(lstCoordinateSystems->currentItem()->text(1).length() > 0)
{
return lstCoordinateSystems->currentItem()->text(1);
}
else
{
return NULL;
}
}
void QgsProjectionSelector::getProjList()
{
// Create the top-level nodes for the list view of projections
//
// Geographic coordinate system node
geoList = new QListViewItem(lstCoordinateSystems,"Geographic Coordinate System");
// Projected coordinate system node
projList = new QListViewItem(lstCoordinateSystems,"Projected Coordinate System");
// open the database containing the spatial reference data
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open(srsDatabaseFileName, &db);
if(rc)
{
std::cout << "Can't open database: " << sqlite3_errmsg(db) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(rc == 0);
}
// prepare the sql statement
const char *pzTail;
sqlite3_stmt *ppStmt;
char *pzErrmsg;
// get total count of records in the projection table
QString sql = "select count(*) from srs_name";
rc = sqlite3_prepare(db, sql, sql.length(), &ppStmt, &pzTail);
assert(rc == SQLITE_OK);
sqlite3_step(ppStmt);
// Set the max for the progress dialog to the number of entries in the srs_name table
int myEntriesCount = sqlite3_column_int(ppStmt, 0);
sqlite3_finalize(ppStmt);
// Set up the query to retreive the projection information needed to populate the list
sql = "select * from srs_name order by name";
rc = sqlite3_prepare(db, (const char *)sql, sql.length(), &ppStmt, &pzTail);
// XXX Need to free memory from the error msg if one is set
if(rc == SQLITE_OK)
{
QListViewItem *newItem;
// set up the progress dialog
int myProgress = 1;
QProgressDialog myProgressBar( "Building Projections List...", 0, myEntriesCount,
this, "progress", TRUE );
// set initial value to 1
myProgressBar.setProgress(myProgress);
while(sqlite3_step(ppStmt) == SQLITE_ROW)
{
// only update the progress dialog every 10 records
if((myProgress++ % 10) == 0)
{
myProgressBar.setProgress(myProgress++);
}
// check to see if the srs is geographic
int isGeo = sqlite3_column_int(ppStmt, 3);
if(isGeo)
{
// this is a geographic coordinate system
// Add it to the tree
newItem = new QListViewItem(geoList, (char *)sqlite3_column_text(ppStmt,1));
// display the spatial reference id in the second column of the list view
newItem->setText(1,(char *)sqlite3_column_text(ppStmt, 0));
}
else
{
// This is a projected srs
QListViewItem *node;
// Fine the node for this type and add the projection to it
// If the node doesn't exist, create it
node = lstCoordinateSystems->findItem(QString((char*)sqlite3_column_text(ppStmt, 2)),0);
if(node == 0)
{
// the node doesn't exist -- create it
node = new QListViewItem(projList, (char*)sqlite3_column_text(ppStmt, 2));
}
// add the item, setting the projection name in the first column of the list view
newItem = new QListViewItem(node, (char *)sqlite3_column_text(ppStmt,1));
// set the srid in the second column on the list view
newItem->setText(1,(char *)sqlite3_column_text(ppStmt, 0));
}
}
// update the progress bar to 100% -- just for eye candy purposes (some people hate to
// see a progress dialog end at 99%)
myProgressBar.setProgress(myEntriesCount);
}
// close the sqlite3 statement
sqlite3_finalize(ppStmt);
// close the database
sqlite3_close(db);
}
// New coordinate system selected from the list
void QgsProjectionSelector::coordinateSystemSelected( QListViewItem * theItem)
{
if(theItem->text(1).length() > 0)
{
sqlite3 *db;
char *zErrMsg = 0;
int rc;
rc = sqlite3_open(srsDatabaseFileName, &db);
if(rc)
{
std::cout << "Can't open database: " << sqlite3_errmsg(db) << std::endl;
// XXX This will likely never happen since on open, sqlite creates the
// database if it does not exist.
assert(rc == 0);
}
// prepare the sql statement
const char *pzTail;
sqlite3_stmt *ppStmt;
char *pzErrmsg;
QString sql = "select srtext from spatial_ref_sys where srid = ";
sql += theItem->text(1);
rc = sqlite3_prepare(db, (const char *)sql, sql.length(), &ppStmt, &pzTail);
// XXX Need to free memory from the error msg if one is set
QString wkt;
if(rc == SQLITE_OK)
{
if(sqlite3_step(ppStmt) == SQLITE_ROW)
{
wkt = (char*)sqlite3_column_text(ppStmt, 0);
}
}
// close the statement
sqlite3_finalize(ppStmt);
// close the database
sqlite3_close(db);
#ifdef QGISDEBUG
std::cout << "Item selected : " << theItem->text(0) << std::endl;
std::cout << "Item selected full wkt : " << wkt << std::endl;
#endif
assert(wkt.length() > 0);
// reformat the wkt to improve the display in the textedit
// box
wkt = wkt.replace(",", ", ");
teProjection->setText(wkt);
// let anybody who's listening know about the change
// XXX Is this appropriate here if the dialog is cancelled??
emit wktSelected(wkt);
}
}

View File

@ -0,0 +1,67 @@
/***************************************************************************
* Copyright (C) 2005 by Tim Sutton *
* tim@linfiniti.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef QGSPROJECTIONSELECTOR_H
#define QGSPROJECTIONSELECTOR_H
#ifdef WIN32
#include "qgsprojectionselectorbase.uic.h"
#else
#include "qgsprojectionselectorbase.h"
#endif
#include <qgis.h>
#include <qstring.h>
#include <qlistview.h>
/**
@author Tim Sutton
*/
class QgsProjectionSelector: public QgsProjectionSelectorBase
{
Q_OBJECT
public:
QgsProjectionSelector( QWidget* parent , const char* name ,WFlags fl =0 );
~QgsProjectionSelector();
//! Populate the wkts map with projection names...
void getProjList();
public slots:
void setSelectedWKT(QString theWKT);
QString getSelectedWKT();
void setSelectedSRID(QString theSRID);
QString getCurrentWKT();
QString getCurrentSRID();
private:
// List view nodes for the tree view of projections
//! GEOGCS node
QListViewItem *geoList;
//! PROJCS node
QListViewItem *projList;
//! Users custom coordinate system file
// XXX This has to change to a sqlite3 database installed in user home dir
QString customCsFile;
//! File name of the sqlite3 database
QString srsDatabaseFileName;
//private handler for when user selects a cs
//it will cause wktSelected and sridSelected events to be spawned
void coordinateSystemSelected(QListViewItem*);
signals:
void wktSelected(QString theWKT);
void sridSelected(QString theSRID);
//! Refresh any listening canvases
void refresh();
};
#endif

View File

@ -0,0 +1,116 @@
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>QgsProjectionSelectorBase</class>
<widget class="QWidget">
<property name="name">
<cstring>QgsProjectionSelectorBase</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>477</height>
</rect>
</property>
<property name="caption">
<string>Projection Selector</string>
</property>
<property name="icon">
<pixmap>image0</pixmap>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QButtonGroup" row="0" column="0">
<property name="name">
<cstring>buttonGroup2</cstring>
</property>
<property name="title">
<string>Projection</string>
</property>
<grid>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QListView" row="1" column="0">
<column>
<property name="text">
<string>Coordinate Systems</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<column>
<property name="text">
<string>Spatial Reference Id</string>
</property>
<property name="clickable">
<bool>true</bool>
</property>
<property name="resizable">
<bool>true</bool>
</property>
</column>
<property name="name">
<cstring>lstCoordinateSystems</cstring>
</property>
<property name="showSortIndicator">
<bool>true</bool>
</property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit" row="2" column="0">
<property name="name">
<cstring>teProjection</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>32767</width>
<height>76</height>
</size>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</grid>
</widget>
</grid>
</widget>
<images>
<image name="image0">
<data format="PNG" length="593">89504e470d0a1a0a0000000d49484452000000100000001008060000001ff3ff610000021849444154388d8d933f6853511487bf4886fb20e00b4478810e062a34e0f092adcfc988430382766bede29f0e5237c716858253079796ec2a594ad3c15a0721298a4fa72ab4f47590c6a1f0de10c8050befa00fae43882135959eed77ef39dfb9f777ef49f9becf79a3fac6332a07510dfc977e0a207daec275cfe00039d011f07db0776154c1c4f891999c3c3217331bc6c96d98d59b55d8571081ea0ce7fe0370dd2393bda479fbbec1b5ca1a4b2bdb142714ca15e880defb0fc0750f8c658584dd5d1a9b01ba23345a01739bdb70a2783056421dabb3019625843f03448420e8f616ef409808d57481fbf34516ee1587007f4d8c4f360c284820164177403d02958362c7e6c97c092b0385717b34a0381113ff8e914400452c1a350612c1f45889acd383abb48c0604fb9a92a35069458c509872c85eb15091e2ee4c1995eea213a1abcf30f146b58ed68224829581cad53caa050b3305f239858880c0e72fe16880effb297f2784a4a7db879a7a2da070d921941050345b21cd7711bedffb8543006fd6338ff75a2cadfb743bc2f4ad0225d7c1b62d0076bf45acad7c456be1d3c7553304a8bcf08c3dd5336c7bff0773cf9a047b5d1697cb44c7402288401881f9f51a918111a9fe30799e6700d46d4083ecf412b69a55caae8d24e064f234b6da3c9c6dd0fc706a98faf7aad63c23d1402f3e9d3595eb59b2399b83c380c67a1b49463c633ff42bc019e8e7cbf554ff74a79b01fc013633ebcd0e2d66c60000000049454e44ae426082</data>
</image>
</images>
<connections>
<connection>
<sender>lstCoordinateSystems</sender>
<signal>currentChanged(QListViewItem*)</signal>
<receiver>QgsProjectionSelectorBase</receiver>
<slot>coordinateSystemSelected(QListViewItem*)</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">qgsprojectionselectorbase.ui.h</include>
</includes>
<slots>
<slot>projectionChanged( const QString &amp; )</slot>
<slot>coordinateSystemSelected( QListViewItem * )</slot>
</slots>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@ -0,0 +1,24 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
void QgsProjectionSelectorBase::projectionChanged( const QString & )
{
}
void QgsProjectionSelectorBase::coordinateSystemSelected( QListViewItem * )
{
}