[QGIS Commit] r12965 - trunk/qgis/src/plugins/georeferencer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Feb 23 10:17:49 EST 2010


Author: mmassing
Date: 2010-02-23 10:17:48 -0500 (Tue, 23 Feb 2010)
New Revision: 12965

Added:
   trunk/qgis/src/plugins/georeferencer/qgsvalidateddoublespinbox.h
Removed:
   trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.cpp
   trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.h
   trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialogbase.ui
Modified:
   trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
   trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h
   trunk/qgis/src/plugins/georeferencer/qgsimagewarper.cpp
   trunk/qgis/src/plugins/georeferencer/qgsimagewarper.h
   trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialog.cpp
   trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialog.h
   trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialogbase.ui
Log:
Georeferencer: Implement resampling with user-specified target resolution (enhancement request #2447).

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-02-23 15:17:48 UTC (rev 12965)
@@ -264,7 +264,7 @@
   }
 
   d.getTransformSettings(mTransformParam, mResamplingMethod, mCompressionMethod,
-                         mModifiedRasterFileName, mProjection, mUseZeroForTrans, mLoadInQgis);
+                         mModifiedRasterFileName, mProjection, mUseZeroForTrans, mLoadInQgis, mUserResX, mUserResY);
   mTransformParamLabel->setText(tr("Transform: ") + convertTransformEnumToString(mTransformParam));
   mGeorefTransform.selectTransformParametrisation(mTransformParam);
   mGCPListWidget->setGeorefTransform(&mGeorefTransform);
@@ -300,9 +300,12 @@
     QString gdalwarpCommand;
     QString resamplingStr = convertResamplingEnumToString(mResamplingMethod);
     if (QgsGeorefTransform::ThinPlateSpline == mTransformParam)
-      gdalwarpCommand = gdalwarpCommandTPS(resamplingStr, mCompressionMethod, mUseZeroForTrans);
+      gdalwarpCommand = gdalwarpCommandTPS(resamplingStr, mCompressionMethod, mUseZeroForTrans, 
+                                           mUserResX, mUserResY);
     else
-      gdalwarpCommand = gdalwarpCommandGCP(resamplingStr, mCompressionMethod, mUseZeroForTrans, polynomeOrder(mTransformParam));
+      gdalwarpCommand = gdalwarpCommandGCP(resamplingStr, mCompressionMethod, mUseZeroForTrans,
+                                           polynomeOrder(mTransformParam),
+                                           mUserResX, mUserResY);
 
     showGDALScript(2, gdal_translateCommand().toAscii().data(), gdalwarpCommand.toAscii().data());
   }
@@ -1072,7 +1075,7 @@
   {
     QgsImageWarper warper(this);
     int res = warper.warpFile( mRasterFileName, mModifiedRasterFileName, mGeorefTransform,
-                               mResamplingMethod, mUseZeroForTrans, mCompressionMethod, mProjection);
+                               mResamplingMethod, mUseZeroForTrans, mCompressionMethod, mProjection, mUserResX, mUserResY);
     if (res == 0) // fault to compute GCP transform
     {
       //TODO: be more specific in the error message
@@ -1177,23 +1180,37 @@
 }
 
 QString QgsGeorefPluginGui::gdalwarpCommandGCP(QString resampling, QString compress,
-                                               bool useZeroForTrans, int order)
+                                               bool useZeroForTrans, int order,
+                                               double targetResX, double targetResY)
 {
   QStringList gdalCommand;
   gdalCommand << "gdalwarp" << "-r" << resampling << "-order" << QString::number(order)
-      << "-co COMPRESS" << compress << (useZeroForTrans ? "-dstalpha" : "")
-      << mTranslatedRasterFileName << mModifiedRasterFileName;
+      << "-co COMPRESS="+compress << (useZeroForTrans ? "-dstalpha" : "");
 
+  if (targetResX != 0.0 && targetResY != 0.0)
+  {
+    gdalCommand << "-tr" << QString::number(targetResX, 'f') << QString::number(targetResY, 'f');
+  }
+
+  gdalCommand << mTranslatedRasterFileName << mModifiedRasterFileName;
+
   return gdalCommand.join(" ");
 }
 
