Skip to content

Commit

Permalink
Merge pull request #226 from homann/issue2465_patch
Browse files Browse the repository at this point in the history
Issue2465 patch now included. Question if old pints-file now work directly.
  • Loading branch information
homann committed Sep 10, 2012
2 parents 5eba984 + 83482fe commit 847cae9
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/plugins/georeferencer/CMakeLists.txt
Expand Up @@ -27,6 +27,8 @@ SET (GEOREF_SRCS
qgsimagewarper.cpp
qgsgeoreftransform.cpp
qgsgcplistwidget.cpp

qgsrasterchangecoords.cpp
)

SET (GEOREF_UIS
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/plugins/georeferencer/qgsgcplistmodel.cpp
Expand Up @@ -76,7 +76,6 @@ void QgsGCPListModel::updateModel()
return;

bool bTransformUpdated = false;
QgsPoint origin;

vector<QgsPoint> mapCoords, pixelCoords;
mGCPList->createGCPVectors( mapCoords, pixelCoords );
Expand Down Expand Up @@ -125,7 +124,7 @@ void QgsGCPListModel::updateModel()
setItem( i, j++, si );
setItem( i, j++, new QgsStandardItem( i ) );
setItem( i, j++, new QgsStandardItem( p->pixelCoords().x() ) );
setItem( i, j++, new QgsStandardItem( -p->pixelCoords().y() ) );
setItem( i, j++, new QgsStandardItem( p->pixelCoords().y() ) );
setItem( i, j++, new QgsStandardItem( p->mapCoords().x() ) );
setItem( i, j++, new QgsStandardItem( p->mapCoords().y() ) );

Expand All @@ -136,6 +135,7 @@ void QgsGCPListModel::updateModel()
if ( mGeorefTransform && bTransformUpdated && mGeorefTransform->parametersInitialized() )
{
QgsPoint dst;
QgsPoint pixel = mGeorefTransform->hasCrs() ? mGeorefTransform->toColumnLine( p->pixelCoords() ) : p->pixelCoords();
if ( unitType == tr( "pixels" ) )
{
// Transform from world to raster coordinate:
Expand All @@ -144,13 +144,13 @@ void QgsGCPListModel::updateModel()
// interested in the residual in this direction
if ( mGeorefTransform->transformWorldToRaster( p->mapCoords(), dst ) )
{
dX = ( dst.x() - p->pixelCoords().x() );
dY = -( dst.y() - p->pixelCoords().y() );
dX = ( dst.x() - pixel.x() );
dY = -( dst.y() - pixel.y() );
}
}
else if ( unitType == tr( "map units" ) )
{
if ( mGeorefTransform->transformRasterToWorld( p->pixelCoords(), dst ) )
if ( mGeorefTransform->transformRasterToWorld( pixel, dst ) )
{
dX = ( dst.x() - p->mapCoords().x() );
dY = ( dst.y() - p->mapCoords().y() );
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/georeferencer/qgsgcplistwidget.cpp
Expand Up @@ -148,7 +148,7 @@ void QgsGCPListWidget::updateItemCoords( QWidget *editor )
}
else if ( mPrevColumn == 3 ) // srcY
{
newPixelCoords.setY( -value );
newPixelCoords.setY( value );
}
else if ( mPrevColumn == 4 ) // dstX
{
Expand Down
85 changes: 67 additions & 18 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -238,6 +238,7 @@ void QgsGeorefPluginGui::openRaster()
s.setValue( "/Plugin-GeoReferencer/lastusedfilter", lastUsedFilter );

mGeorefTransform.selectTransformParametrisation( mTransformParam );
mGeorefTransform.setRasterChangeCoords( mRasterFileName );
statusBar()->showMessage( tr( "Raster loaded: %1" ).arg( mRasterFileName ) );
setWindowTitle( tr( "Georeferencer - %1" ).arg( fileInfo.fileName() ) );

Expand Down Expand Up @@ -628,6 +629,23 @@ void QgsGeorefPluginGui::showGeorefConfigDialog()
}
}

// Histogram stretch slots
void QgsGeorefPluginGui::fullHistogramStretch()
{
mLayer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" );
mLayer->setMinimumMaximumUsingDataset();
mLayer->setCacheImage( NULL );
mCanvas->refresh();
}

void QgsGeorefPluginGui::localHistogramStretch()
{
mLayer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" );
mLayer->setMinimumMaximumUsingLastExtent();
mLayer->setCacheImage( NULL );
mCanvas->refresh();
}

// Info slots
void QgsGeorefPluginGui::contextHelp()
{
Expand Down Expand Up @@ -673,7 +691,8 @@ void QgsGeorefPluginGui::extentsChangedGeorefCanvas()
}

// Reproject the georeference plugin canvas into world coordinates and fit axis aligned bounding box
QgsRectangle boundingBox = transformViewportBoundingBox( mCanvas->extent(), mGeorefTransform, true );
QgsRectangle rectMap = mGeorefTransform.hasCrs() ? mGeorefTransform.getBoundingBox( mCanvas->extent(), true ) : mCanvas->extent();
QgsRectangle boundingBox = transformViewportBoundingBox( rectMap, mGeorefTransform, true );

mExtentsChangedRecursionGuard = true;
// Just set the whole extent for now
Expand Down Expand Up @@ -703,11 +722,12 @@ void QgsGeorefPluginGui::extentsChangedQGisCanvas()

// Reproject the canvas into raster coordinates and fit axis aligned bounding box
QgsRectangle boundingBox = transformViewportBoundingBox( mIface->mapCanvas()->extent(), mGeorefTransform, false );
QgsRectangle rectMap = mGeorefTransform.hasCrs() ? mGeorefTransform.getBoundingBox( boundingBox, false ) : boundingBox;

mExtentsChangedRecursionGuard = true;
// Just set the whole extent for now
// TODO: better fitting function which acounts for differing aspect ratios etc.
mCanvas->setExtent( boundingBox );
mCanvas->setExtent( rectMap );
mCanvas->refresh();
mExtentsChangedRecursionGuard = false;
}
Expand Down Expand Up @@ -840,6 +860,15 @@ void QgsGeorefPluginGui::createActions()
mActionGeorefConfig->setIcon( getThemeIcon( "/mActionGeorefConfig.png" ) );
connect( mActionGeorefConfig, SIGNAL( triggered() ), this, SLOT( showGeorefConfigDialog() ) );

// Histogram stretch
mActionLocalHistogramStretch->setIcon( getThemeIcon( "/mActionLocalHistogramStretch.png" ) );
connect( mActionLocalHistogramStretch, SIGNAL( triggered() ), this, SLOT( localHistogramStretch() ) );
mActionLocalHistogramStretch->setEnabled(false);

mActionFullHistogramStretch->setIcon( getThemeIcon( "/mActionFullHistogramStretch.png" ) );
connect( mActionFullHistogramStretch, SIGNAL( triggered() ), this, SLOT( fullHistogramStretch() ) );
mActionFullHistogramStretch->setEnabled(false);

// Help actions
mActionHelp = new QAction( tr( "Help" ), this );
connect( mActionHelp, SIGNAL( triggered() ), this, SLOT( contextHelp() ) );
Expand Down Expand Up @@ -985,32 +1014,35 @@ void QgsGeorefPluginGui::createDockWidgets()
connect( mGCPListWidget, SIGNAL( pointEnabled( QgsGeorefDataPoint*, int ) ), this, SLOT( updateGeorefTransform() ) );
}

