~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          qgsrasterterrainanalysisplugin.cpp  -  description
 
3
                             -------------------
 
4
    begin                : August 6th, 2009
 
5
    copyright            : (C) 2009 by Marco Hugentobler
 
6
    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "qgsrasterterrainanalysisplugin.h"
 
19
#include "qgis.h"
 
20
#include "qgisinterface.h"
 
21
#include "qgsmaplayer.h"
 
22
#include "qgsmaplayerregistry.h"
 
23
#include "qgsaspectfilter.h"
 
24
#include "qgsslopefilter.h"
 
25
#include "qgsruggednessfilter.h"
 
26
#include "qgstotalcurvaturefilter.h"
 
27
#include "qgsrasterterrainanalysisdialog.h"
 
28
#include <QAction>
 
29
#include <QProgressDialog>
 
30
 
 
31
static const QString name_ = QObject::tr( "Raster Terrain Analysis plugin" );
 
32
static const QString description_ = QObject::tr( "A plugin for raster based terrain analysis" );
 
33
static const QString version_ = QObject::tr( "Version 0.1" );
 
34
 
 
35
QgsRasterTerrainAnalysisPlugin::QgsRasterTerrainAnalysisPlugin( QgisInterface* iface ): mIface( iface ), mAction( 0 )
 
36
{
 
37
 
 
38
}
 
39
 
 
40
QgsRasterTerrainAnalysisPlugin::~QgsRasterTerrainAnalysisPlugin()
 
41
{
 
42
 
 
43
}
 
44
 
 
45
void QgsRasterTerrainAnalysisPlugin::initGui()
 
46
{
 
47
  //create Action
 
48
  if ( mIface )
 
49
  {
 
50
    mAction = new QAction( QIcon( ":/raster/raster_terrain_icon.png" ), tr( "&Raster based terrain analysis..." ), 0 );
 
51
    QObject::connect( mAction, SIGNAL( triggered() ), this, SLOT( run() ) );
 
52
    mIface->addToolBarIcon( mAction );
 
53
    mIface->addPluginToMenu( tr( "&Raster based terrain analysis..." ), mAction );
 
54
  }
 
55
}
 
56
 
 
57
void QgsRasterTerrainAnalysisPlugin::unload()
 
58
{
 
59
  if ( mIface )
 
60
  {
 
61
    mIface->removePluginMenu( tr( "&Raster based terrain analysis..." ), mAction );
 
62
    mIface ->removeToolBarIcon( mAction );
 
63
    delete mAction;
 
64
  }
 
65
}
 
66
 
 
67
void QgsRasterTerrainAnalysisPlugin::run()
 
68
{
 
69
  //testcode, remove it after debugging and show a dialog
 
70
  //QgsRuggednessFilter r("/home/marco/geodaten/raster/albis/mmal25.agr", "/home/marco/tmp/ruggedtest.tif", "GTiff");
 
71
  //QgsSlopeFilter slopeFilter("/home/marco/geodaten/raster/albis/mmal25.agr", "/home/marco/tmp/ruggedtest.tif", "GTiff");
 
72
  //QgsAspectFilter aspectFilter("/home/marco/geodaten/raster/albis/mmal25.agr", "/home/marco/tmp/ruggedtest.tif", "GTiff");
 
73
  //slopeFilter.processRaster(0);
 
74
 
 
75
  QgsRasterTerrainAnalysisDialog d( mIface );
 
76
  if ( d.exec() == QDialog::Accepted )
 
77
  {
 
78
    //get input layer from id
 
79
    QString inputLayerId = d.selectedInputLayerId();
 
80
    QgsMapLayer* inputLayer = QgsMapLayerRegistry::instance()->mapLayer( inputLayerId );
 
81
    if ( !inputLayer )
 
82
    {
 
83
      return;
 
84
    }
 
85
    QString inputFilePath = inputLayer->source();
 
86
 
 
87
    QString analysisMethod = d.selectedAnalysisMethod();
 
88
    QString selectedFormat = d.selectedDriverKey();
 
89
    QString outputFile = d.selectedOuputFilePath();
 
90
    int returnValue;
 
91
 
 
92
    QgsNineCellFilter* filter = 0;
 
93
    if ( d.selectedAnalysisMethod() == tr( "Slope" ) )
 
94
    {
 
95
      filter = new QgsSlopeFilter( inputFilePath, outputFile, selectedFormat );
 
96
    }
 
97
    else if ( d.selectedAnalysisMethod() == tr( "Aspect" ) )
 
98
    {
 
99
      filter = new QgsAspectFilter( inputFilePath, outputFile, selectedFormat );
 
100
    }
 
101
    else if ( d.selectedAnalysisMethod() == tr( "Ruggedness index" ) )
 
102
    {
 
103
      filter = new QgsRuggednessFilter( inputFilePath, outputFile, selectedFormat );
 
104
    }
 
105
    else if ( d.selectedAnalysisMethod() == tr( "Total curvature" ) )
 
106
    {
 
107
      filter = new QgsTotalCurvatureFilter( inputFilePath, outputFile, selectedFormat );
 
108
    }
 
109
 
 
110
    if ( filter )
 
111
    {
 
112
      QProgressDialog p( tr( "Calculating " ) + d.selectedAnalysisMethod() + "...", tr( "Abort..." ), 0, 0 );
 
113
      p.setWindowModality( Qt::WindowModal );
 
114
      returnValue = filter->processRaster( &p );
 
115
      delete filter;
 
116
      if ( d.addLayerToProject() )
 
117
      {
 
118
        mIface->addRasterLayer( outputFile, d.selectedAnalysisMethod() );
 
119
      }
 
120
    }
 
121
  }
 
122
}
 
123
 
 
124
//global methods for the plugin manager
 
125
QGISEXTERN QgisPlugin* classFactory( QgisInterface * ifacePointer )
 
126
{
 
127
  return new QgsRasterTerrainAnalysisPlugin( ifacePointer );
 
128
}
 
129
 
 
130
QGISEXTERN QString name()
 
131
{
 
132
  return name_;
 
133
}
 
134
 
 
135
QGISEXTERN QString description()
 
136
{
 
137
  return description_;
 
138
}
 
139
 
 
140
QGISEXTERN QString version()
 
141
{
 
142
  return version_;
 
143
}
 
144
 
 
145
QGISEXTERN int type()
 
146
{
 
147
  return QgisPlugin::UI;
 
148
}
 
149
 
 
150
QGISEXTERN void unload( QgisPlugin* pluginPointer )
 
151
{
 
152
  delete pluginPointer;
 
153
}
 
154
 
 
155