-QString QgsGeorefPluginGui::gdalwarpCommandTPS(QString resampling, QString compress, bool useZeroForTrans)
+QString QgsGeorefPluginGui::gdalwarpCommandTPS(QString resampling, QString compress, bool useZeroForTrans,
+                                               double targetResX, double targetResY)
 {
   QStringList gdalCommand;
   gdalCommand << "gdalwarp" << "-r" << resampling << "-tps"
-      << "-co COMPRESS" << compress << (useZeroForTrans ? "-dstalpha" : "")
-      << mTranslatedRasterFileName << mModifiedRasterFileName;
+      << "-co COMPRESS="+compress << (useZeroForTrans ? "-dstalpha" : "");
 
+  if (targetResX != 0.0 && targetResY != 0.0)
+  {
+    gdalCommand << "-tr" << QString::number(targetResX, 'f') << QString::number(targetResY, 'f');
+  }
+
+  gdalCommand << mTranslatedRasterFileName << mModifiedRasterFileName;
+
   return gdalCommand.join(" ");
 }
 

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h	2010-02-23 15:17:48 UTC (rev 12965)
@@ -136,9 +136,10 @@
   // gdal script
   void showGDALScript(int argNum...);
   QString gdal_translateCommand(bool generateTFW = true);
-  QString gdalwarpCommandGCP(QString resampling, QString compress, bool useZeroForTrans,
-                             int order);
-  QString gdalwarpCommandTPS(QString resampling, QString compress, bool useZeroForTrans);
+  QString gdalwarpCommandGCP(QString resampling, QString compress, bool useZeroForTrans, int order,
+                             double targetResX, double targetResY);
+  QString gdalwarpCommandTPS(QString resampling, QString compress, bool useZeroForTrans,
+                             double targetResX, double targetResY);
 
   // log
   void showMessageInLog(const QString &description, const QString &msg);
@@ -180,6 +181,7 @@
   QString mTranslatedRasterFileName;
   QString mGCPpointsFileName;
   QString mProjection;
+  double  mUserResX, mUserResY;  // User specified target scale
 
   QgsGeorefTransform::TransformParametrisation mTransformParam;
   QgsImageWarper::ResamplingMethod mResamplingMethod;

