Skip to content

Commit 82a1591

Browse files
committedSep 10, 2012
Applied patch 2012-06-27 only
1 parent 5eba984 commit 82a1591

File tree

7 files changed

+147
-36
lines changed

7 files changed

+147
-36
lines changed
 

‎src/plugins/georeferencer/qgsgcplistmodel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ void QgsGCPListModel::updateModel()
7676
return;
7777

7878
bool bTransformUpdated = false;
79-
QgsPoint origin;
8079

8180
vector<QgsPoint> mapCoords, pixelCoords;
8281
mGCPList->createGCPVectors( mapCoords, pixelCoords );
@@ -125,7 +124,7 @@ void QgsGCPListModel::updateModel()
125124
setItem( i, j++, si );
126125
setItem( i, j++, new QgsStandardItem( i ) );
127126
setItem( i, j++, new QgsStandardItem( p->pixelCoords().x() ) );
128-
setItem( i, j++, new QgsStandardItem( -p->pixelCoords().y() ) );
127+
setItem( i, j++, new QgsStandardItem( p->pixelCoords().y() ) );
129128
setItem( i, j++, new QgsStandardItem( p->mapCoords().x() ) );
130129
setItem( i, j++, new QgsStandardItem( p->mapCoords().y() ) );
131130

@@ -136,6 +135,7 @@ void QgsGCPListModel::updateModel()
136135
if ( mGeorefTransform && bTransformUpdated && mGeorefTransform->parametersInitialized() )
137136
{
138137
QgsPoint dst;
138+
QgsPoint pixel = mGeorefTransform->hasCrs() ? mGeorefTransform->toColumnLine( p->pixelCoords() ) : p->pixelCoords();
139139
if ( unitType == tr( "pixels" ) )
140140
{
141141
// Transform from world to raster coordinate:
@@ -144,13 +144,13 @@ void QgsGCPListModel::updateModel()
144144
// interested in the residual in this direction
145145
if ( mGeorefTransform->transformWorldToRaster( p->mapCoords(), dst ) )
146146
{
147-
dX = ( dst.x() - p->pixelCoords().x() );
148-
dY = -( dst.y() - p->pixelCoords().y() );
147+
dX = ( dst.x() - pixel.x() );
148+
dY = -( dst.y() - pixel.y() );
149149
}
150150
}
151151
else if ( unitType == tr( "map units" ) )
152152
{
153-
if ( mGeorefTransform->transformRasterToWorld( p->pixelCoords(), dst ) )
153+
if ( mGeorefTransform->transformRasterToWorld( pixel, dst ) )
154154
{
155155
dX = ( dst.x() - p->mapCoords().x() );
156156
dY = ( dst.y() - p->mapCoords().y() );

‎src/plugins/georeferencer/qgsgcplistwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void QgsGCPListWidget::updateItemCoords( QWidget *editor )
148148
}
149149
else if ( mPrevColumn == 3 ) // srcY
150150
{
151-
newPixelCoords.setY( -value );
151+
newPixelCoords.setY( value );
152152
}
153153
else if ( mPrevColumn == 4 ) // dstX
154154
{

‎src/plugins/georeferencer/qgsgeorefplugingui.cpp

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ void QgsGeorefPluginGui::openRaster()
238238
s.setValue( "/Plugin-GeoReferencer/lastusedfilter", lastUsedFilter );
239239

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

@@ -628,6 +629,23 @@ void QgsGeorefPluginGui::showGeorefConfigDialog()
628629
}
629630
}
630631

632+
// Histogram stretch slots
633+
void QgsGeorefPluginGui::fullHistogramStretch()
634+
{
635+
mLayer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" );
636+
mLayer->setMinimumMaximumUsingDataset();
637+
mLayer->setCacheImage( NULL );
638+
mCanvas->refresh();
639+
}
640+
641+
void QgsGeorefPluginGui::localHistogramStretch()
642+
{
643+
mLayer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" );
644+
mLayer->setMinimumMaximumUsingLastExtent();
645+
mLayer->setCacheImage( NULL );
646+
mCanvas->refresh();
647+
}
648+
631649
// Info slots
632650
void QgsGeorefPluginGui::contextHelp()
633651
{
@@ -673,7 +691,8 @@ void QgsGeorefPluginGui::extentsChangedGeorefCanvas()
673691
}
674692

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

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

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

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

863+
// Histogram stretch
864+
mActionLocalHistogramStretch->setIcon( getThemeIcon( "/mActionLocalHistogramStretch.png" ) );
865+
connect( mActionLocalHistogramStretch, SIGNAL( triggered() ), this, SLOT( localHistogramStretch() ) );
866+
mActionLocalHistogramStretch->setEnabled(false);
867+
868+
mActionFullHistogramStretch->setIcon( getThemeIcon( "/mActionFullHistogramStretch.png" ) );
869+
connect( mActionFullHistogramStretch, SIGNAL( triggered() ), this, SLOT( fullHistogramStretch() ) );
870+
mActionFullHistogramStretch->setEnabled(false);
871+
843872
// Help actions
844873
mActionHelp = new QAction( tr( "Help" ), this );
845874
connect( mActionHelp, SIGNAL( triggered() ), this, SLOT( contextHelp() ) );
@@ -985,32 +1014,35 @@ void QgsGeorefPluginGui::createDockWidgets()
9851014
connect( mGCPListWidget, SIGNAL( pointEnabled( QgsGeorefDataPoint*, int ) ), this, SLOT( updateGeorefTransform() ) );
9861015
}
9871016

