[QGIS Commit] r11558 - in trunk/qgis/src: analysis analysis/raster plugins/raster_terrain_analysis

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Sep 5 05:59:26 EDT 2009


Author: mhugent
Date: 2009-09-05 05:59:26 -0400 (Sat, 05 Sep 2009)
New Revision: 11558

Added:
   trunk/qgis/src/analysis/raster/
   trunk/qgis/src/analysis/raster/qgsaspectfilter.cpp
   trunk/qgis/src/analysis/raster/qgsaspectfilter.h
   trunk/qgis/src/analysis/raster/qgsderivativefilter.cpp
   trunk/qgis/src/analysis/raster/qgsderivativefilter.h
   trunk/qgis/src/analysis/raster/qgsninecellfilter.cpp
   trunk/qgis/src/analysis/raster/qgsninecellfilter.h
   trunk/qgis/src/analysis/raster/qgsruggednessfilter.cpp
   trunk/qgis/src/analysis/raster/qgsruggednessfilter.h
   trunk/qgis/src/analysis/raster/qgsslopefilter.cpp
   trunk/qgis/src/analysis/raster/qgsslopefilter.h
   trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.cpp
   trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.h
Removed:
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.cpp
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.h
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.cpp
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.h
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.cpp
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.h
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.cpp
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.h
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.cpp
   trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.h
   trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.cpp
   trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.h
Modified:
   trunk/qgis/src/analysis/CMakeLists.txt
   trunk/qgis/src/plugins/raster_terrain_analysis/CMakeLists.txt
Log:
Moved non-gui related raster terrain classes to analysis branch

Modified: trunk/qgis/src/analysis/CMakeLists.txt
===================================================================
--- trunk/qgis/src/analysis/CMakeLists.txt	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/analysis/CMakeLists.txt	2009-09-05 09:59:26 UTC (rev 11558)
@@ -18,6 +18,12 @@
   interpolation/TriangleInterpolator.cc
   interpolation/Triangulation.cc
   interpolation/Vector3D.cc
+  raster/qgsninecellfilter.cpp
+  raster/qgsruggednessfilter.cpp
+  raster/qgsderivativefilter.cpp
+  raster/qgsslopefilter.cpp
+  raster/qgsaspectfilter.cpp
+  raster/qgstotalcurvaturefilter.cpp
   vector/qgsgeometryanalyzer.cpp
 )
 

