mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-08 00:05:32 -04:00
commit
add0ebcc1e
@ -132,6 +132,7 @@ void QgsRasterProjector::calc()
|
|||||||
{
|
{
|
||||||
QgsDebugMsg( "Entered" );
|
QgsDebugMsg( "Entered" );
|
||||||
mCPMatrix.clear();
|
mCPMatrix.clear();
|
||||||
|
mCPLegalMatrix.clear();
|
||||||
delete[] pHelperTop;
|
delete[] pHelperTop;
|
||||||
pHelperTop = 0;
|
pHelperTop = 0;
|
||||||
delete[] pHelperBottom;
|
delete[] pHelperBottom;
|
||||||
@ -169,6 +170,12 @@ void QgsRasterProjector::calc()
|
|||||||
myRow.append( QgsPoint() );
|
myRow.append( QgsPoint() );
|
||||||
myRow.append( QgsPoint() );
|
myRow.append( QgsPoint() );
|
||||||
mCPMatrix.insert( i, myRow );
|
mCPMatrix.insert( i, myRow );
|
||||||
|
// And the legal points
|
||||||
|
QList<bool> myLegalRow;
|
||||||
|
myLegalRow.append( bool( false ) );
|
||||||
|
myLegalRow.append( bool( false ) );
|
||||||
|
myLegalRow.append( bool( false ) );
|
||||||
|
mCPLegalMatrix.insert( i, myLegalRow );
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < mCPRows; i++ )
|
for ( int i = 0; i < mCPRows; i++ )
|
||||||
{
|
{
|
||||||
@ -238,9 +245,12 @@ void QgsRasterProjector::calcSrcExtent()
|
|||||||
for ( int j = 0; j < mCPCols ; j++ )
|
for ( int j = 0; j < mCPCols ; j++ )
|
||||||
{
|
{
|
||||||
myPoint = mCPMatrix[i][j];
|
myPoint = mCPMatrix[i][j];
|
||||||
|
if ( mCPLegalMatrix[i][j] )
|
||||||
|
{
|
||||||
mSrcExtent.combineExtentWith( myPoint.x(), myPoint.y() );
|
mSrcExtent.combineExtentWith( myPoint.x(), myPoint.y() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Expand a bit to avoid possible approx coords falling out because of representation error?
|
// Expand a bit to avoid possible approx coords falling out because of representation error?
|
||||||
|
|
||||||
// If mMaxSrcXRes, mMaxSrcYRes are defined (fixed src resolution)
|
// If mMaxSrcXRes, mMaxSrcYRes are defined (fixed src resolution)
|
||||||
@ -288,8 +298,15 @@ QString QgsRasterProjector::cpToString()
|
|||||||
if ( j > 0 )
|
if ( j > 0 )
|
||||||
myString += " ";
|
myString += " ";
|
||||||
QgsPoint myPoint = mCPMatrix[i][j];
|
QgsPoint myPoint = mCPMatrix[i][j];
|
||||||
|
if ( mCPLegalMatrix[i][j] )
|
||||||
|
{
|
||||||
myString += myPoint.toString();
|
myString += myPoint.toString();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myString += "(-,-)";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return myString;
|
return myString;
|
||||||
}
|
}
|
||||||
@ -316,6 +333,8 @@ void QgsRasterProjector::calcSrcRowsCols()
|
|||||||
QgsPoint myPointA = mCPMatrix[i][j];
|
QgsPoint myPointA = mCPMatrix[i][j];
|
||||||
QgsPoint myPointB = mCPMatrix[i][j+1];
|
QgsPoint myPointB = mCPMatrix[i][j+1];
|
||||||
QgsPoint myPointC = mCPMatrix[i+1][j];
|
QgsPoint myPointC = mCPMatrix[i+1][j];
|
||||||
|
if ( mCPLegalMatrix[i][j] && mCPLegalMatrix[i][j+1] && mCPLegalMatrix[i+1][j] )
|
||||||
|
{
|
||||||
double mySize = sqrt( myPointA.sqrDist( myPointB ) ) / myDestColsPerMatrixCell;
|
double mySize = sqrt( myPointA.sqrDist( myPointB ) ) / myDestColsPerMatrixCell;
|
||||||
if ( mySize < myMinSize )
|
if ( mySize < myMinSize )
|
||||||
myMinSize = mySize;
|
myMinSize = mySize;
|
||||||
@ -325,6 +344,7 @@ void QgsRasterProjector::calcSrcRowsCols()
|
|||||||
myMinSize = mySize;
|
myMinSize = mySize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Make it a bit higher resolution
|
// Make it a bit higher resolution
|
||||||
// TODO: find the best coefficient, attention, increasing resolution for WMS
|
// TODO: find the best coefficient, attention, increasing resolution for WMS
|
||||||
@ -517,12 +537,15 @@ void QgsRasterProjector::insertRows()
|
|||||||
for ( int r = 0; r < mCPRows - 1; r++ )
|
for ( int r = 0; r < mCPRows - 1; r++ )
|
||||||
{
|
{
|
||||||
QList<QgsPoint> myRow;
|
QList<QgsPoint> myRow;
|
||||||
|
QList<bool> myLegalRow;
|
||||||
for ( int c = 0; c < mCPCols; c++ )
|
for ( int c = 0; c < mCPCols; c++ )
|
||||||
{
|
{
|
||||||
myRow.append( QgsPoint() );
|
myRow.append( QgsPoint() );
|
||||||
|
myLegalRow.append( false );
|
||||||
}
|
}
|
||||||
QgsDebugMsgLevel( QString( "insert new row at %1" ).arg( 1 + r*2 ), 3 );
|
QgsDebugMsgLevel( QString( "insert new row at %1" ).arg( 1 + r*2 ), 3 );
|
||||||
mCPMatrix.insert( 1 + r*2, myRow );
|
mCPMatrix.insert( 1 + r*2, myRow );
|
||||||
|
mCPLegalMatrix.insert( 1 + r*2, myLegalRow );
|
||||||
}
|
}
|
||||||
mCPRows += mCPRows - 1;
|
mCPRows += mCPRows - 1;
|
||||||
for ( int r = 1; r < mCPRows - 1; r += 2 )
|
for ( int r = 1; r < mCPRows - 1; r += 2 )
|
||||||
@ -536,9 +559,11 @@ void QgsRasterProjector::insertCols()
|
|||||||
for ( int r = 0; r < mCPRows; r++ )
|
for ( int r = 0; r < mCPRows; r++ )
|
||||||
{
|
{
|
||||||
QList<QgsPoint> myRow;
|
QList<QgsPoint> myRow;
|
||||||
|
QList<bool> myLegalRow;
|
||||||
for ( int c = 0; c < mCPCols - 1; c++ )
|
for ( int c = 0; c < mCPCols - 1; c++ )
|
||||||
{
|
{
|
||||||
mCPMatrix[r].insert( 1 + c*2, QgsPoint() );
|
mCPMatrix[r].insert( 1 + c*2, QgsPoint() );
|
||||||
|
mCPLegalMatrix[r].insert( 1 + c*2, false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCPCols += mCPCols - 1;
|
mCPCols += mCPCols - 1;
|
||||||
@ -554,8 +579,17 @@ void QgsRasterProjector::calcCP( int theRow, int theCol )
|
|||||||
double myDestX, myDestY;
|
double myDestX, myDestY;
|
||||||
destPointOnCPMatrix( theRow, theCol, &myDestX, &myDestY );
|
destPointOnCPMatrix( theRow, theCol, &myDestX, &myDestY );
|
||||||
QgsPoint myDestPoint( myDestX, myDestY );
|
QgsPoint myDestPoint( myDestX, myDestY );
|
||||||
|
try
|
||||||
|
{
|
||||||
mCPMatrix[theRow][theCol] = mCoordinateTransform.transform( myDestPoint );
|
mCPMatrix[theRow][theCol] = mCoordinateTransform.transform( myDestPoint );
|
||||||
|
mCPLegalMatrix[theRow][theCol] = true;
|
||||||
|
}
|
||||||
|
catch ( QgsCsException &e )
|
||||||
|
{
|
||||||
|
Q_UNUSED( e );
|
||||||
|
// Caught an error in transform
|
||||||
|
mCPLegalMatrix[theRow][theCol] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsRasterProjector::calcRow( int theRow )
|
bool QgsRasterProjector::calcRow( int theRow )
|
||||||
@ -595,6 +629,11 @@ bool QgsRasterProjector::checkCols()
|
|||||||
QgsPoint mySrcPoint3 = mCPMatrix[r+1][c];
|
QgsPoint mySrcPoint3 = mCPMatrix[r+1][c];
|
||||||
|
|
||||||
QgsPoint mySrcApprox(( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, ( mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
|
QgsPoint mySrcApprox(( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, ( mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
|
||||||
|
if ( !mCPLegalMatrix[r-1][c] || !mCPLegalMatrix[r][c] || !mCPLegalMatrix[r+1][c] )
|
||||||
|
{
|
||||||
|
// There was an error earlier in transform, just abort
|
||||||
|
return false;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QgsPoint myDestApprox = mCoordinateTransform.transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
|
QgsPoint myDestApprox = mCoordinateTransform.transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
|
||||||
@ -630,6 +669,11 @@ bool QgsRasterProjector::checkRows()
|
|||||||
QgsPoint mySrcPoint3 = mCPMatrix[r][c+1];
|
QgsPoint mySrcPoint3 = mCPMatrix[r][c+1];
|
||||||
|
|
||||||
QgsPoint mySrcApprox(( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, ( mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
|
QgsPoint mySrcApprox(( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, ( mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
|
||||||
|
if ( !mCPLegalMatrix[r][c-1] || !mCPLegalMatrix[r][c] || !mCPLegalMatrix[r][c+1] )
|
||||||
|
{
|
||||||
|
// There was an error earlier in transform, just abort
|
||||||
|
return false;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QgsPoint myDestApprox = mCoordinateTransform.transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
|
QgsPoint myDestApprox = mCoordinateTransform.transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
|
||||||
|
@ -213,6 +213,10 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
|
|||||||
/** Grid of source control points */
|
/** Grid of source control points */
|
||||||
QList< QList<QgsPoint> > mCPMatrix;
|
QList< QList<QgsPoint> > mCPMatrix;
|
||||||
|
|
||||||
|
/** Grid of source control points transformation possible indicator */
|
||||||
|
/* Same size as mCPMatrix */
|
||||||
|
QList< QList<bool> > mCPLegalMatrix;
|
||||||
|
|
||||||
/** Array of source points for each destination column on top of current CPMatrix grid row */
|
/** Array of source points for each destination column on top of current CPMatrix grid row */
|
||||||
/* Warning: using QList is slow on access */
|
/* Warning: using QList is slow on access */
|
||||||
QgsPoint *pHelperTop;
|
QgsPoint *pHelperTop;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user