[QGIS Commit] r11523 - trunk/qgis/src/plugins/interpolation

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Aug 28 16:32:24 EDT 2009


Author: mhugent
Date: 2009-08-28 16:32:23 -0400 (Fri, 28 Aug 2009)
New Revision: 11523

Modified:
   trunk/qgis/src/plugins/interpolation/qgsgridfilewriter.cpp
   trunk/qgis/src/plugins/interpolation/qgsgridfilewriter.h
   trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.cpp
   trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.h
   trunk/qgis/src/plugins/interpolation/qgsinterpolationdialogbase.ui
Log:
Better options to specify output raster extent and resolution in interpolation plugin

Modified: trunk/qgis/src/plugins/interpolation/qgsgridfilewriter.cpp
===================================================================
--- trunk/qgis/src/plugins/interpolation/qgsgridfilewriter.cpp	2009-08-28 14:49:22 UTC (rev 11522)
+++ trunk/qgis/src/plugins/interpolation/qgsgridfilewriter.cpp	2009-08-28 20:32:23 UTC (rev 11523)
@@ -20,10 +20,10 @@
 #include <QFile>
 #include <QProgressDialog>
 
-QgsGridFileWriter::QgsGridFileWriter( QgsInterpolator* i, QString outputPath, QgsRectangle extent, int nCols, int nRows ): mInterpolator( i ), mOutputFilePath( outputPath ), mInterpolationExtent( extent ), mNumColumns( nCols ), mNumRows( nRows )
+QgsGridFileWriter::QgsGridFileWriter( QgsInterpolator* i, QString outputPath, QgsRectangle extent, int nCols, int nRows , double cellSizeX, double cellSizeY ): \
+    mInterpolator( i ), mOutputFilePath( outputPath ), mInterpolationExtent( extent ), mNumColumns( nCols ), mNumRows( nRows ), mCellSizeX( cellSizeX ), mCellSizeY( cellSizeY )
 {
-  mCellSizeX = ( mInterpolationExtent.xMaximum() - mInterpolationExtent.xMinimum() ) / mNumColumns;
-  mCellSizeY = ( mInterpolationExtent.yMaximum() - mInterpolationExtent.yMinimum() ) / mNumRows;
+
 }
 
 QgsGridFileWriter::QgsGridFileWriter(): mInterpolator( 0 )