Copied: trunk/qgis/src/analysis/raster/qgsaspectfilter.cpp (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.cpp)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsaspectfilter.cpp	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsaspectfilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,50 @@
+/***************************************************************************
+                          qgsaspectfilter.cpp  -  description
+                          -----------------------------------
+    begin                : August 7th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "qgsaspectfilter.h"
+
+QgsAspectFilter::QgsAspectFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ) :
+    QgsDerivativeFilter( inputFile, outputFile, outputFormat )
+{
+
+}
+
+QgsAspectFilter::~QgsAspectFilter()
+{
+
+}
+
+float QgsAspectFilter::processNineCellWindow(
+  float* x11, float* x21, float* x31,
+  float* x12, float* x22, float* x32,
+  float* x13, float* x23, float* x33 )
+{
+  float derX = calcFirstDerX( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
+  float derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
+
+  if ( derX == mOutputNodataValue ||
+       derY == mOutputNodataValue ||
+       ( derX == 0.0 && derY == 0.0 ) )
+  {
+    return mOutputNodataValue;
+  }
+  else
+  {
+    return 180.0 + atan2( derX, derY ) * 180.0 / M_PI;
+  }
+}
+


Property changes on: trunk/qgis/src/analysis/raster/qgsaspectfilter.cpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgsaspectfilter.h (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.h)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsaspectfilter.h	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsaspectfilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,38 @@
+/***************************************************************************
+                          qgsaspectfilter.h  -  description
+                          ---------------------------------
+    begin                : August 7th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef QGSASPECTFILTER_H
+#define QGSASPECTFILTER_H
+
+#include "qgsderivativefilter.h"
+
+/**Calculates aspect values in a window of 3x3 cells based on first order derivatives in x- and y- directions. Direction is clockwise starting from north*/
+class QgsAspectFilter: public QgsDerivativeFilter
+{
+  public:
+    QgsAspectFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
+    ~QgsAspectFilter();
+
+  protected:
+  protected:
+    /**Calculates output value from nine input values. The input values and the output value can be equal to the \
+      nodata value if not present or outside of the border. Must be implemented by subclasses*/
+    float processNineCellWindow( float* x11, float* x21, float* x31, \
+                                 float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
+};
+
+#endif // QGSASPECTFILTER_H


Property changes on: trunk/qgis/src/analysis/raster/qgsaspectfilter.h
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgsderivativefilter.cpp (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.cpp)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsderivativefilter.cpp	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsderivativefilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,168 @@
+/***************************************************************************
+                          qgsderivativefilter.cpp  -  description
+                          -----------------------
+    begin                : August 7th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "qgsderivativefilter.h"
+
+QgsDerivativeFilter::QgsDerivativeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
+    QgsNineCellFilter( inputFile, outputFile, outputFormat )
+{
+
+}
+
+QgsDerivativeFilter::~QgsDerivativeFilter()
+{
+
+}
+
+float QgsDerivativeFilter::calcFirstDerX( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
+{
+  //the basic formula would be simple, but we need to test for nodata values...
+  //return (( (*x31 - *x11) + 2 * (*x32 - *x12) + (*x33 - *x13) ) / (8 * mCellSizeX));
+
+  int weight = 0;
+  double sum = 0;
+
+  //first row
+  if ( *x31 != mInputNodataValue && *x11 != mInputNodataValue ) //the normal case
+  {
+    sum += ( *x31 - *x11 );
+    weight += 2;
+  }
+  else if ( *x31 == mInputNodataValue && *x11 != mInputNodataValue && *x21 != mInputNodataValue ) //probably 3x3 window is at the border
+  {
+    sum += ( *x21 - *x11 );
+    weight += 1;
+  }
+  else if ( *x11 == mInputNodataValue && *x31 != mInputNodataValue && *x21 != mInputNodataValue ) //probably 3x3 window is at the border
+  {
+    sum += ( *x31 - *x21 );
+    weight += 1;
+  }
+
+  //second row
+  if ( *x32 != mInputNodataValue && *x12 != mInputNodataValue ) //the normal case
+  {
+    sum += 2 * ( *x32 - *x12 );
+    weight += 4;
+  }
+  else if ( *x32 == mInputNodataValue && *x12 != mInputNodataValue && *x22 != mInputNodataValue )
+  {
+    sum += 2 * ( *x22 - *x12 );
+    weight += 2;
+  }
+  else if ( *x12 == mInputNodataValue && *x32 != mInputNodataValue && *x22 != mInputNodataValue )
+  {
+    sum += 2 * ( *x32 - *x22 );
+    weight += 2;
+  }
+
+  //third row
+  if ( *x33 != mInputNodataValue && *x13 != mInputNodataValue ) //the normal case
+  {
+    sum += ( *x33 - *x13 );
+    weight += 2;
+  }
+  else if ( *x33 == mInputNodataValue && *x13 != mInputNodataValue && *x23 != mInputNodataValue )
+  {
+    sum += ( *x23 - *x13 );
+    weight += 1;
+  }
+  else if ( *x13 == mInputNodataValue && *x33 != mInputNodataValue && *x23 != mInputNodataValue )
+  {
+    sum += ( *x33 - *x23 );
+    weight += 1;
+  }
+
+  if ( weight == 0 )
+  {
+    return mOutputNodataValue;
+  }
+
+  return sum / ( weight * mCellSizeX );
+}
+
+float QgsDerivativeFilter::calcFirstDerY( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
+{
+  //the basic formula would be simple, but we need to test for nodata values...
+  //return (((*x11 - *x13) + 2 * (*x21 - *x23) + (*x31 - *x33)) / ( 8 * mCellSizeY));
+
+  double sum = 0;
+  int weight = 0;
+
+  //first row
+  if ( *x11 != mInputNodataValue && *x13 != mInputNodataValue ) //normal case
+  {
+    sum += ( *x11 - *x13 );
+    weight += 2;
+  }
+  else if ( *x11 == mInputNodataValue && *x13 != mInputNodataValue && *x12 != mInputNodataValue )
+  {
+    sum += ( *x12 - *x13 );
+    weight += 1;
+  }
+  else if ( *x31 == mInputNodataValue && *x11 != mInputNodataValue && *x12 != mInputNodataValue )
+  {
+    sum += ( *x11 - *x12 );
+    weight += 1;
+  }
+
+  //second row
+  if ( *x21 != mInputNodataValue && *x23 != mInputNodataValue )
+  {
+    sum += 2 * ( *x21 - *x23 );
+    weight += 4;
+  }
+  else if ( *x21 == mInputNodataValue && *x23 != mInputNodataValue && *x22 != mInputNodataValue )
+  {
+    sum += 2 * ( *x22 - *x23 );
+    weight += 2;
+  }
+  else if ( *x23 == mInputNodataValue && *x21 != mInputNodataValue && *x22 != mInputNodataValue )
+  {
+    sum += 2 * ( *x21 - *x22 );
+    weight += 2;
+  }
+
+  //third row
+  if ( *x31 != mInputNodataValue && *x33 != mInputNodataValue )
+  {
+    sum += ( *x31 - *x33 );
+    weight += 2;
+  }
+  else if ( *x31 == mInputNodataValue && *x33 != mInputNodataValue && *x32 != mInputNodataValue )
+  {
+    sum += ( *x32 - *x33 );
+    weight += 1;
+  }
+  else if ( *x33 == mInputNodataValue && *x31 != mInputNodataValue && *x32 != mInputNodataValue )
+  {
+    sum += ( *x31 - *x32 );
+    weight += 1;
+  }
+
+  if ( weight == 0 )
+  {
+    return mOutputNodataValue;
+  }
+
+  return sum / ( weight * mCellSizeY );
+}
+
+
+
+
+


Property changes on: trunk/qgis/src/analysis/raster/qgsderivativefilter.cpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgsderivativefilter.h (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.h)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsderivativefilter.h	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsderivativefilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,40 @@
+/***************************************************************************
+                          qgsderivativefilter.h  -  description
+                          ---------------------
+    begin                : August 7th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef QGSDERIVATIVEFILTER_H
+#define QGSDERIVATIVEFILTER_H
+
+#include "qgsninecellfilter.h"
+
+/**Adds the ability to calculate derivatives in x- and y-directions. Needs to be subclassed (e.g. for slope and aspect)*/
+class QgsDerivativeFilter: public QgsNineCellFilter
+{
+  public:
+    QgsDerivativeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
+    virtual ~QgsDerivativeFilter();
+    //to be implemented by subclasses
+    virtual float processNineCellWindow( float* x11, float* x21, float* x31, float* x12, float* x22, \
+                                         float* x32, float* x13, float* x23, float* x33 ) = 0;
+
+  protected:
+    /**Calculates the first order derivative in x-direction according to Horn (1981)*/
+    float calcFirstDerX( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
+    /**Calculates the first order derivative in y-direction according to Horn (1981)*/
+    float calcFirstDerY( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
+};
+
+#endif // QGSDERIVATIVEFILTER_H


Property changes on: trunk/qgis/src/analysis/raster/qgsderivativefilter.h
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgsninecellfilter.cpp (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.cpp)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsninecellfilter.cpp	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsninecellfilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,275 @@
+/***************************************************************************
+                          qgsninecellfilter.h  -  description
+                             -------------------
+    begin                : August 6th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "qgsninecellfilter.h"
+#include "cpl_string.h"
+#include <QProgressDialog>
+
+
+QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
+    mInputFile( inputFile ), mOutputFile( outputFile ), mOutputFormat( outputFormat ), mCellSizeX( -1 ), mCellSizeY( -1 ), mInputNodataValue( -1 ), mOutputNodataValue( -1 )
+{
+
+}
+
+QgsNineCellFilter::QgsNineCellFilter()
+{
+
+}
+
+QgsNineCellFilter::~QgsNineCellFilter()
+{
+
+}
+
+int QgsNineCellFilter::processRaster( QProgressDialog* p )
+{
+  GDALAllRegister();
+
+  //open input file
+  int xSize, ySize;
+  GDALDatasetH  inputDataset = openInputFile( xSize, ySize );
+  if ( inputDataset == NULL )
+  {
+    return 1; //opening of input file failed
+  }
+
+  //output driver
+  GDALDriverH outputDriver = openOutputDriver();
+  if ( outputDriver == 0 )
+  {
+    return 2;
+  }
+
+  GDALDatasetH outputDataset = openOutputFile( inputDataset, outputDriver );
+  if ( outputDataset == NULL )
+  {
+    return 3; //create operation on output file failed
+  }
+
+  //open first raster band for reading (operation is only for single band raster)
+  GDALRasterBandH rasterBand = GDALGetRasterBand( inputDataset, 1 );
+  if ( rasterBand == NULL )
+  {
+    GDALClose( inputDataset );
+    GDALClose( outputDataset );
+    return 4;
+  }
+  mInputNodataValue = GDALGetRasterNoDataValue( rasterBand, NULL );
+
+  GDALRasterBandH outputRasterBand = GDALGetRasterBand( outputDataset, 1 );
+  if ( outputRasterBand == NULL )
+  {
+    GDALClose( inputDataset );
+    GDALClose( outputDataset );
+    return 5;
+  }
+  //try to set -9999 as nodata value
+  GDALSetRasterNoDataValue( outputRasterBand, -9999 );
+  mOutputNodataValue = GDALGetRasterNoDataValue( outputRasterBand, NULL );
+
+  if ( ySize < 3 ) //we require at least three rows (should be true for most datasets)
+  {
+    GDALClose( inputDataset );
+    GDALClose( outputDataset );
+    return 6;
+  }
+
+  //keep only three scanlines in memory at a time
+  float* scanLine1 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
+  float* scanLine2 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
+  float* scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
+
+  float* resultLine = ( float * ) CPLMalloc( sizeof( float ) * xSize );
+
+  if ( p )
+  {
+    p->setMaximum( ySize );
+  }
+
+  //values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
+  for ( int i = 0; i < ySize; ++i )
+  {
+    if ( p )
+    {
+      p->setValue( i );
+    }
+
+    if ( p && p->wasCanceled() )
+    {
+      break;
+    }
+
+    if ( i == 0 )
+    {
+      //fill scanline 1 with (input) nodata for the values above the first row and feed scanline2 with the first row
+      for ( int a = 0; a < xSize; ++a )
+      {
+        scanLine1[a] = mInputNodataValue;
+      }
+      GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 );
+    }
+    else
+    {
+      //normally fetch only scanLine3 and release scanline 1 if we move forward one row
+      CPLFree( scanLine1 );
+      scanLine1 = scanLine2;
+      scanLine2 = scanLine3;
+      scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
+    }
+
+    if ( i == ySize - 1 ) //fill the row below the bottom with nodata values
+    {
+      for ( int a = 0; a < xSize; ++a )
+      {
+        scanLine3[a] = mInputNodataValue;
+      }
+    }
+    else
+    {
+      GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 );
+    }
+
+    for ( int j = 0; j < xSize; ++j )
+    {
+      if ( j == 0 )
+      {
+        resultLine[j] = processNineCellWindow( &mInputNodataValue, &scanLine1[j], &scanLine1[j+1], &mInputNodataValue, &scanLine2[j], \
+                                               &scanLine2[j+1], &mInputNodataValue, &scanLine3[j], &scanLine3[j+1] );
+      }
+      else if ( j == xSize - 1 )
+      {
+        resultLine[j] = processNineCellWindow( &scanLine1[j-1], &scanLine1[j], &mInputNodataValue, &scanLine2[j-1], &scanLine2[j], \
+                                               &mInputNodataValue, &scanLine3[j-1], &scanLine3[j], &mInputNodataValue );
+      }
+      else
+      {
+        resultLine[j] = processNineCellWindow( &scanLine1[j-1], &scanLine1[j], &scanLine1[j+1], &scanLine2[j-1], &scanLine2[j], \
+                                               &scanLine2[j+1], &scanLine3[j-1], &scanLine3[j], &scanLine3[j+1] );
+      }
+    }
+
+    GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 );
+  }
+
+  if ( p )
+  {
+    p->setValue( ySize );
+  }
+
+  CPLFree( resultLine );
+  CPLFree( scanLine1 );
+  CPLFree( scanLine2 );
+  CPLFree( scanLine3 );
+
+  GDALClose( inputDataset );
+
+  if ( p && p->wasCanceled() )
+  {
+    //delete the dataset without closing (because it is faster)
+    GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
+    return 7;
+  }
+  GDALClose( outputDataset );
+
+  return 0;
+}
+
+GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
+{
+  GDALDatasetH inputDataset = GDALOpen( mInputFile.toLocal8Bit().data(), GA_ReadOnly );
+  if ( inputDataset != NULL )
+  {
+    nCellsX = GDALGetRasterXSize( inputDataset );
+    nCellsY = GDALGetRasterYSize( inputDataset );
+
+    //we need at least one band
+    if ( GDALGetRasterCount( inputDataset ) < 1 )
+    {
+      GDALClose( inputDataset );
+      return NULL;
+    }
+  }
+  return inputDataset;
+}
+
+GDALDriverH QgsNineCellFilter::openOutputDriver()
+{
+  char **driverMetadata;
+
+  //open driver
+  GDALDriverH outputDriver = GDALGetDriverByName( mOutputFormat.toLocal8Bit().data() );
+
+  if ( outputDriver == NULL )
+  {
+    return outputDriver; //return NULL, driver does not exist
+  }
+
+  driverMetadata = GDALGetMetadata( outputDriver, NULL );
+  if ( !CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, FALSE ) )
+  {
+    return NULL; //driver exist, but it does not support the create operation
+  }
+
+  return outputDriver;
+}
+
+GDALDatasetH QgsNineCellFilter::openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver )
+{
+  if ( inputDataset == NULL )
+  {
+    return NULL;
+  }
+
+  int xSize = GDALGetRasterXSize( inputDataset );
+  int ySize = GDALGetRasterYSize( inputDataset );;
+
+  //open output file
+  char **papszOptions = NULL;
+  GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), xSize, ySize, 1, GDT_Float32, papszOptions );
+  if ( outputDataset == NULL )
+  {
+    return outputDataset;
+  }
+
+  //get geotransform from inputDataset
+  double geotransform[6];
+  if ( GDALGetGeoTransform( inputDataset, geotransform ) != CE_None )
+  {
+    GDALClose( outputDataset );
+    return NULL;
+  }
+  GDALSetGeoTransform( outputDataset, geotransform );
+
+  //make sure mCellSizeX and mCellSizeY are always > 0
+  mCellSizeX = geotransform[1];
+  if ( mCellSizeX < 0 )
+  {
+    mCellSizeX = -mCellSizeX;
+  }
+  mCellSizeY = geotransform[5];
+  if ( mCellSizeY < 0 )
+  {
+    mCellSizeY = -mCellSizeY;
+  }
+
+  const char* projection = GDALGetProjectionRef( inputDataset );
+  GDALSetProjection( outputDataset, projection );
+
+  return outputDataset;
+}
+


Property changes on: trunk/qgis/src/analysis/raster/qgsninecellfilter.cpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgsninecellfilter.h (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.h)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsninecellfilter.h	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsninecellfilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,72 @@
+/***************************************************************************
+                          qgsninecellfilter.h  -  description
+                             -------------------
+    begin                : August 6th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef QGSNINECELLFILTER_H
+#define QGSNINECELLFILTER_H
+
+#include <QString>
+#include "gdal.h"
+
+class QProgressDialog;
+
+/**Base class for raster analysis methods that work with a 3x3 cell filter and calculate the value of each cell based on \
+the cell value and the eight neighbour cells. Common examples are slope and aspect calculation in DEMs. Subclasses only implement \
+the method that calculates the new value from the nine values. Everything else (reading file, writing file) is done by this subclass*/
+
+class QgsNineCellFilter
+{
+  public:
+    /**Constructor that takes input file, output file and output format (GDAL string)*/
+    QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
+    virtual ~QgsNineCellFilter();
+    /**Starts the calculation, reads from mInputFile and stores the result in mOutputFile
+      @param p progress dialog that receives update and that is checked for abort. 0 if no progress bar is needed.
+      @return 0 in case of success*/
+    int processRaster( QProgressDialog* p );
+
+  private:
+    //default constructor forbidden. We need input file, output file and format obligatory
+    QgsNineCellFilter();
+
+    /**Opens the input file and returns the dataset handle and the number of pixels in x-/y- direction*/
+    GDALDatasetH openInputFile( int& nCellsX, int& nCellsY );
+    /**Opens the output driver and tests if it supports the creation of a new dataset
+      @return NULL on error and the driver handle on success*/
+    GDALDriverH openOutputDriver();
+    /**Opens the output file and sets the same geotransform and CRS as the input data
+      @return the output dataset or NULL in case of error*/
+    GDALDatasetH openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver );
+
+  protected:
+    /**Calculates output value from nine input values. The input values and the output value can be equal to the \
+      nodata value if not present or outside of the border. Must be implemented by subclasses*/
+    virtual float processNineCellWindow( float* x11, float* x21, float* x31, \
+                                         float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 ) = 0;
+
+    QString mInputFile;
+    QString mOutputFile;
+    QString mOutputFormat;
+
+    double mCellSizeX;
+    double mCellSizeY;
+    /**The nodata value of the input layer*/
+    float mInputNodataValue;
+    /**The nodata value of the output layer*/
+    float mOutputNodataValue;
+};
+
+#endif // QGSNINECELLFILTER_H


Property changes on: trunk/qgis/src/analysis/raster/qgsninecellfilter.h
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgsruggednessfilter.cpp (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.cpp)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsruggednessfilter.cpp	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsruggednessfilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,94 @@
+/***************************************************************************
+                          qgsruggednessfilter.cpp  -  description
+                          -----------------------
+    begin                : August 7th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "qgsruggednessfilter.h"
+
+QgsRuggednessFilter::QgsRuggednessFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): QgsNineCellFilter( inputFile, outputFile, outputFormat )
+{
+
+}
+
+QgsRuggednessFilter::QgsRuggednessFilter(): QgsNineCellFilter( "", "", "" )
+{
+
+}
+
+
+QgsRuggednessFilter::~QgsRuggednessFilter()
+{
+
+}
+
+float QgsRuggednessFilter::processNineCellWindow( float* x11, float* x21, float* x31, \
+    float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
+{
+  //the formula would be that easy without nodata values...
+  /*
+    //return *x22; //test: write the raster value of the middle cell
+    float diff1 = *x11 - *x22;
+    float diff2 = *x21 - *x22;
+    float diff3 = *x31 - *x22;
+    float diff4 = *x12 - *x22;
+    float diff5 = *x32 - *x22;
+    float diff6 = *x13 - *x22;
+    float diff7 = *x23 - *x22;
+    float diff8 = *x33 - *x22;
+    return sqrt(diff1 * diff1 + diff2 * diff2 + diff3 * diff3 + diff4 * diff4 + diff5 * diff5 + diff6 * diff6 + diff7 * diff7 + diff8 * diff8);
+   */
+
+  if ( *x22 == mInputNodataValue )
+  {
+    return mOutputNodataValue;
+  }
+
+  double sum = 0;
+  if ( *x11 != mInputNodataValue )
+  {
+    sum += ( *x11 - *x22 ) * ( *x11 - *x22 );
+  }
+  if ( *x21 != mInputNodataValue )
+  {
+    sum += ( *x21 - *x22 ) * ( *x21 - *x22 );
+  }
+  if ( *x31 != mInputNodataValue )
+  {
+    sum += ( *x31 - *x22 ) * ( *x31 - *x22 );
+  }
+  if ( *x12 != mInputNodataValue )
+  {
+    sum += ( *x12 - *x22 ) * ( *x12 - *x22 );
+  }
+  if ( *x32 != mInputNodataValue )
+  {
+    sum += ( *x32 - *x22 ) * ( *x32 - *x22 );
+  }
+  if ( *x13 != mInputNodataValue )
+  {
+    sum += ( *x13 - *x22 ) * ( *x13 - *x22 );
+  }
+  if ( *x23 != mInputNodataValue )
+  {
+    sum += ( *x23 - *x22 ) * ( *x23 - *x22 );
+  }
+  if ( *x33 != mInputNodataValue )
+  {
+    sum += ( *x33 - *x22 ) * ( *x33 - *x22 );
+  }
+
+  return sqrt( sum );
+}
+


Property changes on: trunk/qgis/src/analysis/raster/qgsruggednessfilter.cpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgsruggednessfilter.h (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.h)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsruggednessfilter.h	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsruggednessfilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,40 @@
+/***************************************************************************
+                          qgsruggednessfilter.h  -  description
+                          ---------------------
+    begin                : August 7th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef QGSRUGGEDNESSFILTER_H
+#define QGSRUGGEDNESSFILTER_H
+
+#include "qgsninecellfilter.h"
+
+/**Calculates the ruggedness index based on a 3x3 moving window*/
+class QgsRuggednessFilter: public QgsNineCellFilter
+{
+  public:
+    QgsRuggednessFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
+    ~QgsRuggednessFilter();
+
+  protected:
+    /**Calculates output value from nine input values. The input values and the output value can be equal to the \
+      nodata value if not present or outside of the border. Must be implemented by subclasses*/
+    float processNineCellWindow( float* x11, float* x21, float* x31, \
+                                 float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
+
+  private:
+    QgsRuggednessFilter();
+};
+
+#endif // QGSRUGGEDNESSFILTER_H


Property changes on: trunk/qgis/src/analysis/raster/qgsruggednessfilter.h
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgsslopefilter.cpp (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.cpp)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsslopefilter.cpp	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsslopefilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,44 @@
+/***************************************************************************
+                          qgsslopefilter.h  -  description
+                          --------------------------------
+    begin                : August 7th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "qgsslopefilter.h"
+
+QgsSlopeFilter::QgsSlopeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
+    QgsDerivativeFilter( inputFile, outputFile, outputFormat )
+{
+
+}
+
+QgsSlopeFilter::~QgsSlopeFilter()
+{
+
+}
+
+float QgsSlopeFilter::processNineCellWindow( float* x11, float* x21, float* x31, \
+    float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
+{
+  float derX = calcFirstDerX( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
+  float derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
+
+  if ( derX == mOutputNodataValue || derY == mOutputNodataValue )
+  {
+    return mOutputNodataValue;
+  }
+
+  return atan( sqrt( derX * derX + derY * derY ) ) * 180.0 / M_PI;
+}
+


Property changes on: trunk/qgis/src/analysis/raster/qgsslopefilter.cpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgsslopefilter.h (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.h)
===================================================================
--- trunk/qgis/src/analysis/raster/qgsslopefilter.h	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgsslopefilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,37 @@
+/***************************************************************************
+                          qgsslopefilter.h  -  description
+                          --------------------------------
+    begin                : August 7th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef QGSSLOPEFILTER_H
+#define QGSSLOPEFILTER_H
+
+#include "qgsderivativefilter.h"
+
+/**Calculates slope values in a window of 3x3 cells based on first order derivatives in x- and y- directions*/
+class QgsSlopeFilter: public QgsDerivativeFilter
+{
+  public:
+    QgsSlopeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
+    ~QgsSlopeFilter();
+
+  protected:
+    /**Calculates output value from nine input values. The input values and the output value can be equal to the \
+      nodata value if not present or outside of the border. Must be implemented by subclasses*/
+    float processNineCellWindow( float* x11, float* x21, float* x31, \
+                                 float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
+};
+
+#endif // QGSSLOPEFILTER_H


Property changes on: trunk/qgis/src/analysis/raster/qgsslopefilter.h
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.cpp (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.cpp)
===================================================================
--- trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.cpp	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,48 @@
+/***************************************************************************
+                          qgstotalcurvaturefilter.h  -  description
+                             -------------------
+    begin                : August 21th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "qgstotalcurvaturefilter.h"
+
+QgsTotalCurvatureFilter::QgsTotalCurvatureFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
+    QgsNineCellFilter( inputFile, outputFile, outputFormat )
+{
+
+}
+
+QgsTotalCurvatureFilter::~QgsTotalCurvatureFilter()
+{
+
+}
+
+float QgsTotalCurvatureFilter::processNineCellWindow( float* x11, float* x21, float* x31, float* x12, \
+    float* x22, float* x32, float* x13, float* x23, float* x33 )
+{
+  //return nodata if one value is the nodata value
+  if ( *x11 == mInputNodataValue || *x21 == mInputNodataValue || *x31 == mInputNodataValue || *x12 == mInputNodataValue \
+       || *x22 == mInputNodataValue || *x32 == mInputNodataValue || *x13 == mInputNodataValue || *x23 == mInputNodataValue \
+       || *x33 == mInputNodataValue )
+  {
+    return mOutputNodataValue;
+  }
+
+  double cellSizeAvg = ( mCellSizeX + mCellSizeY ) / 2.0;
+  double dxx = ( *x32 - 2 * *x22 + *x12 ) / ( mCellSizeX * mCellSizeX );
+  double dyy = ( -*x11 + *x31 + *x13 - *x33 ) / ( 4 * cellSizeAvg * cellSizeAvg );
+  double dxy = ( *x21 - 2 * *x22 + *x23 ) / ( mCellSizeY * mCellSizeY );
+
+  return dxx*dxx + 2*dxy*dxy + dyy*dyy;
+}


Property changes on: trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.cpp
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.h (from rev 11557, trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.h)
===================================================================
--- trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.h	                        (rev 0)
+++ trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -0,0 +1,37 @@
+/***************************************************************************
+                          qgstotalcurvaturefilter.h  -  description
+                             -------------------
+    begin                : August 21th, 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef QGSTOTALCURVATUREFILTER_H
+#define QGSTOTALCURVATUREFILTER_H
+
+#include "qgsninecellfilter.h"
+
+/**Calculates total curvature as described by Wilson, Gallant (2000): terrain analysis*/
+class QgsTotalCurvatureFilter: public QgsNineCellFilter
+{
+  public:
+    QgsTotalCurvatureFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
+    ~QgsTotalCurvatureFilter();
+
+  protected:
+    /**Calculates total curvature from nine input values. The input values and the output value can be equal to the \
+      nodata value if not present or outside of the border. Must be implemented by subclasses*/
+    float processNineCellWindow( float* x11, float* x21, float* x31, \
+                                 float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
+};
+
+#endif // QGSTOTALCURVATUREFILTER_H


Property changes on: trunk/qgis/src/analysis/raster/qgstotalcurvaturefilter.h
___________________________________________________________________
Added: svn:mergeinfo
   + 

Modified: trunk/qgis/src/plugins/raster_terrain_analysis/CMakeLists.txt
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/CMakeLists.txt	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/CMakeLists.txt	2009-09-05 09:59:26 UTC (rev 11558)
@@ -3,12 +3,6 @@
 
 SET (RASTER_TERRAIN_SRCS
      qgsrasterterrainanalysisplugin.cpp
-     qgsninecellfilter.cpp
-     qgsruggednessfilter.cpp
-     qgsderivativefilter.cpp
-     qgsslopefilter.cpp
-     qgsaspectfilter.cpp
-     qgstotalcurvaturefilter.cpp
      qgsrasterterrainanalysisdialog.cpp
 )
 
@@ -48,6 +42,7 @@
 )
 
 TARGET_LINK_LIBRARIES(rasterterrainplugin
+  qgis_analysis
   qgis_core
   qgis_gui
 )

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.cpp	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,50 +0,0 @@
-/***************************************************************************
-                          qgsaspectfilter.cpp  -  description
-                          -----------------------------------
-    begin                : August 7th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "qgsaspectfilter.h"
-
-QgsAspectFilter::QgsAspectFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ) :
-    QgsDerivativeFilter( inputFile, outputFile, outputFormat )
-{
-
-}
-
-QgsAspectFilter::~QgsAspectFilter()
-{
-
-}
-
-float QgsAspectFilter::processNineCellWindow(
-    float* x11, float* x21, float* x31,
-    float* x12, float* x22, float* x32,
-    float* x13, float* x23, float* x33 )
-{
-  float derX = calcFirstDerX( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
-  float derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
-
-  if ( derX == mOutputNodataValue ||
-       derY == mOutputNodataValue ||
-       (derX == 0.0 && derY == 0.0) )
-  {
-    return mOutputNodataValue;
-  }
-  else
-  {
-    return 180.0 + atan2(derX, derY) * 180.0 / M_PI;
-  }
-}
-

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.h	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,38 +0,0 @@
-/***************************************************************************
-                          qgsaspectfilter.h  -  description
-                          ---------------------------------
-    begin                : August 7th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef QGSASPECTFILTER_H
-#define QGSASPECTFILTER_H
-
-#include "qgsderivativefilter.h"
-
-/**Calculates aspect values in a window of 3x3 cells based on first order derivatives in x- and y- directions. Direction is clockwise starting from north*/
-class QgsAspectFilter: public QgsDerivativeFilter
-{
-  public:
-    QgsAspectFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
-    ~QgsAspectFilter();
-
-  protected:
-  protected:
-    /**Calculates output value from nine input values. The input values and the output value can be equal to the \
-      nodata value if not present or outside of the border. Must be implemented by subclasses*/
-    float processNineCellWindow( float* x11, float* x21, float* x31, \
-                                 float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
-};
-
-#endif // QGSASPECTFILTER_H

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.cpp	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,168 +0,0 @@
-/***************************************************************************
-                          qgsderivativefilter.cpp  -  description
-                          -----------------------
-    begin                : August 7th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "qgsderivativefilter.h"
-
-QgsDerivativeFilter::QgsDerivativeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
-    QgsNineCellFilter( inputFile, outputFile, outputFormat )
-{
-
-}
-
-QgsDerivativeFilter::~QgsDerivativeFilter()
-{
-
-}
-
-float QgsDerivativeFilter::calcFirstDerX( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
-{
-  //the basic formula would be simple, but we need to test for nodata values...
-  //return (( (*x31 - *x11) + 2 * (*x32 - *x12) + (*x33 - *x13) ) / (8 * mCellSizeX));
-
-  int weight = 0;
-  double sum = 0;
-
-  //first row
-  if ( *x31 != mInputNodataValue && *x11 != mInputNodataValue ) //the normal case
-  {
-    sum += ( *x31 - *x11 );
-    weight += 2;
-  }
-  else if ( *x31 == mInputNodataValue && *x11 != mInputNodataValue && *x21 != mInputNodataValue ) //probably 3x3 window is at the border
-  {
-    sum += ( *x21 - *x11 );
-    weight += 1;
-  }
-  else if ( *x11 == mInputNodataValue && *x31 != mInputNodataValue && *x21 != mInputNodataValue ) //probably 3x3 window is at the border
-  {
-    sum += ( *x31 - *x21 );
-    weight += 1;
-  }
-
-  //second row
-  if ( *x32 != mInputNodataValue && *x12 != mInputNodataValue ) //the normal case
-  {
-    sum += 2 * ( *x32 - *x12 );
-    weight += 4;
-  }
-  else if ( *x32 == mInputNodataValue && *x12 != mInputNodataValue && *x22 != mInputNodataValue )
-  {
-    sum += 2 * ( *x22 - *x12 );
-    weight += 2;
-  }
-  else if ( *x12 == mInputNodataValue && *x32 != mInputNodataValue && *x22 != mInputNodataValue )
-  {
-    sum += 2 * ( *x32 - *x22 );
-    weight += 2;
-  }
-
-  //third row
-  if ( *x33 != mInputNodataValue && *x13 != mInputNodataValue ) //the normal case
-  {
-    sum += ( *x33 - *x13 );
-    weight += 2;
-  }
-  else if ( *x33 == mInputNodataValue && *x13 != mInputNodataValue && *x23 != mInputNodataValue )
-  {
-    sum += ( *x23 - *x13 );
-    weight += 1;
-  }
-  else if ( *x13 == mInputNodataValue && *x33 != mInputNodataValue && *x23 != mInputNodataValue )
-  {
-    sum += ( *x33 - *x23 );
-    weight += 1;
-  }
-
-  if ( weight == 0 )
-  {
-    return mOutputNodataValue;
-  }
-
-  return sum / ( weight * mCellSizeX );
-}
-
-float QgsDerivativeFilter::calcFirstDerY( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
-{
-  //the basic formula would be simple, but we need to test for nodata values...
-  //return (((*x11 - *x13) + 2 * (*x21 - *x23) + (*x31 - *x33)) / ( 8 * mCellSizeY));
-
-  double sum = 0;
-  int weight = 0;
-
-  //first row
-  if ( *x11 != mInputNodataValue && *x13 != mInputNodataValue ) //normal case
-  {
-    sum += ( *x11 - *x13 );
-    weight += 2;
-  }
-  else if ( *x11 == mInputNodataValue && *x13 != mInputNodataValue && *x12 != mInputNodataValue )
-  {
-    sum += ( *x12 - *x13 );
-    weight += 1;
-  }
-  else if ( *x31 == mInputNodataValue && *x11 != mInputNodataValue && *x12 != mInputNodataValue )
-  {
-    sum += ( *x11 - *x12 );
-    weight += 1;
-  }
-
-  //second row
-  if ( *x21 != mInputNodataValue && *x23 != mInputNodataValue )
-  {
-    sum += 2 * ( *x21 - *x23 );
-    weight += 4;
-  }
-  else if ( *x21 == mInputNodataValue && *x23 != mInputNodataValue && *x22 != mInputNodataValue )
-  {
-    sum += 2 * ( *x22 - *x23 );
-    weight += 2;
-  }
-  else if ( *x23 == mInputNodataValue && *x21 != mInputNodataValue && *x22 != mInputNodataValue )
-  {
-    sum += 2 * ( *x21 - *x22 );
-    weight += 2;
-  }
-
-  //third row
-  if ( *x31 != mInputNodataValue && *x33 != mInputNodataValue )
-  {
-    sum += ( *x31 - *x33 );
-    weight += 2;
-  }
-  else if ( *x31 == mInputNodataValue && *x33 != mInputNodataValue && *x32 != mInputNodataValue )
-  {
-    sum += ( *x32 - *x33 );
-    weight += 1;
-  }
-  else if ( *x33 == mInputNodataValue && *x31 != mInputNodataValue && *x32 != mInputNodataValue )
-  {
-    sum += ( *x31 - *x32 );
-    weight += 1;
-  }
-
-  if ( weight == 0 )
-  {
-    return mOutputNodataValue;
-  }
-
-  return sum / ( weight * mCellSizeY );
-}
-
-
-
-
-

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.h	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,40 +0,0 @@
-/***************************************************************************
-                          qgsderivativefilter.h  -  description
-                          ---------------------
-    begin                : August 7th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef QGSDERIVATIVEFILTER_H
-#define QGSDERIVATIVEFILTER_H
-
-#include "qgsninecellfilter.h"
-
-/**Adds the ability to calculate derivatives in x- and y-directions. Needs to be subclassed (e.g. for slope and aspect)*/
-class QgsDerivativeFilter: public QgsNineCellFilter
-{
-  public:
-    QgsDerivativeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
-    virtual ~QgsDerivativeFilter();
-    //to be implemented by subclasses
-    virtual float processNineCellWindow( float* x11, float* x21, float* x31, float* x12, float* x22, \
-                                         float* x32, float* x13, float* x23, float* x33 ) = 0;
-
-  protected:
-    /**Calculates the first order derivative in x-direction according to Horn (1981)*/
-    float calcFirstDerX( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
-    /**Calculates the first order derivative in y-direction according to Horn (1981)*/
-    float calcFirstDerY( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
-};
-
-#endif // QGSDERIVATIVEFILTER_H

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.cpp	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,275 +0,0 @@
-/***************************************************************************
-                          qgsninecellfilter.h  -  description
-                             -------------------
-    begin                : August 6th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "qgsninecellfilter.h"
-#include "cpl_string.h"
-#include <QProgressDialog>
-
-
-QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
-    mInputFile( inputFile ), mOutputFile( outputFile ), mOutputFormat( outputFormat ), mCellSizeX( -1 ), mCellSizeY( -1 ), mInputNodataValue( -1 ), mOutputNodataValue( -1 )
-{
-
-}
-
-QgsNineCellFilter::QgsNineCellFilter()
-{
-
-}
-
-QgsNineCellFilter::~QgsNineCellFilter()
-{
-
-}
-
-int QgsNineCellFilter::processRaster( QProgressDialog* p )
-{
-  GDALAllRegister();
-
-  //open input file
-  int xSize, ySize;
-  GDALDatasetH  inputDataset = openInputFile( xSize, ySize );
-  if ( inputDataset == NULL )
-  {
-    return 1; //opening of input file failed
-  }
-
-  //output driver
-  GDALDriverH outputDriver = openOutputDriver();
-  if ( outputDriver == 0 )
-  {
-    return 2;
-  }
-
-  GDALDatasetH outputDataset = openOutputFile( inputDataset, outputDriver );
-  if ( outputDataset == NULL )
-  {
-    return 3; //create operation on output file failed
-  }
-
-  //open first raster band for reading (operation is only for single band raster)
-  GDALRasterBandH rasterBand = GDALGetRasterBand( inputDataset, 1 );
-  if ( rasterBand == NULL )
-  {
-    GDALClose( inputDataset );
-    GDALClose( outputDataset );
-    return 4;
-  }
-  mInputNodataValue = GDALGetRasterNoDataValue( rasterBand, NULL );
-
-  GDALRasterBandH outputRasterBand = GDALGetRasterBand( outputDataset, 1 );
-  if ( outputRasterBand == NULL )
-  {
-    GDALClose( inputDataset );
-    GDALClose( outputDataset );
-    return 5;
-  }
-  //try to set -9999 as nodata value
-  GDALSetRasterNoDataValue( outputRasterBand, -9999 );
-  mOutputNodataValue = GDALGetRasterNoDataValue( outputRasterBand, NULL );
-
-  if ( ySize < 3 ) //we require at least three rows (should be true for most datasets)
-  {
-    GDALClose( inputDataset );
-    GDALClose( outputDataset );
-    return 6;
-  }
-
-  //keep only three scanlines in memory at a time
-  float* scanLine1 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
-  float* scanLine2 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
-  float* scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
-
-  float* resultLine = ( float * ) CPLMalloc( sizeof( float ) * xSize );
-
-  if ( p )
-  {
-    p->setMaximum( ySize );
-  }
-
-  //values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
-  for ( int i = 0; i < ySize; ++i )
-  {
-    if ( p )
-    {
-      p->setValue( i );
-    }
-
-    if ( p && p->wasCanceled() )
-    {
-      break;
-    }
-
-    if ( i == 0 )
-    {
-      //fill scanline 1 with (input) nodata for the values above the first row and feed scanline2 with the first row
-      for ( int a = 0; a < xSize; ++a )
-      {
-        scanLine1[a] = mInputNodataValue;
-      }
-      GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 );
-    }
-    else
-    {
-      //normally fetch only scanLine3 and release scanline 1 if we move forward one row
-      CPLFree( scanLine1 );
-      scanLine1 = scanLine2;
-      scanLine2 = scanLine3;
-      scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
-    }
-
-    if ( i == ySize - 1 ) //fill the row below the bottom with nodata values
-    {
-      for ( int a = 0; a < xSize; ++a )
-      {
-        scanLine3[a] = mInputNodataValue;
-      }
-    }
-    else
-    {
-      GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 );
-    }
-
-    for ( int j = 0; j < xSize; ++j )
-    {
-      if ( j == 0 )
-      {
-        resultLine[j] = processNineCellWindow( &mInputNodataValue, &scanLine1[j], &scanLine1[j+1], &mInputNodataValue, &scanLine2[j], \
-                                               &scanLine2[j+1], &mInputNodataValue, &scanLine3[j], &scanLine3[j+1] );
-      }
-      else if ( j == xSize - 1 )
-      {
-        resultLine[j] = processNineCellWindow( &scanLine1[j-1], &scanLine1[j], &mInputNodataValue, &scanLine2[j-1], &scanLine2[j], \
-                                               &mInputNodataValue, &scanLine3[j-1], &scanLine3[j], &mInputNodataValue );
-      }
-      else
-      {
-        resultLine[j] = processNineCellWindow( &scanLine1[j-1], &scanLine1[j], &scanLine1[j+1], &scanLine2[j-1], &scanLine2[j], \
-                                               &scanLine2[j+1], &scanLine3[j-1], &scanLine3[j], &scanLine3[j+1] );
-      }
-    }
-
-    GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 );
-  }
-
-  if ( p )
-  {
-    p->setValue( ySize );
-  }
-
-  CPLFree( resultLine );
-  CPLFree( scanLine1 );
-  CPLFree( scanLine2 );
-  CPLFree( scanLine3 );
-
-  GDALClose( inputDataset );
-
-  if ( p && p->wasCanceled() )
-  {
-    //delete the dataset without closing (because it is faster)
-    GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
-    return 7;
-  }
-  GDALClose( outputDataset );
-
-  return 0;
-}
-
-GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
-{
-  GDALDatasetH inputDataset = GDALOpen( mInputFile.toLocal8Bit().data(), GA_ReadOnly );
-  if ( inputDataset != NULL )
-  {
-    nCellsX = GDALGetRasterXSize( inputDataset );
-    nCellsY = GDALGetRasterYSize( inputDataset );
-
-    //we need at least one band
-    if ( GDALGetRasterCount( inputDataset ) < 1 )
-    {
-      GDALClose( inputDataset );
-      return NULL;
-    }
-  }
-  return inputDataset;
-}
-
-GDALDriverH QgsNineCellFilter::openOutputDriver()
-{
-  char **driverMetadata;
-
-  //open driver
-  GDALDriverH outputDriver = GDALGetDriverByName( mOutputFormat.toLocal8Bit().data() );
-
-  if ( outputDriver == NULL )
-  {
-    return outputDriver; //return NULL, driver does not exist
-  }
-
-  driverMetadata = GDALGetMetadata( outputDriver, NULL );
-  if ( !CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, FALSE ) )
-  {
-    return NULL; //driver exist, but it does not support the create operation
-  }
-
-  return outputDriver;
-}
-
-GDALDatasetH QgsNineCellFilter::openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver )
-{
-  if ( inputDataset == NULL )
-  {
-    return NULL;
-  }
-
-  int xSize = GDALGetRasterXSize( inputDataset );
-  int ySize = GDALGetRasterYSize( inputDataset );;
-
-  //open output file
-  char **papszOptions = NULL;
-  GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), xSize, ySize, 1, GDT_Float32, papszOptions );
-  if ( outputDataset == NULL )
-  {
-    return outputDataset;
-  }
-
-  //get geotransform from inputDataset
-  double geotransform[6];
-  if ( GDALGetGeoTransform( inputDataset, geotransform ) != CE_None )
-  {
-    GDALClose( outputDataset );
-    return NULL;
-  }
-  GDALSetGeoTransform( outputDataset, geotransform );
-
-  //make sure mCellSizeX and mCellSizeY are always > 0
-  mCellSizeX = geotransform[1];
-  if ( mCellSizeX < 0 )
-  {
-    mCellSizeX = -mCellSizeX;
-  }
-  mCellSizeY = geotransform[5];
-  if ( mCellSizeY < 0 )
-  {
-    mCellSizeY = -mCellSizeY;
-  }
-
-  const char* projection = GDALGetProjectionRef( inputDataset );
-  GDALSetProjection( outputDataset, projection );
-
-  return outputDataset;
-}
-

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.h	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,72 +0,0 @@
-/***************************************************************************
-                          qgsninecellfilter.h  -  description
-                             -------------------
-    begin                : August 6th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef QGSNINECELLFILTER_H
-#define QGSNINECELLFILTER_H
-
-#include <QString>
-#include "gdal.h"
-
-class QProgressDialog;
-
-/**Base class for raster analysis methods that work with a 3x3 cell filter and calculate the value of each cell based on \
-the cell value and the eight neighbour cells. Common examples are slope and aspect calculation in DEMs. Subclasses only implement \
-the method that calculates the new value from the nine values. Everything else (reading file, writing file) is done by this subclass*/
-
-class QgsNineCellFilter
-{
-  public:
-    /**Constructor that takes input file, output file and output format (GDAL string)*/
-    QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
-    virtual ~QgsNineCellFilter();
-    /**Starts the calculation, reads from mInputFile and stores the result in mOutputFile
-      @param p progress dialog that receives update and that is checked for abort. 0 if no progress bar is needed.
-      @return 0 in case of success*/
-    int processRaster( QProgressDialog* p );
-
-  private:
-    //default constructor forbidden. We need input file, output file and format obligatory
-    QgsNineCellFilter();
-
-    /**Opens the input file and returns the dataset handle and the number of pixels in x-/y- direction*/
-    GDALDatasetH openInputFile( int& nCellsX, int& nCellsY );
-    /**Opens the output driver and tests if it supports the creation of a new dataset
-      @return NULL on error and the driver handle on success*/
-    GDALDriverH openOutputDriver();
-    /**Opens the output file and sets the same geotransform and CRS as the input data
-      @return the output dataset or NULL in case of error*/
-    GDALDatasetH openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver );
-
-  protected:
-    /**Calculates output value from nine input values. The input values and the output value can be equal to the \
-      nodata value if not present or outside of the border. Must be implemented by subclasses*/
-    virtual float processNineCellWindow( float* x11, float* x21, float* x31, \
-                                         float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 ) = 0;
-
-    QString mInputFile;
-    QString mOutputFile;
-    QString mOutputFormat;
-
-    double mCellSizeX;
-    double mCellSizeY;
-    /**The nodata value of the input layer*/
-    float mInputNodataValue;
-    /**The nodata value of the output layer*/
-    float mOutputNodataValue;
-};
-
-#endif // QGSNINECELLFILTER_H

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.cpp	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,94 +0,0 @@
-/***************************************************************************
-                          qgsruggednessfilter.cpp  -  description
-                          -----------------------
-    begin                : August 7th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "qgsruggednessfilter.h"
-
-QgsRuggednessFilter::QgsRuggednessFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): QgsNineCellFilter( inputFile, outputFile, outputFormat )
-{
-
-}
-
-QgsRuggednessFilter::QgsRuggednessFilter(): QgsNineCellFilter( "", "", "" )
-{
-
-}
-
-
-QgsRuggednessFilter::~QgsRuggednessFilter()
-{
-
-}
-
-float QgsRuggednessFilter::processNineCellWindow( float* x11, float* x21, float* x31, \
-    float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
-{
-  //the formula would be that easy without nodata values...
-  /*
-    //return *x22; //test: write the raster value of the middle cell
-    float diff1 = *x11 - *x22;
-    float diff2 = *x21 - *x22;
-    float diff3 = *x31 - *x22;
-    float diff4 = *x12 - *x22;
-    float diff5 = *x32 - *x22;
-    float diff6 = *x13 - *x22;
-    float diff7 = *x23 - *x22;
-    float diff8 = *x33 - *x22;
-    return sqrt(diff1 * diff1 + diff2 * diff2 + diff3 * diff3 + diff4 * diff4 + diff5 * diff5 + diff6 * diff6 + diff7 * diff7 + diff8 * diff8);
-   */
-
-  if ( *x22 == mInputNodataValue )
-  {
-    return mOutputNodataValue;
-  }
-
-  double sum = 0;
-  if ( *x11 != mInputNodataValue )
-  {
-    sum += ( *x11 - *x22 ) * ( *x11 - *x22 );
-  }
-  if ( *x21 != mInputNodataValue )
-  {
-    sum += ( *x21 - *x22 ) * ( *x21 - *x22 );
-  }
-  if ( *x31 != mInputNodataValue )
-  {
-    sum += ( *x31 - *x22 ) * ( *x31 - *x22 );
-  }
-  if ( *x12 != mInputNodataValue )
-  {
-    sum += ( *x12 - *x22 ) * ( *x12 - *x22 );
-  }
-  if ( *x32 != mInputNodataValue )
-  {
-    sum += ( *x32 - *x22 ) * ( *x32 - *x22 );
-  }
-  if ( *x13 != mInputNodataValue )
-  {
-    sum += ( *x13 - *x22 ) * ( *x13 - *x22 );
-  }
-  if ( *x23 != mInputNodataValue )
-  {
-    sum += ( *x23 - *x22 ) * ( *x23 - *x22 );
-  }
-  if ( *x33 != mInputNodataValue )
-  {
-    sum += ( *x33 - *x22 ) * ( *x33 - *x22 );
-  }
-
-  return sqrt( sum );
-}
-

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.h	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,40 +0,0 @@
-/***************************************************************************
-                          qgsruggednessfilter.h  -  description
-                          ---------------------
-    begin                : August 7th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef QGSRUGGEDNESSFILTER_H
-#define QGSRUGGEDNESSFILTER_H
-
-#include "qgsninecellfilter.h"
-
-/**Calculates the ruggedness index based on a 3x3 moving window*/
-class QgsRuggednessFilter: public QgsNineCellFilter
-{
-  public:
-    QgsRuggednessFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
-    ~QgsRuggednessFilter();
-
-  protected:
-    /**Calculates output value from nine input values. The input values and the output value can be equal to the \
-      nodata value if not present or outside of the border. Must be implemented by subclasses*/
-    float processNineCellWindow( float* x11, float* x21, float* x31, \
-                                 float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
-
-  private:
-    QgsRuggednessFilter();
-};
-
-#endif // QGSRUGGEDNESSFILTER_H

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.cpp	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,44 +0,0 @@
-/***************************************************************************
-                          qgsslopefilter.h  -  description
-                          --------------------------------
-    begin                : August 7th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "qgsslopefilter.h"
-
-QgsSlopeFilter::QgsSlopeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
-    QgsDerivativeFilter( inputFile, outputFile, outputFormat )
-{
-
-}
-
-QgsSlopeFilter::~QgsSlopeFilter()
-{
-
-}
-
-float QgsSlopeFilter::processNineCellWindow( float* x11, float* x21, float* x31, \
-    float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
-{
-  float derX = calcFirstDerX( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
-  float derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
-
-  if ( derX == mOutputNodataValue || derY == mOutputNodataValue )
-  {
-    return mOutputNodataValue;
-  }
-
-  return atan( sqrt( derX * derX + derY * derY ) ) * 180.0 / M_PI;
-}
-

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.h	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,37 +0,0 @@
-/***************************************************************************
-                          qgsslopefilter.h  -  description
-                          --------------------------------
-    begin                : August 7th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef QGSSLOPEFILTER_H
-#define QGSSLOPEFILTER_H
-
-#include "qgsderivativefilter.h"
-
-/**Calculates slope values in a window of 3x3 cells based on first order derivatives in x- and y- directions*/
-class QgsSlopeFilter: public QgsDerivativeFilter
-{
-  public:
-    QgsSlopeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
-    ~QgsSlopeFilter();
-
-  protected:
-    /**Calculates output value from nine input values. The input values and the output value can be equal to the \
-      nodata value if not present or outside of the border. Must be implemented by subclasses*/
-    float processNineCellWindow( float* x11, float* x21, float* x31, \
-                                 float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
-};
-
-#endif // QGSSLOPEFILTER_H

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.cpp	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.cpp	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,48 +0,0 @@
-/***************************************************************************
-                          qgstotalcurvaturefilter.h  -  description
-                             -------------------
-    begin                : August 21th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "qgstotalcurvaturefilter.h"
-
-QgsTotalCurvatureFilter::QgsTotalCurvatureFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
-    QgsNineCellFilter( inputFile, outputFile, outputFormat )
-{
-
-}
-
-QgsTotalCurvatureFilter::~QgsTotalCurvatureFilter()
-{
-
-}
-
-float QgsTotalCurvatureFilter::processNineCellWindow( float* x11, float* x21, float* x31, float* x12, \
-    float* x22, float* x32, float* x13, float* x23, float* x33 )
-{
-  //return nodata if one value is the nodata value
-  if ( *x11 == mInputNodataValue || *x21 == mInputNodataValue || *x31 == mInputNodataValue || *x12 == mInputNodataValue \
-       || *x22 == mInputNodataValue || *x32 == mInputNodataValue || *x13 == mInputNodataValue || *x23 == mInputNodataValue \
-       || *x33 == mInputNodataValue )
-  {
-    return mOutputNodataValue;
-  }
-
-  double cellSizeAvg = ( mCellSizeX + mCellSizeY ) / 2.0;
-  double dxx = ( *x32 - 2 * *x22 + *x12 ) / ( mCellSizeX * mCellSizeX );
-  double dyy = ( -*x11 + *x31 + *x13 - *x33 ) / ( 4 * cellSizeAvg * cellSizeAvg );
-  double dxy = ( *x21 - 2 * *x22 + *x23 ) / ( mCellSizeY * mCellSizeY );
-
-  return dxx*dxx + 2*dxy*dxy + dyy*dyy;
-}

Deleted: trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.h	2009-09-05 09:42:46 UTC (rev 11557)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.h	2009-09-05 09:59:26 UTC (rev 11558)
@@ -1,37 +0,0 @@
-/***************************************************************************
-                          qgstotalcurvaturefilter.h  -  description
-                             -------------------
-    begin                : August 21th, 2009
-    copyright            : (C) 2009 by Marco Hugentobler
-    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   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.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef QGSTOTALCURVATUREFILTER_H
-#define QGSTOTALCURVATUREFILTER_H
-
-#include "qgsninecellfilter.h"
-
-/**Calculates total curvature as described by Wilson, Gallant (2000): terrain analysis*/
-class QgsTotalCurvatureFilter: public QgsNineCellFilter
-{
-  public:
-    QgsTotalCurvatureFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
-    ~QgsTotalCurvatureFilter();
-
-  protected:
-    /**Calculates total curvature from nine input values. The input values and the output value can be equal to the \
-      nodata value if not present or outside of the border. Must be implemented by subclasses*/
-    float processNineCellWindow( float* x11, float* x21, float* x31, \
-                                 float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
-};
-
-#endif // QGSTOTALCURVATUREFILTER_H



More information about the QGIS-commit mailing list