Deleted: trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.cpp	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.cpp	2010-02-23 15:17:48 UTC (rev 12965)
@@ -1,68 +0,0 @@
-/***************************************************************************
-     qgsgeorefwarpoptionsdialog.cpp
-     --------------------------------------
-    Date                 : Sun Sep 16 12:03:02 AKDT 2007
-    Copyright            : (C) 2007 by Gary E. Sherman
-    Email                : sherman at mrcc dot 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 "qgsgeorefwarpoptionsdialog.h"
-
-
-QgsGeorefWarpOptionsDialog::QgsGeorefWarpOptionsDialog( QWidget* parent )
-  : QDialog( parent ) //QgsGeorefWarpOptionsDialogBase()
-{
-  setupUi( this );
-
-  textBrowser->setHtml(tr("<p>A %1 transform requires modifications in "
-                          "the raster layer.</p><p>The modified raster will be "
-                          "saved in a new file and a world file will be "
-                          "generated for this new file instead.</p><p>Are you "
-                          "sure that this is what you want?</p>" ).arg("polynomial") +
-                       "<p><i>" + tr( "Currently all modified files will be written in TIFF format." ) +
-                       "</i><p>");
-  adjustSize();
-}
-
-void QgsGeorefWarpOptionsDialog::
-    getWarpOptions( QgsImageWarper::ResamplingMethod& resampling,
-                    bool& useZeroForTransparency, QString& compression )
-{
-  QgsImageWarper::ResamplingMethod methods[] =
-  {
-    QgsImageWarper::NearestNeighbour,
-    QgsImageWarper::Bilinear,
-    QgsImageWarper::Cubic,
-    QgsImageWarper::CubicSpline,
-    QgsImageWarper::Lanczos
-  };
-  resampling = methods[cmbResampling->currentIndex()];
-  useZeroForTransparency = cbxZeroAsTrans->isChecked();
-
-  QString compressionString = mCompressionComboBox->currentText();
-  if ( compressionString.startsWith( "NONE" ) )
-  {
-    compression = "NONE";
-  }
-  else if ( compressionString.startsWith( "LZW" ) )
-  {
-    compression = "LZW";
-  }
-  else if ( compressionString.startsWith( "PACKBITS" ) )
-  {
-    compression = "PACKBITS";
-  }
-  else if ( compressionString.startsWith( "DEFLATE" ) )
-  {
-    compression = "DEFLATE";
-  }
-}
-

Deleted: trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.h	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.h	2010-02-23 15:17:48 UTC (rev 12965)
@@ -1,34 +0,0 @@
-/***************************************************************************
- *   Copyright (C) 2003 by Tim Sutton                                      *
- *   tim at linfiniti.com                                                     *
- *                                                                         *
- *   This is a plugin generated from the QGIS plugin template              *
- *                                                                         *
- *   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 QGSGEOREFWARPOPTIONSDIALOG_H
-#define QGSGEOREFWARPOPTIONSDIALOG_H
-
-#include <cstdio>
-
-#include "qgsimagewarper.h"
-
-#include "ui_qgsgeorefwarpoptionsdialogbase.h"
-#include <QDialog>
-
-class QgsGeorefWarpOptionsDialog : public QDialog, private Ui::QgsGeorefWarpOptionsDialogBase
-{
-  Q_OBJECT
-
-public:
-
-  QgsGeorefWarpOptionsDialog( QWidget* parent );
-  void getWarpOptions( QgsImageWarper::ResamplingMethod& resampling,
-                       bool& useZeroForTransparency, QString& compression );
-};
-
-#endif

Deleted: trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialogbase.ui
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialogbase.ui	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefwarpoptionsdialogbase.ui	2010-02-23 15:17:48 UTC (rev 12965)
@@ -1,158 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>QgsGeorefWarpOptionsDialogBase</class>
- <widget class="QDialog" name="QgsGeorefWarpOptionsDialogBase">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>288</width>
-    <height>319</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>Warp options</string>
-  </property>
-  <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0" colspan="2">
-    <widget class="QTextBrowser" name="textBrowser">
-     <property name="sizePolicy">
-      <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
-       <horstretch>0</horstretch>
-       <verstretch>0</verstretch>
-      </sizepolicy>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="0">
-    <widget class="QLabel" name="textLabel1">
-     <property name="text">
-      <string>Resampling method</string>
-     </property>
-     <property name="buddy">
-      <cstring>cmbResampling</cstring>
-     </property>
-    </widget>
-   </item>
-   <item row="1" column="1">
-    <widget class="QComboBox" name="cmbResampling">
-     <property name="currentIndex">
-      <number>0</number>
-     </property>
-     <item>
-      <property name="text">
-       <string>Nearest neighbour</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>Linear</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>Cubic</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>Cubic Spline</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>Lanczos</string>
-      </property>
-     </item>
-    </widget>
-   </item>
-   <item row="2" column="0">
-    <widget class="QLabel" name="mCompressionLabel">
-     <property name="text">
-      <string>Compression</string>
-     </property>
-     <property name="buddy">
-      <cstring>mCompressionComboBox</cstring>
-     </property>
-    </widget>
-   </item>
-   <item row="2" column="1">
-    <widget class="QComboBox" name="mCompressionComboBox">
-     <item>
-      <property name="text">
-       <string>NONE</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>LZW</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>PACKBITS</string>
-      </property>
-     </item>
-     <item>
-      <property name="text">
-       <string>DEFLATE</string>
-      </property>
-     </item>
-    </widget>
-   </item>
-   <item row="3" column="0" colspan="2">
-    <widget class="QCheckBox" name="cbxZeroAsTrans">
-     <property name="text">
-      <string>Use 0 for transparency when needed</string>
-     </property>
-     <property name="checked">
-      <bool>false</bool>
-     </property>
-    </widget>
-   </item>
-   <item row="4" column="0" colspan="2">
-    <widget class="QDialogButtonBox" name="buttonBox">
-     <property name="standardButtons">
-      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
-     </property>
-    </widget>
-   </item>
-  </layout>
- </widget>
- <layoutdefault spacing="6" margin="11"/>
- <resources/>
- <connections>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>accepted()</signal>
-   <receiver>QgsGeorefWarpOptionsDialogBase</receiver>
-   <slot>accept()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>182</x>
-     <y>105</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>182</x>
-     <y>61</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>buttonBox</sender>
-   <signal>rejected()</signal>
-   <receiver>QgsGeorefWarpOptionsDialogBase</receiver>
-   <slot>reject()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>182</x>
-     <y>105</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>182</x>
-     <y>61</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
-</ui>

Modified: trunk/qgis/src/plugins/georeferencer/qgsimagewarper.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsimagewarper.cpp	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgsimagewarper.cpp	2010-02-23 15:17:48 UTC (rev 12965)
@@ -17,6 +17,7 @@
 #include <cmath>
 #include <iostream>
 #include <cstdio>
+#include <assert.h>
 
 #include <cpl_conv.h>
 #include <cpl_string.h>
@@ -149,7 +150,8 @@
                               ResamplingMethod resampling,
                               bool useZeroAsTrans,
                               const QString& compression,
-                              const QString &projection)
+                              const QString &projection,
+                              double destResX, double destResY)
 {
   if (!georefTransform.parametersInitialized())
     return false;
@@ -174,7 +176,36 @@
     GDALDestroyWarpOptions( psWarpOptions );
     return false;
   }
+  
+  // If specified, override the suggested resolution with user values
+  if (destResX != 0.0 || destResY != 0.0)
+  {
+    // If only one scale has been specified, fill in the other from the GDAL suggestion
+    if (destResX == 0.0) destResX = adfGeoTransform[1];
+    if (destResY == 0.0) destResY = adfGeoTransform[5];
 
+    // Make sure user-specified coordinate system has canonical orientation
+    if (destResX < 0.0) destResX = -destResX;
+    if (destResY > 0.0) destResY = -destResY;
+
+    // Assert that the north-up convention is fullfiled by GDALSuggestedWarpOutput (should always be the case)
+    assert(adfGeoTransform[0] > 0.0);
+    assert(adfGeoTransform[5] < 0.0);
+    // Find suggested output image extent (in georeferenced units)
+    double minX = adfGeoTransform[0];
+    double maxX = adfGeoTransform[0] + adfGeoTransform[1]*destPixels;
+    double maxY = adfGeoTransform[3];
+    double minY = adfGeoTransform[3] + adfGeoTransform[5]*destLines;
+
+    // Update line and pixel count to match extent at user-specified resolution
+    destPixels = (int)(((maxX - minX) / destResX) + 0.5);
+    destLines  = (int)(((minY - maxY) / destResY) + 0.5);
+    adfGeoTransform[0] = minX;
+    adfGeoTransform[3] = maxY;
+    adfGeoTransform[1] = destResX;
+    adfGeoTransform[5] = destResY;
+  }
+
   if (!createDestinationDataset(output, hSrcDS, hDstDS, destPixels, destLines,
                                 adfGeoTransform, useZeroAsTrans, compression,
                                 projection))

Modified: trunk/qgis/src/plugins/georeferencer/qgsimagewarper.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsimagewarper.h	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgsimagewarper.h	2010-02-23 15:17:48 UTC (rev 12965)
@@ -43,13 +43,22 @@
       Lanczos          = GRA_Lanczos
     };
 
+    /**
+     * Warp the file specified by "input" and write the resulting raster to the file "output".
+     * \param georefTransform Specified the warp transformation which should be applied to "input".
+     * \param resampling Specifies image resampling algorithm to use.
+     * \param useZeroAsTrans Specifies whether to mark transparent areas with a value of "zero".
+     * \param destResX The desired horizontal resolution of the output file, in target georeferenced units. A value of zero means automatic selection.
+     * \param destResY The desired vertical resolution of the output file, in target georeferenced units. A value of zero means automatic selection.
+     */
     int warpFile( const QString& input,
                   const QString& output,
                   const QgsGeorefTransform &georefTransform,
                   ResamplingMethod resampling,
                   bool useZeroAsTrans,
                   const QString& compression,
-                  const QString &projection);
+                  const QString& projection,
+                  double destResX = 0.0, double destResY = 0.0);
   private:
     struct TransformChain {
       GDALTransformerFunc GDALTransformer;

Modified: trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialog.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialog.cpp	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialog.cpp	2010-02-23 15:17:48 UTC (rev 12965)
@@ -50,8 +50,22 @@
   cmbResampling->setCurrentIndex(s.value("/Plugin-GeoReferencer/lastresampling", 0).toInt());
   cmbCompressionComboBox->setCurrentIndex(s.value("/Plugin-GeoReferencer/lastcompression", 0).toInt());
   leTargetSRS->setText(s.value("/Plugin-GeoReferencer/targetsrs").toString());
+
+  cbxUserResolution->setChecked(s.value("/Plugin-Georeferencer/user_specified_resolution", false).toBool());
+  bool ok;
+  dsbHorizRes->setValue(s.value("/Plugin-GeoReferencer/user_specified_resx",     1.0).toDouble(&ok));
+  if (!ok) dsbHorizRes->setValue( 1.0);
+  dsbVerticalRes->setValue(s.value("/Plugin-GeoReferencer/user_specified_resy", -1.0).toDouble(&ok));
+  if (!ok) dsbHorizRes->setValue(-1.0);
+  // Activate spin boxes for vertical/horizontal resolution, if the option is checked
+  dsbHorizRes->setEnabled(cbxUserResolution->isChecked());
+  dsbVerticalRes->setEnabled(cbxUserResolution->isChecked());
+  // Update activation of spinboxes, if the user specified resolution is checked/unchecked
+  connect( cbxUserResolution, SIGNAL( toggled( bool ) ), dsbHorizRes, SLOT( setEnabled( bool ) ) );
+  connect( cbxUserResolution, SIGNAL( toggled( bool ) ), dsbVerticalRes, SLOT( setEnabled( bool ) ) );
+
   cbxZeroAsTrans->setChecked(s.value("/Plugin-GeoReferencer/zeroastrans", false).toBool());
-  cbxLoadInQgisWhenDone->setChecked(s.value("/Plugin-GeoReferencer/loadinqgis", false).toBool());;;
+  cbxLoadInQgisWhenDone->setChecked(s.value("/Plugin-GeoReferencer/loadinqgis", false).toBool());
 
   tbnOutputRaster->setIcon(getThemeIcon("/mPushButtonFileOpen.png"));
   tbnTargetSRS->setIcon(getThemeIcon("/mPushButtonTargetSRSDisabled.png"));
@@ -60,7 +74,8 @@
 void QgsTransformSettingsDialog::getTransformSettings(QgsGeorefTransform::TransformParametrisation &tp,
                                                       QgsImageWarper::ResamplingMethod &rm,
                                                       QString &comprMethod, QString &raster,
-                                                      QString &proj, bool &zt, bool &loadInQgis)
+                                                      QString &proj, bool &zt, bool &loadInQgis,
+                                                      double& resX, double& resY)
 {
   if (cmbTransformType->currentIndex() == -1)
     tp = QgsGeorefTransform::InvalidTransform;
@@ -73,6 +88,13 @@
   proj = leTargetSRS->text();
   zt = cbxZeroAsTrans->isChecked();
   loadInQgis = cbxLoadInQgisWhenDone->isChecked();
+  resX = 0.0;
+  resY = 0.0;
+  if (cbxUserResolution->isChecked())
+  {
+    resX = dsbHorizRes->value();
+    resY = dsbVerticalRes->value();
+  }
 }
 
 void QgsTransformSettingsDialog::resetSettings()