void QgsGeorefPluginGui::createStatusBar()
QLabel* QgsGeorefPluginGui::createBaseLabelStatus()
{
QFont myFont( "Arial", 9 );
QLabel* label = new QLabel( statusBar() );
label->setFont( myFont );
label->setMinimumWidth( 10 );
label->setMaximumHeight( 20 );
label->setMargin( 3 );
label->setAlignment( Qt::AlignCenter );
label->setFrameStyle( QFrame::NoFrame );
return label;
}

mTransformParamLabel = new QLabel( statusBar() );
mTransformParamLabel->setFont( myFont );
mTransformParamLabel->setMinimumWidth( 10 );
mTransformParamLabel->setMaximumHeight( 20 );
mTransformParamLabel->setMargin( 3 );
mTransformParamLabel->setAlignment( Qt::AlignCenter );
mTransformParamLabel->setFrameStyle( QFrame::NoFrame );
void QgsGeorefPluginGui::createStatusBar()
{
mTransformParamLabel = createBaseLabelStatus();
mTransformParamLabel->setText( tr( "Transform: " ) + convertTransformEnumToString( mTransformParam ) );
mTransformParamLabel->setToolTip( tr( "Current transform parametrisation" ) );
statusBar()->addPermanentWidget( mTransformParamLabel, 0 );

mCoordsLabel = new QLabel( QString(), statusBar() );
mCoordsLabel->setFont( myFont );
mCoordsLabel->setMinimumWidth( 10 );
mCoordsLabel->setMaximumHeight( 20 );
mCoordsLabel = createBaseLabelStatus();
mCoordsLabel->setMaximumWidth( 100 );
mCoordsLabel->setMargin( 3 );
mCoordsLabel->setAlignment( Qt::AlignCenter );
mCoordsLabel->setFrameStyle( QFrame::NoFrame );
mCoordsLabel->setText( tr( "Coordinate: " ) );
mCoordsLabel->setToolTip( tr( "Current map coordinate" ) );
statusBar()->addPermanentWidget( mCoordsLabel, 0 );

mEPSG = createBaseLabelStatus();
mEPSG->setText("EPSG:");
statusBar()->addPermanentWidget( mEPSG, 0 );
}