Modified: trunk/qgis/src/plugins/interpolation/qgsgridfilewriter.h
===================================================================
--- trunk/qgis/src/plugins/interpolation/qgsgridfilewriter.h	2009-08-28 14:49:22 UTC (rev 11522)
+++ trunk/qgis/src/plugins/interpolation/qgsgridfilewriter.h	2009-08-28 20:32:23 UTC (rev 11523)
@@ -29,7 +29,7 @@
 class QgsGridFileWriter
 {
   public:
-    QgsGridFileWriter( QgsInterpolator* i, QString outputPath, QgsRectangle extent, int nCols, int nRows );
+    QgsGridFileWriter( QgsInterpolator* i, QString outputPath, QgsRectangle extent, int nCols, int nRows, double cellSizeX, double cellSizeY );
     ~QgsGridFileWriter();
 
     /**Writes the grid file.

Modified: trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.cpp
===================================================================
--- trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.cpp	2009-08-28 14:49:22 UTC (rev 11522)
+++ trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.cpp	2009-08-28 20:32:23 UTC (rev 11523)
@@ -22,6 +22,7 @@
 #include "qgsgridfilewriter.h"
 #include "qgsidwinterpolatordialog.h"
 #include "qgstininterpolatordialog.h"
+#include "qgsmapcanvas.h"
 #include "qgsmaplayerregistry.h"
 #include "qgsvectordataprovider.h"
 #include "qgsvectorlayer.h"
@@ -93,6 +94,12 @@
     return;
   }
 
+  QgsRectangle outputBBox = currentBoundingBox();
+  if ( outputBBox.isEmpty() )
+  {
+    return;
+  }
+
   //warn the user if there isn't any input layer
   if ( mLayersTreeWidget->topLevelItemCount() < 1 )
   {
@@ -111,7 +118,6 @@
 
   int nLayers = mLayersTreeWidget->topLevelItemCount();
   QList< QgsInterpolator::LayerData > inputLayerList;
-  QgsRectangle combinedLayerExtent;
 
   for ( int i = 0; i < nLayers; ++i )
   {
@@ -128,17 +134,6 @@
       continue;
     }
 
-    //update extent
-    QgsRectangle currentLayerExtent = theVectorLayer->extent();
-    if ( combinedLayerExtent.isEmpty() )
-    {
-      combinedLayerExtent = currentLayerExtent;
-    }
-    else
-    {
-      combinedLayerExtent.combineExtentWith( &currentLayerExtent );
-    }
-
     QgsInterpolator::LayerData currentLayerData;
     currentLayerData.vectorLayer = theVectorLayer;
 
@@ -189,7 +184,8 @@
   }
 
   //create grid file writer
-  QgsGridFileWriter theWriter( theInterpolator, fileName, combinedLayerExtent, mNumberOfColumnsSpinBox->value(), mNumberOfRowsSpinBox->value() );
+  QgsGridFileWriter theWriter( theInterpolator, fileName, outputBBox, mNumberOfColumnsSpinBox->value(), \
+                               mNumberOfRowsSpinBox->value(), mCellsizeXSpinBox->value(), mCellSizeYSpinBox->value() );
   if ( theWriter.writeFile( true ) == 0 )
   {
     mIface->addRasterLayer( fileName, "Interpolation" );
@@ -273,6 +269,9 @@
   typeComboBox->setCurrentIndex( 0 );
   mLayersTreeWidget->setItemWidget( newLayerItem, 2, typeComboBox );
 
+  //keep bounding box up to date
+  setLayersBoundingBox();
+
   enableOrDisableOkButton();
 }
 
@@ -345,3 +344,218 @@
     mInterpolatorDialog = new QgsTINInterpolatorDialog( 0, mIface );
   }
 }
+
+void QgsInterpolationDialog::on_mNumberOfColumnsSpinBox_valueChanged( int value )
+{
+  setNewCellsizeXOnNColumnsChange();
+}
+
+void QgsInterpolationDialog::on_mNumberOfRowsSpinBox_valueChanged( int value )
+{
+  setNewCellsizeYOnNRowschange();
+}
+
+void QgsInterpolationDialog::on_mCellsizeXSpinBox_valueChanged( double value )
+{
+  setNColsOnCellsizeXChange();
+}
+
+void QgsInterpolationDialog::on_mCellSizeYSpinBox_valueChanged( double value )
+{
+  setNRowsOnCellsizeYChange();
+}
+
+void QgsInterpolationDialog::on_mXMinLineEdit_textEdited( const QString& text )
+{
+  setNewCellsizeOnBoundingBoxChange();
+}
+
+void QgsInterpolationDialog::on_mXMaxLineEdit_textEdited( const QString& text )
+{
+  setNewCellsizeOnBoundingBoxChange();
+}
+
+void QgsInterpolationDialog::on_mYMinLineEdit_textEdited( const QString& text )
+{
+  setNewCellsizeOnBoundingBoxChange();
+}
+
+void QgsInterpolationDialog::on_mYMaxLineEdit_textEdited( const QString& text )
+{
+  setNewCellsizeOnBoundingBoxChange();
+}
+
+void QgsInterpolationDialog::on_mBBoxToCurrentExtent_clicked()
+{
+  if ( mIface )
+  {
+    QgsMapCanvas* canvas = mIface->mapCanvas();
+    if ( canvas )
+    {
+      QgsRectangle extent = canvas->extent();
+      mXMinLineEdit->setText( QString::number( extent.xMinimum() ) );
+      mXMaxLineEdit->setText( QString::number( extent.xMaximum() ) );
+      mYMinLineEdit->setText( QString::number( extent.yMinimum() ) );
+      mYMaxLineEdit->setText( QString::number( extent.yMaximum() ) );
+    }
+  }
+}
+
+QgsRectangle QgsInterpolationDialog::boundingBoxOfLayers()
+{
+  int nLayers = mLayersTreeWidget->topLevelItemCount();
+  QList< QgsInterpolator::LayerData > inputLayerList;
+  QgsRectangle combinedLayerExtent;
+
+  for ( int i = 0; i < nLayers; ++i )
+  {
+    QString layerName = mLayersTreeWidget->topLevelItem( i )->text( 0 );
+    QgsVectorLayer* theVectorLayer = vectorLayerFromName( layerName );
+    if ( !theVectorLayer )
+    {
+      continue;
+    }
+
+    QgsVectorDataProvider* theProvider = theVectorLayer->dataProvider();
+    if ( !theProvider )
+    {
+      continue;
+    }
+
+    //update extent
+    QgsRectangle currentLayerExtent = theVectorLayer->extent();
+    if ( combinedLayerExtent.isEmpty() )
+    {
+      combinedLayerExtent = currentLayerExtent;
+    }
+    else
+    {
+      combinedLayerExtent.combineExtentWith( &currentLayerExtent );
+    }
+  }
+  return combinedLayerExtent;
+}
+
+void QgsInterpolationDialog::setLayersBoundingBox()
+{
+  QgsRectangle layersBoundingBox = boundingBoxOfLayers();
+  mXMinLineEdit->setText( QString::number( layersBoundingBox.xMinimum() ) );
+  mXMaxLineEdit->setText( QString::number( layersBoundingBox.xMaximum() ) );
+  mYMinLineEdit->setText( QString::number( layersBoundingBox.yMinimum() ) );
+  mYMaxLineEdit->setText( QString::number( layersBoundingBox.yMaximum() ) );
+  setNewCellsizeOnBoundingBoxChange();
+}
+
+void QgsInterpolationDialog::setNewCellsizeOnBoundingBoxChange()
+{
+  QgsRectangle currentBbox = currentBoundingBox();
+  if ( currentBbox.isEmpty() )
+  {
+    return;
+  }
+
+  if ( currentBbox.width() > 0 && mNumberOfColumnsSpinBox->value() > 0 )
+  {
+    mCellsizeXSpinBox->blockSignals( true );
+    mCellsizeXSpinBox->setValue( currentBbox.width() / mNumberOfColumnsSpinBox->value() );
+    mCellsizeXSpinBox->blockSignals( false );
+  }
+  if ( currentBbox.height() > 0 && mNumberOfRowsSpinBox->value() > 0 )
+  {
+    mCellSizeYSpinBox->blockSignals( true );
+    mCellSizeYSpinBox->setValue( currentBbox.height() / mNumberOfRowsSpinBox->value() );
+    mCellSizeYSpinBox->blockSignals( false );
+  }
+}
+
+void QgsInterpolationDialog::setNewCellsizeXOnNColumnsChange()
+{
+  QgsRectangle currentBBox = currentBoundingBox();
+  if ( !currentBBox.isEmpty() && mNumberOfColumnsSpinBox->value() > 0 )
+  {
+    mCellsizeXSpinBox->blockSignals( true );
+    mCellsizeXSpinBox->setValue( currentBBox.width() / mNumberOfColumnsSpinBox->value() );
+    mCellsizeXSpinBox->blockSignals( false );
+  }
+}
+
+void QgsInterpolationDialog::setNewCellsizeYOnNRowschange()
+{
+  QgsRectangle currentBBox = currentBoundingBox();
+  if ( !currentBBox.isEmpty() && mNumberOfRowsSpinBox->value() > 0 )
+  {
+    mCellSizeYSpinBox->blockSignals( true );
+    mCellSizeYSpinBox->setValue( currentBBox.height() / mNumberOfRowsSpinBox->value() );
+    mCellSizeYSpinBox->blockSignals( false );
+  }
+}
+
+void QgsInterpolationDialog::setNColsOnCellsizeXChange()
+{
+  QgsRectangle currentBBox = currentBoundingBox();
+  int newSize;
+
+  if ( !mCellsizeXSpinBox->value() > 0 )
+  {
+    return;
+  }
+
+  if ( !currentBBox.width() > 0 )
+  {
+    newSize = 0;
+  }
+  else
+  {
+    newSize = ( int )( currentBBox.width() / mCellsizeXSpinBox->value() );
+  }
+
+  mNumberOfColumnsSpinBox->blockSignals( true );
+  mNumberOfColumnsSpinBox->setValue( newSize );
+  mNumberOfColumnsSpinBox->blockSignals( false );
+}
+
+void QgsInterpolationDialog::setNRowsOnCellsizeYChange()
+{
+  QgsRectangle currentBBox = currentBoundingBox();
+  int newSize;
+
+  if ( !mCellSizeYSpinBox->value() > 0 )
+  {
+    return;
+  }
+
+  if ( !currentBBox.height() > 0 )
+  {
+    newSize = 0;
+  }
+  else
+  {
+    newSize = ( int )( currentBBox.height() / mCellSizeYSpinBox->value() );
+  }
+
+  mNumberOfRowsSpinBox->blockSignals( true );
+  mNumberOfRowsSpinBox->setValue( newSize );
+  mNumberOfRowsSpinBox->blockSignals( false );
+}
+
+QgsRectangle QgsInterpolationDialog::currentBoundingBox()
+{
+  QString xMinString = mXMinLineEdit->text();
+  QString xMaxString = mXMaxLineEdit->text();
+  QString yMinString = mYMinLineEdit->text();
+  QString yMaxString = mYMaxLineEdit->text();
+
+  bool xMinOk, xMaxOk, yMinOk, yMaxOk;
+  double xMin = xMinString.toDouble( &xMinOk );
+  double xMax = xMaxString.toDouble( &xMaxOk );
+  double yMin = yMinString.toDouble( &yMinOk );
+  double yMax = yMaxString.toDouble( &yMaxOk );
+
+  if ( !xMinOk || !xMaxOk || !yMinOk || !yMaxOk )
+  {
+    QgsRectangle emptyBbox;
+    return emptyBbox; //error, return empty bounding box
+  }
+
+  return QgsRectangle( xMin, yMin, xMax, yMax );
+}

Modified: trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.h
===================================================================
--- trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.h	2009-08-28 14:49:22 UTC (rev 11522)
+++ trunk/qgis/src/plugins/interpolation/qgsinterpolationdialog.h	2009-08-28 20:32:23 UTC (rev 11523)
@@ -19,6 +19,7 @@
 #define QGSINTERPOLATIONDIALOG_H
 
 #include "ui_qgsinterpolationdialogbase.h"
+#include "qgsrectangle.h"
 #include "qgisinterface.h"
 #include <QFileInfo>
 
@@ -42,6 +43,19 @@
     void on_mAddPushButton_clicked();
     void on_mRemovePushButton_clicked();
 
+    void on_mNumberOfColumnsSpinBox_valueChanged( int value );
+    void on_mNumberOfRowsSpinBox_valueChanged( int value );
+    void on_mCellsizeXSpinBox_valueChanged( double value );
+    void on_mCellSizeYSpinBox_valueChanged( double value );
+    void on_mBBoxToCurrentExtent_clicked();
+
+    void on_mXMinLineEdit_textEdited( const QString& text );
+    void on_mXMaxLineEdit_textEdited( const QString& text );
+    void on_mYMinLineEdit_textEdited( const QString& text );
+    void on_mYMaxLineEdit_textEdited( const QString& text );
+
+
+
   private:
     QgisInterface* mIface;
     /**Dialog to get input for the current interpolation method*/
@@ -52,6 +66,19 @@
     QgsVectorLayer* vectorLayerFromName( const QString& name );
     /**Enables or disables the Ok button depending on the availability of input layers and the output file*/
     void enableOrDisableOkButton();
+    /**Get the current output bounding box (might be different to the compound layers bounding box because of user edits)
+      @return the bounding box or an empty bounding box in case of error*/
+    QgsRectangle currentBoundingBox();
+    /**Returns the compound bounding box of the inserted layers*/
+    QgsRectangle boundingBoxOfLayers();
+    /**Inserts the compound bounding box of the input layers into the line edits for the output bounding box*/
+    void setLayersBoundingBox();
+    /**Set cellsizes according to nex bounding box and number of columns / rows */
+    void setNewCellsizeOnBoundingBoxChange();
+    void setNewCellsizeXOnNColumnsChange();
+    void setNewCellsizeYOnNRowschange();
+    void setNColsOnCellsizeXChange();
+    void setNRowsOnCellsizeYChange();
 };
 
 #endif