@@ -84,6 +106,9 @@
   s.setValue("/Plugin-GeoReferencer/targetsrs", QString());
   s.setValue("/Plugin-GeoReferencer/zeroastrans", false);
   s.setValue("/Plugin-GeoReferencer/loadinqgis", false);
+  s.setValue("/Plugin-GeoReferencer/user_specified_resolution", false);
+  s.setValue("/Plugin-GeoReferencer/user_specified_resx",  1.0);
+  s.setValue("/Plugin-GeoReferencer/user_specified_resy", -1.0);
 }
 
 void QgsTransformSettingsDialog::changeEvent(QEvent *e)
@@ -126,6 +151,9 @@
   s.setValue("/Plugin-GeoReferencer/targetsrs", leTargetSRS->text());
   s.setValue("/Plugin-GeoReferencer/zeroastrans", cbxZeroAsTrans->isChecked());
   s.setValue("/Plugin-GeoReferencer/loadinqgis", cbxLoadInQgisWhenDone->isChecked());
+  s.setValue("/Plugin-GeoReferencer/user_specified_resolution", cbxUserResolution->isChecked());
+  s.setValue("/Plugin-GeoReferencer/user_specified_resx", dsbHorizRes->value());
+  s.setValue("/Plugin-GeoReferencer/user_specified_resy", dsbVerticalRes->value());
 }
 
 void QgsTransformSettingsDialog::on_tbnOutputRaster_clicked()