988-
void QgsGeorefPluginGui::createStatusBar()
1017+
QLabel* QgsGeorefPluginGui::createBaseLabelStatus()
9891018
{
9901019
QFont myFont( "Arial", 9 );
1020+
QLabel* label = new QLabel( statusBar() );
1021+
label->setFont( myFont );
1022+
label->setMinimumWidth( 10 );
1023+
label->setMaximumHeight( 20 );
1024+
label->setMargin( 3 );
1025+
label->setAlignment( Qt::AlignCenter );
1026+
label->setFrameStyle( QFrame::NoFrame );
1027+
return label;
1028+
}
9911029

992-
mTransformParamLabel = new QLabel( statusBar() );
993-
mTransformParamLabel->setFont( myFont );
994-
mTransformParamLabel->setMinimumWidth( 10 );
995-
mTransformParamLabel->setMaximumHeight( 20 );
996-
mTransformParamLabel->setMargin( 3 );
997-
mTransformParamLabel->setAlignment( Qt::AlignCenter );
998-
mTransformParamLabel->setFrameStyle( QFrame::NoFrame );
1030+
void QgsGeorefPluginGui::createStatusBar()
1031+
{
1032+
mTransformParamLabel = createBaseLabelStatus();
9991033
mTransformParamLabel->setText( tr( "Transform: " ) + convertTransformEnumToString( mTransformParam ) );
10001034
mTransformParamLabel->setToolTip( tr( "Current transform parametrisation" ) );
10011035
statusBar()->addPermanentWidget( mTransformParamLabel, 0 );
10021036

1003-
mCoordsLabel = new QLabel( QString(), statusBar() );
1004-
mCoordsLabel->setFont( myFont );
1005-
mCoordsLabel->setMinimumWidth( 10 );
1006-
mCoordsLabel->setMaximumHeight( 20 );
1037+
mCoordsLabel = createBaseLabelStatus();
10071038
mCoordsLabel->setMaximumWidth( 100 );
1008-
mCoordsLabel->setMargin( 3 );
1009-
mCoordsLabel->setAlignment( Qt::AlignCenter );
1010-
mCoordsLabel->setFrameStyle( QFrame::NoFrame );
10111039
mCoordsLabel->setText( tr( "Coordinate: " ) );
10121040
mCoordsLabel->setToolTip( tr( "Current map coordinate" ) );
10131041
statusBar()->addPermanentWidget( mCoordsLabel, 0 );
1042+
1043+
mEPSG = createBaseLabelStatus();
1044+
mEPSG->setText("EPSG:");
1045+
statusBar()->addPermanentWidget( mEPSG, 0 );
10141046
}
10151047