void QgsGeorefPluginGui::setupConnections()
Expand Down Expand Up @@ -1088,6 +1120,23 @@ void QgsGeorefPluginGui::addRaster( QString file )
mCanvas->setLayerSet( layers );

mAgainAddRaster = false;

mActionLocalHistogramStretch->setEnabled(true);
mActionFullHistogramStretch->setEnabled(true);

// Status Bar
QString sEpsg("ESPG: %1");
if ( mGeorefTransform.hasCrs() )
{
long epsg = mLayer->crs().epsg();
mEPSG->setText( sEpsg.arg( epsg ) );
mEPSG->setToolTip( mLayer->crs().toProj4() );
}
else
{
mEPSG->setText( sEpsg.arg( tr("None") ) );
mEPSG->setToolTip( tr("Coordinate of image(column/line)") );
}
}

// Settings
Expand Down Expand Up @@ -1894,7 +1943,7 @@ bool QgsGeorefPluginGui::updateGeorefTransform()
// Samples the given rectangle at numSamples per edge.
// Returns an axis aligned bounding box which contains the transformed samples.
QgsRectangle QgsGeorefPluginGui::transformViewportBoundingBox( const QgsRectangle &canvasExtent,
const QgsGeorefTransform &t,
QgsGeorefTransform &t,
bool rasterToWorld, uint numSamples )
{
double minX, minY;
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/georeferencer/qgsgeorefplugingui.h
Expand Up @@ -108,6 +108,11 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
void showMouseCoords( const QgsPoint pt );
void updateMouseCoordinatePrecision();

// Histogram stretch
void localHistogramStretch();
void fullHistogramStretch();


// when one Layer is removed
void layerWillBeRemoved( QString theLayerId );
void extentsChanged(); // Use for need add again Raster (case above)
Expand All @@ -131,6 +136,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
void createMapCanvas();
void createMenus();
void createDockWidgets();
QLabel* createBaseLabelStatus();
void createStatusBar();
void setupConnections();
void removeOldLayer();
Expand Down Expand Up @@ -165,7 +171,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas

// utils
bool checkReadyGeoref();
QgsRectangle transformViewportBoundingBox( const QgsRectangle &canvasExtent, const QgsGeorefTransform &t,
QgsRectangle transformViewportBoundingBox( const QgsRectangle &canvasExtent, QgsGeorefTransform &t,
bool rasterToWorld = true, uint numSamples = 4 );
QString convertTransformEnumToString( QgsGeorefTransform::TransformParametrisation transform );
QString convertResamplingEnumToString( QgsImageWarper::ResamplingMethod resampling );
Expand Down Expand Up @@ -202,6 +208,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
QLabel *mScaleLabel;
QLabel *mCoordsLabel;
QLabel *mTransformParamLabel;
QLabel *mEPSG;
unsigned int mMousePrecisionDecimalPlaces;

QString mRasterFileName;
Expand Down
31 changes: 27 additions & 4 deletions src/plugins/georeferencer/qgsgeorefpluginguibase.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>900</width>
<height>800</height>
<width>872</width>
<height>621</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -21,8 +21,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>900</width>
<height>23</height>
<width>872</width>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down Expand Up @@ -164,6 +164,19 @@
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
</widget>
</widget>
<widget class="QToolBar" name="toolBarHistogramStretch">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionFullHistogramStretch"/>
<addaction name="mActionLocalHistogramStretch"/>
</widget>
<action name="mActionOpenRaster">
<property name="text">
<string>Open raster</string>
Expand Down Expand Up @@ -351,6 +364,16 @@
<string>Zoom Last</string>
</property>
</action>
<action name="mActionLocalHistogramStretch">
<property name="text">
<string>Local histogram stretch</string>
</property>
</action>
<action name="mActionFullHistogramStretch">
<property name="text">
<string>Full histogram stretch</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down
23 changes: 19 additions & 4 deletions src/plugins/georeferencer/qgsgeoreftransform.cpp
Expand Up @@ -177,6 +177,11 @@ void QgsGeorefTransform::selectTransformParametrisation( TransformParametrisatio
}
}

void QgsGeorefTransform::setRasterChangeCoords( const QString &fileRaster )
{
mRasterChangeCoords.setRaster( fileRaster );
}

bool QgsGeorefTransform::providesAccurateInverseTransformation() const
{
return ( mTransformParametrisation == Linear
Expand All @@ -203,7 +208,17 @@ bool QgsGeorefTransform::updateParametersFromGCPs( const std::vector<QgsPoint> &
{
return false;
}
return mParametersInitialized = mGeorefTransformImplementation->updateParametersFromGCPs( mapCoords, pixelCoords );
if ( mRasterChangeCoords.hasCrs() )
{
std::vector<QgsPoint> pixelCoordsCorrect = mRasterChangeCoords.getPixelCoords(pixelCoords);
mParametersInitialized = mGeorefTransformImplementation->updateParametersFromGCPs( mapCoords, pixelCoordsCorrect );
pixelCoordsCorrect.clear();
}
else
{
mParametersInitialized = mGeorefTransformImplementation->updateParametersFromGCPs( mapCoords, pixelCoords );
}
return mParametersInitialized;
}

uint QgsGeorefTransform::getMinimumGCPCount() const
Expand Down Expand Up @@ -248,22 +263,22 @@ QgsGeorefTransformInterface *QgsGeorefTransform::createImplementation( Transform
}
}

bool QgsGeorefTransform::transformRasterToWorld( const QgsPoint &raster, QgsPoint &world ) const
bool QgsGeorefTransform::transformRasterToWorld( const QgsPoint &raster, QgsPoint &world )
{
// flip y coordinate due to different CS orientation
QgsPoint raster_flipped( raster.x(), -raster.y() );
return gdal_transform( raster_flipped, world, 0 );
}

bool QgsGeorefTransform::transformWorldToRaster( const QgsPoint &world, QgsPoint &raster ) const
bool QgsGeorefTransform::transformWorldToRaster( const QgsPoint &world, QgsPoint &raster )
{
bool success = gdal_transform( world, raster, 1 );
// flip y coordinate due to different CS orientation
raster.setY( -raster.y() );
return success;
}

bool QgsGeorefTransform::transform( const QgsPoint &src, QgsPoint &dst, bool rasterToWorld ) const
bool QgsGeorefTransform::transform( const QgsPoint &src, QgsPoint &dst, bool rasterToWorld )
{
return rasterToWorld ? transformRasterToWorld( src, dst ) : transformWorldToRaster( src, dst );
}
Expand Down

0 comments on commit 847cae9

Please sign in to comment.