Modified: trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialog.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialog.h	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialog.h	2010-02-23 15:17:48 UTC (rev 12965)
@@ -32,7 +32,8 @@
                              int countGCPpoints, QWidget *parent = 0);
   void getTransformSettings(QgsGeorefTransform::TransformParametrisation &tp,
                             QgsImageWarper::ResamplingMethod &rm, QString &comprMethod,
-                            QString &raster, QString &proj, bool &zt, bool &loadInQgis);
+                            QString &raster, QString &proj, bool &zt, bool &loadInQgis,
+                            double& resX, double& resY);
   static void resetSettings();
 
 protected:

Modified: trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialogbase.ui
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialogbase.ui	2010-02-23 11:14:39 UTC (rev 12964)
+++ trunk/qgis/src/plugins/georeferencer/qgstransformsettingsdialogbase.ui	2010-02-23 15:17:48 UTC (rev 12965)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>312</width>
-    <height>249</height>
+    <width>307</width>
+    <height>328</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -16,6 +16,9 @@
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <layout class="QFormLayout" name="formLayout">
+     <property name="fieldGrowthPolicy">
+      <enum>QFormLayout::ExpandingFieldsGrow</enum>
+     </property>
      <item row="0" column="0">
       <widget class="QLabel" name="label">
        <property name="text">