Modified: trunk/qgis/src/plugins/interpolation/qgsinterpolationdialogbase.ui
===================================================================
--- trunk/qgis/src/plugins/interpolation/qgsinterpolationdialogbase.ui	2009-08-28 14:49:22 UTC (rev 11522)
+++ trunk/qgis/src/plugins/interpolation/qgsinterpolationdialogbase.ui	2009-08-28 20:32:23 UTC (rev 11523)
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>538</width>
-    <height>577</height>
+    <height>733</height>
    </rect>
   </property>
   <property name="sizePolicy" >
@@ -18,7 +18,7 @@
   <property name="windowTitle" >
    <string>Interpolation plugin</string>
   </property>
-  <layout class="QGridLayout" name="gridLayout_2" >
+  <layout class="QGridLayout" name="gridLayout_3" >
    <item row="0" column="0" >
     <widget class="QGroupBox" name="mInputGroupBox" >
      <property name="sizePolicy" >
@@ -122,7 +122,7 @@
      <property name="title" >
       <string>Output</string>
      </property>
-     <layout class="QGridLayout" >
+     <layout class="QGridLayout" name="gridLayout_2" >
       <item row="0" column="0" >
        <widget class="QLabel" name="mInterpolationLabel" >
         <property name="text" >
@@ -181,7 +181,111 @@
         </property>
        </widget>
       </item>