10161048
void QgsGeorefPluginGui::setupConnections()
@@ -1088,6 +1120,23 @@ void QgsGeorefPluginGui::addRaster( QString file )
10881120
mCanvas->setLayerSet( layers );
10891121

10901122
mAgainAddRaster = false;
1123+
1124+
mActionLocalHistogramStretch->setEnabled(true);
1125+
mActionFullHistogramStretch->setEnabled(true);
1126+
1127+
// Status Bar
1128+
QString sEpsg("ESPG: %1");
1129+
if ( mGeorefTransform.hasCrs() )
1130+
{
1131+
long epsg = mLayer->crs().epsg();
1132+
mEPSG->setText( sEpsg.arg( epsg ) );
1133+
mEPSG->setToolTip( mLayer->crs().toProj4() );
1134+
}
1135+
else
1136+
{
1137+
mEPSG->setText( sEpsg.arg( tr("None") ) );
1138+
mEPSG->setToolTip( tr("Coordinate of image(column/line)") );
1139+
}
10911140
}
10921141

10931142
// Settings
@@ -1894,7 +1943,7 @@ bool QgsGeorefPluginGui::updateGeorefTransform()
18941943
// Samples the given rectangle at numSamples per edge.
18951944
// Returns an axis aligned bounding box which contains the transformed samples.
18961945
QgsRectangle QgsGeorefPluginGui::transformViewportBoundingBox( const QgsRectangle &canvasExtent,
1897-
const QgsGeorefTransform &t,
1946+
QgsGeorefTransform &t,
18981947
bool rasterToWorld, uint numSamples )
18991948
{
19001949
double minX, minY;

‎src/plugins/georeferencer/qgsgeorefplugingui.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
108108
void showMouseCoords( const QgsPoint pt );
109109
void updateMouseCoordinatePrecision();
110110

111+
// Histogram stretch
112+
void localHistogramStretch();
113+
void fullHistogramStretch();
114+
115+
111116
// when one Layer is removed
112117
void layerWillBeRemoved( QString theLayerId );
113118
void extentsChanged(); // Use for need add again Raster (case above)
@@ -131,6 +136,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
131136
void createMapCanvas();
132137
void createMenus();
133138
void createDockWidgets();
139+
QLabel* createBaseLabelStatus();
134140
void createStatusBar();
135141
void setupConnections();
136142
void removeOldLayer();
@@ -165,7 +171,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
165171

166172
// utils
167173
bool checkReadyGeoref();
168-
QgsRectangle transformViewportBoundingBox( const QgsRectangle &canvasExtent, const QgsGeorefTransform &t,
174+
QgsRectangle transformViewportBoundingBox( const QgsRectangle &canvasExtent, QgsGeorefTransform &t,
169175
bool rasterToWorld = true, uint numSamples = 4 );
170176
QString convertTransformEnumToString( QgsGeorefTransform::TransformParametrisation transform );
171177
QString convertResamplingEnumToString( QgsImageWarper::ResamplingMethod resampling );
@@ -202,6 +208,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
202208
QLabel *mScaleLabel;
203209
QLabel *mCoordsLabel;
204210
QLabel *mTransformParamLabel;
211+
QLabel *mEPSG;
205212
unsigned int mMousePrecisionDecimalPlaces;
206213

207214
QString mRasterFileName;

‎src/plugins/georeferencer/qgsgeorefpluginguibase.ui

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>900</width>
10-
<height>800</height>
9+
<width>872</width>
10+
<height>621</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -21,8 +21,8 @@
2121
<rect>
2222
<x>0</x>
2323
<y>0</y>
24-
<width>900</width>
25-
<height>23</height>
24+
<width>872</width>
25+
<height>25</height>
2626
</rect>
2727
</property>
2828
<widget class="QMenu" name="menuFile">
@@ -164,6 +164,19 @@
164164
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
165165
</widget>
166166
</widget>
167+
<widget class="QToolBar" name="toolBarHistogramStretch">
168+
<property name="windowTitle">
169+
<string>toolBar</string>
170+
</property>
171+
<attribute name="toolBarArea">
172+
<enum>TopToolBarArea</enum>
173+
</attribute>
174+
<attribute name="toolBarBreak">
175+
<bool>false</bool>
176+
</attribute>
177+
<addaction name="mActionFullHistogramStretch"/>
178+
<addaction name="mActionLocalHistogramStretch"/>
179+
</widget>
167180
<action name="mActionOpenRaster">
168181
<property name="text">
169182
<string>Open raster</string>
@@ -351,6 +364,16 @@
351364
<string>Zoom Last</string>
352365
</property>
353366
</action>
367+
<action name="mActionLocalHistogramStretch">
368+
<property name="text">
369+
<string>Local histogram stretch</string>
370+
</property>
371+
</action>
372+
<action name="mActionFullHistogramStretch">
373+
<property name="text">
374+
<string>Full histogram stretch</string>
375+
</property>
376+
</action>
354377
</widget>
355378
<resources/>
356379
<connections/>

‎src/plugins/georeferencer/qgsgeoreftransform.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ void QgsGeorefTransform::selectTransformParametrisation( TransformParametrisatio
177177
}
178178
}
179179

180+
void QgsGeorefTransform::setRasterChangeCoords( const QString &fileRaster )
181+
{
182+
mRasterChangeCoords.setRaster( fileRaster );
183+
}
184+
180185
bool QgsGeorefTransform::providesAccurateInverseTransformation() const
181186
{
182187
return ( mTransformParametrisation == Linear
@@ -203,7 +208,17 @@ bool QgsGeorefTransform::updateParametersFromGCPs( const std::vector<QgsPoint> &
203208
{
204209
return false;
205210
}
206-
return mParametersInitialized = mGeorefTransformImplementation->updateParametersFromGCPs( mapCoords, pixelCoords );
211+
if ( mRasterChangeCoords.hasCrs() )
212+
{
213+
std::vector<QgsPoint> pixelCoordsCorrect = mRasterChangeCoords.getPixelCoords(pixelCoords);
214+
mParametersInitialized = mGeorefTransformImplementation->updateParametersFromGCPs( mapCoords, pixelCoordsCorrect );
215+
pixelCoordsCorrect.clear();
216+
}
217+
else
218+
{
219+
mParametersInitialized = mGeorefTransformImplementation->updateParametersFromGCPs( mapCoords, pixelCoords );
220+
}
221+
return mParametersInitialized;
207222
}
208223

209224
uint QgsGeorefTransform::getMinimumGCPCount() const
@@ -248,22 +263,22 @@ QgsGeorefTransformInterface *QgsGeorefTransform::createImplementation( Transform
248263
}
249264
}
250265

251-
bool QgsGeorefTransform::transformRasterToWorld( const QgsPoint &raster, QgsPoint &world ) const
266+
bool QgsGeorefTransform::transformRasterToWorld( const QgsPoint &raster, QgsPoint &world )
252267
{
253268
// flip y coordinate due to different CS orientation
254269
QgsPoint raster_flipped( raster.x(), -raster.y() );
255270
return gdal_transform( raster_flipped, world, 0 );
256271
}
257272

258-
bool QgsGeorefTransform::transformWorldToRaster( const QgsPoint &world, QgsPoint &raster ) const
273+
bool QgsGeorefTransform::transformWorldToRaster( const QgsPoint &world, QgsPoint &raster )
259274
{
260275
bool success = gdal_transform( world, raster, 1 );
261276
// flip y coordinate due to different CS orientation
262277
raster.setY( -raster.y() );
263278
return success;
264279
}
265280

266-
bool QgsGeorefTransform::transform( const QgsPoint &src, QgsPoint &dst, bool rasterToWorld ) const
281+
bool QgsGeorefTransform::transform( const QgsPoint &src, QgsPoint &dst, bool rasterToWorld )
267282
{
268283
return rasterToWorld ? transformRasterToWorld( src, dst ) : transformWorldToRaster( src, dst );
269284
}

‎src/plugins/georeferencer/qgsgeoreftransform.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <vector>
2424
#include <stdexcept>
2525

26+
#include "qgsrasterchangecoords.h"
27+
2628
class QgsGeorefTransformInterface
2729
{
2830
public:
@@ -79,6 +81,20 @@ class QgsGeorefTransform : public QgsGeorefTransformInterface
7981
*/
8082
void selectTransformParametrisation( TransformParametrisation parametrisation );
8183

84+
/**
85+
* Setting the mRasterChangeCoords for change type coordinate(map for pixel).
86+
*/
87+
void setRasterChangeCoords( const QString &fileRaster );
88+
89+
//! \returns Whether has Coordinate Reference Systems in image
90+
bool hasCrs() const { return mRasterChangeCoords.hasCrs(); }
91+
92+
//! \returns Coordinates of image
93+
QgsPoint toColumnLine(const QgsPoint &pntMap) { return mRasterChangeCoords.toColumnLine( pntMap ); }
94+
95+
//! \returns Bounding box of image(transform to coordinate of Map or Image )
96+
QgsRectangle getBoundingBox(const QgsRectangle &rect, bool toPixel) { return mRasterChangeCoords.getBoundingBox( rect, toPixel); }
97+
8298
//! \brief The transform parametrisation currently in use.
8399
TransformParametrisation transformParametrisation() const;
84100

@@ -113,22 +129,22 @@ class QgsGeorefTransform : public QgsGeorefTransformInterface
113129
*
114130
* \note Negative y-axis points down in raster CS.
115131
*/
116-
bool transformRasterToWorld( const QgsPoint &raster, QgsPoint &world ) const;
132+
bool transformRasterToWorld( const QgsPoint &raster, QgsPoint &world );
117133

118134
/**
119135
* \brief Transform from referenced coordinates to raster coordinates.
120136
*
121137
* \note Negative y-axis points down in raster CS.
122138
*/
123-
bool transformWorldToRaster( const QgsPoint &world, QgsPoint &raster ) const;
139+
bool transformWorldToRaster( const QgsPoint &world, QgsPoint &raster );
124140

125141
/**
126142
* \brief Transforms from raster to world if rasterToWorld is true,
127143
* \brief or from world to raster when rasterToWorld is false.
128144
*
129145
* \note Negative y-axis points down in raster CS.
130146
*/
131-
bool transform( const QgsPoint &src, QgsPoint &dst, bool rasterToWorld ) const;
147+
bool transform( const QgsPoint &src, QgsPoint &dst, bool rasterToWorld );
132148

133149
//! \brief Returns origin and scale if this is a linear transform, fails otherwise.
134150
bool getLinearOriginScale( QgsPoint &origin, double &scaleX, double &scaleY ) const;
@@ -149,6 +165,7 @@ class QgsGeorefTransform : public QgsGeorefTransformInterface
149165
QgsGeorefTransformInterface *mGeorefTransformImplementation;
150166
TransformParametrisation mTransformParametrisation;
151167
bool mParametersInitialized;
168+
QgsRasterChangeCoords mRasterChangeCoords;
152169
};
153170

154171
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.