@@ -157,6 +160,62 @@
        </item>
       </layout>
      </item>
+     <item row="5" column="0">
+      <widget class="QCheckBox" name="cbxUserResolution">
+       <property name="text">
+        <string>Set Target Resolution</string>
+       </property>
+      </widget>
+     </item>
+     <item row="6" column="0">
+      <widget class="QLabel" name="label_4">
+       <property name="text">
+        <string>Horizontal</string>
+       </property>
+      </widget>
+     </item>
+     <item row="7" column="0">
+      <widget class="QLabel" name="label_5">
+       <property name="text">
+        <string>Vertical</string>
+       </property>
+      </widget>
+     </item>
+     <item row="7" column="1">
+      <widget class="QgsValidatedDoubleSpinBox" name="dsbVerticalRes">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="frame">
+        <bool>true</bool>
+       </property>
+       <property name="decimals">
+        <number>5</number>
+       </property>
+       <property name="minimum">
+        <double>-999999.000000000000000</double>
+       </property>
+       <property name="maximum">
+        <double>0.000000000000000</double>
+       </property>
+      </widget>
+     </item>
+     <item row="6" column="1">
+      <widget class="QgsValidatedDoubleSpinBox" name="dsbHorizRes">
+       <property name="decimals">
+        <number>5</number>
+       </property>
+       <property name="minimum">
+        <double>0.000000000000000</double>
+       </property>
+       <property name="maximum">
+        <double>999999.000000000000000</double>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
    <item>
