24 #include <QDomElement>
25 #include <QApplication>
39 , mInitialisedFlag( false )
40 , mSourceProjection( 0 )
41 , mDestinationProjection( 0 )
48 , mInitialisedFlag( false )
49 , mSourceProjection( 0 )
50 , mDestinationProjection( 0 )
60 , mInitialisedFlag( false )
63 , mSourceProjection( 0 )
64 , mDestinationProjection( 0 )
71 , mInitialisedFlag( false )
72 , mSourceProjection( 0 )
73 , mDestinationProjection( 0 )
89 , mInitialisedFlag( false )
90 , mSourceProjection( 0 )
91 , mDestinationProjection( 0 )
163 #ifdef COORDINATE_TRANSFORM_VERBOSE
171 mInitialisedFlag =
false;
175 mInitialisedFlag =
false;
177 #ifdef COORDINATE_TRANSFORM_VERBOSE
178 if ( mInitialisedFlag )
180 QgsDebugMsg(
"------------------------------------------------------------" );
181 QgsDebugMsg(
"The OGR Coordinate transformation for this layer was set to" );
182 QgsLogger::debug<QgsCoordinateReferenceSystem>(
"Input",
mSourceCRS, __FILE__, __FUNCTION__, __LINE__ );
183 QgsLogger::debug<QgsCoordinateReferenceSystem>(
"Output",
mDestCRS, __FILE__, __FUNCTION__, __LINE__ );
184 QgsDebugMsg(
"------------------------------------------------------------" );
188 QgsDebugMsg(
"------------------------------------------------------------" );
189 QgsDebugMsg(
"The OGR Coordinate transformation FAILED TO INITIALISE!" );
190 QgsDebugMsg(
"------------------------------------------------------------" );
193 if ( !mInitialisedFlag )
195 QgsDebugMsg(
"Coordinate transformation failed to initialize!" );
231 double x = thePoint.
x();
232 double y = thePoint.
y();
289 #ifdef COORDINATE_TRANSFORM_VERBOSE
332 int nVertices = poly.size();
334 QVector<double> x( nVertices );
335 QVector<double> y( nVertices );
336 QVector<double> z( nVertices );
338 for (
int i = 0; i < nVertices; ++i )
340 const QPointF& pt = poly.at( i );
357 for (
int i = 0; i < nVertices; ++i )
359 QPointF& pt = poly[i];
366 QVector<double>& x, QVector<double>& y, QVector<double>& z,
372 Q_ASSERT( x.size() == y.size() );
393 TransformDirection direction )
const
395 double xd = (double) x, yd = (
double) y;
404 TransformDirection direction )
const
431 QVector<float>& x, QVector<float>& y, QVector<float>& z,
432 TransformDirection direction )
const
437 Q_ASSERT( x.size() == y.size() );
447 int vectorSize = x.size();
448 QVector<double> xd( x.size() );
449 QVector<double> yd( y.size() );
450 QVector<double> zd( z.size() );
451 for (
int i = 0; i < vectorSize; ++i )
460 for (
int i = 0; i < vectorSize; ++i )
493 static const int numP = 8;
501 double x[numP * numP];
502 double y[numP * numP];
503 double z[numP * numP];
509 double dx = rect.
width() / ( double )( numP - 1 );
510 double dy = rect.
height() / ( double )( numP - 1 );
514 for (
int i = 0; i < numP ; i++ )
520 for (
int j = 0; j < numP; j++ )
522 x[( i*numP ) + j] = pointX;
523 y[( i*numP ) + j] = pointY;
525 z[( i*numP ) + j] = 0.0;
547 for (
int i = 0; i < numP * numP; i++ )
549 if ( qIsFinite( x[i] ) && qIsFinite( y[i] ) )
569 "The coordinates can not be reprojected. The CRS is: %1" )
576 "The coordinates can not be reprojected. The CRS is: %1" ).arg(
mDestCRS.
toProj4() ),
tr(
"CRS" ) );
580 #ifdef COORDINATE_TRANSFORM_VERBOSE
583 QgsDebugMsg( QString(
"[[[[[[ Number of points to transform: %1 ]]]]]]" ).arg( numPoints ) );
593 for (
int i = 0; i < numPoints; ++i )
605 dir =
tr(
"inverse transform" );
612 dir =
tr(
"forward transform" );
615 if ( projResult != 0 )
620 for (
int i = 0; i < numPoints; ++i )
624 points += QString(
"(%1, %2)\n" ).arg( x[i], 0,
'f' ).arg( y[i], 0,
'f' );
628 points += QString(
"(%1, %2)\n" ).arg( x[i] * RAD_TO_DEG, 0,
'f' ).arg( y[i] * RAD_TO_DEG, 0,
'f' );
632 QString msg =
tr(
"%1 of\n"
634 "PROJ.4: %3 +to %4\n"
639 .arg( QString::fromUtf8( pj_strerrno( projResult ) ) );
641 QgsDebugMsg(
"Projection failed emitting invalid transform signal: " + msg );
655 for (
int i = 0; i < numPoints; ++i )
662 #ifdef COORDINATE_TRANSFORM_VERBOSE
663 QgsDebugMsg( QString(
"[[[[[[ Projected %1, %2 to %3, %4 ]]]]]]" )
664 .arg( xorg, 0,
'g', 15 ).arg( yorg, 0,
'g', 15 )
665 .arg( *x, 0,
'g', 15 ).arg( *y, 0,
'g', 15 ) );
672 QgsDebugMsg(
"Reading Coordinate Transform from xml ------------------------!" );
674 QDomNode mySrcNode = theNode.namedItem(
"sourcesrs" );
677 QDomNode myDestNode = theNode.namedItem(
"destinationsrs" );
687 QDomElement myNodeElement = theNode.toElement();
688 QDomElement myTransformElement = theDoc.createElement(
"coordinatetransform" );
690 QDomElement mySourceElement = theDoc.createElement(
"sourcesrs" );
692 myTransformElement.appendChild( mySourceElement );
694 QDomElement myDestElement = theDoc.createElement(
"destinationsrs" );
696 myTransformElement.appendChild( myDestElement );
698 myNodeElement.appendChild( myTransformElement );
707 proj = QApplication::applicationDirPath()
708 +
"/share/proj/" + QString( name );
712 return proj.toUtf8();
A rectangle specified with double values.
const QgsCoordinateReferenceSystem & crsByAuthId(const QString &authid)
Returns the CRS for authid, e.g.
bool isEmpty() const
test if rectangle is empty
void setMinimal()
Set a rectangle so that min corner is at max.
double yMaximum() const
Get the y maximum value (top side of rectangle)
bool createFromId(const long theId, CrsType theType=PostgisCrsId)
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
void combineExtentWith(QgsRectangle *rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
bool createFromSrsId(const long theSrsId)
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
#define QgsDebugMsgLevel(str, level)
A class to represent a point geometry.
static void debug(const QString &msg, int debuglevel=1, const char *file=NULL, const char *function=NULL, int line=-1)
Goes to qDebug.
bool writeXML(QDomNode &theNode, QDomDocument &theDoc) const
Class for storing a coordinate reference system (CRS)
bool createFromWkt(const QString theWkt)
bool readXML(QDomNode &theNode)
Custom exception class for Coordinate Reference System related exceptions.
double width() const
Width of the rectangle.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
double xMinimum() const
Get the x minimum value (left side of rectangle)
static QgsCRSCache * instance()
double height() const
Height of the rectangle.
QString toProj4() const
Get the Proj Proj4 string representation of this srs.