-      <item row="3" column="0" >
+      <item row="3" column="0" colspan="3" >
+       <layout class="QHBoxLayout" name="horizontalLayout_3" >
+        <item>
+         <widget class="QLabel" name="mCellsizeXLabel" >
+          <property name="text" >
+           <string>Cellsize X:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QDoubleSpinBox" name="mCellsizeXSpinBox" >
+          <property name="maximum" >
+           <double>999999.000000000000000</double>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLabel" name="mCellsizeYLabel" >
+          <property name="text" >
+           <string>Cellsize Y:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QDoubleSpinBox" name="mCellSizeYSpinBox" >
+          <property name="maximum" >
+           <double>999999.000000000000000</double>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item row="4" column="0" colspan="3" >
+       <layout class="QHBoxLayout" name="horizontalLayout" >
+        <item>
+         <widget class="QLabel" name="mXMinLabel" >
+          <property name="text" >
+           <string>X Min:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="mXMinLineEdit" />
+        </item>
+        <item>
+         <widget class="QLabel" name="mXMaxLabel" >
+          <property name="text" >
+           <string>X Max:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="mXMaxLineEdit" />
+        </item>
+       </layout>
+      </item>
+      <item row="5" column="0" colspan="3" >
+       <layout class="QHBoxLayout" name="horizontalLayout_2" >
+        <item>
+         <widget class="QLabel" name="mYMinLabel" >
+          <property name="text" >
+           <string>Y Min:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="mYMinLineEdit" />
+        </item>
+        <item>
+         <widget class="QLabel" name="mYMaxLabel" >
+          <property name="text" >
+           <string>Y Max:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="mYMaxLineEdit" />
+        </item>
+       </layout>
+      </item>
+      <item row="6" column="0" colspan="3" >
+       <layout class="QHBoxLayout" name="horizontalLayout_4" >
+        <item>
+         <spacer name="horizontalSpacer" >
+          <property name="orientation" >
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0" >
+           <size>
+            <width>298</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item>
+         <widget class="QPushButton" name="mBBoxToCurrentExtent" >
+          <property name="text" >
+           <string>Set to current extent</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item row="7" column="0" >
        <widget class="QLabel" name="mOutputFileLabel" >
         <property name="text" >
          <string>Output file </string>
@@ -191,10 +295,10 @@
         </property>
        </widget>
       </item>
-      <item row="3" column="1" >
+      <item row="7" column="1" >
        <widget class="QLineEdit" name="mOutputFileLineEdit" />
       </item>
-      <item row="3" column="2" >
+      <item row="7" column="2" >
        <widget class="QToolButton" name="mOutputFileButton" >
         <property name="text" >
          <string>...</string>



More information about the QGIS-commit mailing list