@@ -188,6 +247,28 @@
    </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>QgsValidatedDoubleSpinBox</class>
+   <extends>QDoubleSpinBox</extends>
+   <header>qgsvalidateddoublespinbox.h</header>
+  </customwidget>
+ </customwidgets>
+ <tabstops>
+  <tabstop>cmbTransformType</tabstop>
+  <tabstop>cmbResampling</tabstop>
+  <tabstop>cmbCompressionComboBox</tabstop>
+  <tabstop>leOutputRaster</tabstop>
+  <tabstop>tbnOutputRaster</tabstop>
+  <tabstop>leTargetSRS</tabstop>
+  <tabstop>tbnTargetSRS</tabstop>
+  <tabstop>cbxUserResolution</tabstop>
+  <tabstop>dsbHorizRes</tabstop>
+  <tabstop>dsbVerticalRes</tabstop>
+  <tabstop>cbxZeroAsTrans</tabstop>
+  <tabstop>cbxLoadInQgisWhenDone</tabstop>
+  <tabstop>buttonBox</tabstop>
+ </tabstops>
  <resources/>
  <connections>
   <connection>

Added: trunk/qgis/src/plugins/georeferencer/qgsvalidateddoublespinbox.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsvalidateddoublespinbox.h	                        (rev 0)
+++ trunk/qgis/src/plugins/georeferencer/qgsvalidateddoublespinbox.h	2010-02-23 15:17:48 UTC (rev 12965)
@@ -0,0 +1,84 @@
+/***************************************************************************
+    qgsvalidateddoublespinbox.h - Simple extension to QDoubleSpinBox which 
+    implements a validate function to disallow zero as input.
+     --------------------------------------
+    Date                 : 23-Feb-2010
+    Copyright            : (c) 2010 by Manuel Massing
+    Email                : m.massing at warped-space.de
+ ***************************************************************************
+ *                                                                         *
+ *   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 QGS_VALIDATED_DOUBLE_SPINBOX_H
+#define QGS_VALIDATED_DOUBLE_SPINBOX_H
+
+#include <QDoubleSpinBox>
+
+class QgsValidatedDoubleSpinBox : public QDoubleSpinBox {
+  public:
+    QgsValidatedDoubleSpinBox(QWidget *widget) : QDoubleSpinBox(widget)  { }
+
+    QValidator::State validate(QString& input, int& pos ) const
+    {
+      QValidator::State state = QDoubleSpinBox::validate(input ,pos);
+      if (state != QValidator::Acceptable)
+      {
+        return state;
+      }
+
+      // A value of zero is acceptable as intermediate result,
+      // but not as final entry
+      double val = valueFromText(input);
+      if (val == 0.0)
+      {
+        return QValidator::Intermediate;
+      }
+      return QValidator::Acceptable;
+    }
+
+    StepEnabled stepEnabled () const
+    {
+      StepEnabled mayStep = StepNone;
+
+      // Zero is off limits, so handle the logic differently
+      // (always exclude zero from the permitted interval)
+      if (minimum() == 0.0) 
+      {
+        if (value() - singleStep() > minimum())
+        {
+          mayStep|= StepDownEnabled;
+        }
+      }
+      else // closed interval
+      {
+        if (value() - singleStep() >= minimum())
+        {
+          mayStep|= StepDownEnabled;
+        }
+      }
+
+      if (maximum() == 0.0)
+      {
+        if (value() + singleStep() < maximum())
+        {
+          mayStep|= StepUpEnabled;
+        }
+      }
+      else
+      {
+        if (value() + singleStep() <= maximum())
+        {
+          mayStep|= StepUpEnabled;
+        }
+      }
+      return mayStep;
+    }
+};
+
+#endif



More information about the QGIS-commit mailing list