[QGIS Commit] r11510 - in trunk/qgis/src/plugins: .
raster_terrain_analysis
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Aug 26 08:28:16 EDT 2009
Author: mhugent
Date: 2009-08-26 08:28:15 -0400 (Wed, 26 Aug 2009)
New Revision: 11510
Added:
trunk/qgis/src/plugins/raster_terrain_analysis/
trunk/qgis/src/plugins/raster_terrain_analysis/CMakeLists.txt
trunk/qgis/src/plugins/raster_terrain_analysis/Makefile
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/qgsrasterterrainanalysisdialog.cpp
trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.h
trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialogbase.h
trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialogbase.ui
trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp
trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.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/qgsruggednessindex.cpp
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
trunk/qgis/src/plugins/raster_terrain_analysis/raster_terrain_icon.png
trunk/qgis/src/plugins/raster_terrain_analysis/resources.qrc
trunk/qgis/src/plugins/raster_terrain_analysis/ui_qgsrasterterrainanalysisdialogbase.h
Modified:
trunk/qgis/src/plugins/CMakeLists.txt
Log:
[FEATURE] Add the raster terrain plugin that does calculate of slope, aspect, ruggedness, total curvature from raster layers
Modified: trunk/qgis/src/plugins/CMakeLists.txt
===================================================================
--- trunk/qgis/src/plugins/CMakeLists.txt 2009-08-26 11:56:41 UTC (rev 11509)
+++ trunk/qgis/src/plugins/CMakeLists.txt 2009-08-26 12:28:15 UTC (rev 11510)
@@ -4,6 +4,7 @@
north_arrow
scale_bar
oracle_raster
+ raster_terrain_analysis
)
IF (POSTGRES_FOUND)
Added: trunk/qgis/src/plugins/raster_terrain_analysis/CMakeLists.txt
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/CMakeLists.txt (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/CMakeLists.txt 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,62 @@
+########################################################
+# Files
+
+SET (RASTER_TERRAIN_SRCS
+ qgsrasterterrainanalysisplugin.cpp
+ qgsninecellfilter.cpp
+ qgsruggednessfilter.cpp
+ qgsderivativefilter.cpp
+ qgsslopefilter.cpp
+ qgsaspectfilter.cpp
+ qgstotalcurvaturefilter.cpp
+ qgsrasterterrainanalysisdialog.cpp
+)
+
+SET (RASTER_TERRAIN_UIS
+ qgsrasterterrainanalysisdialogbase.ui
+ )
+
+SET (RASTER_TERRAIN_MOC_HDRS
+qgsrasterterrainanalysisdialog.h
+qgsrasterterrainanalysisplugin.h
+)
+
+SET (RASTER_TERRAIN_RCCS resources.qrc)
+########################################################
+# Build
+
+QT4_WRAP_UI (RASTER_TERRAIN_UIS_H ${RASTER_TERRAIN_UIS})
+
+QT4_WRAP_CPP (RASTER_TERRAIN_MOC_SRCS ${RASTER_TERRAIN_MOC_HDRS})
+
+QT4_ADD_RESOURCES(RASTER_TERRAIN_RCC_SRCS ${RASTER_TERRAIN_RCCS})
+
+ADD_LIBRARY (rasterterrainplugin MODULE
+ ${RASTER_TERRAIN_SRCS}
+ ${RASTER_TERRAIN_MOC_SRCS}
+ ${RASTER_TERRAIN_RCC_SRCS}
+ ${RASTER_TERRAIN_UIS_H})
+
+INCLUDE_DIRECTORIES(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${GDAL_INCLUDE_DIR}
+ ../../core
+ ../../core/raster
+ ../../gui
+ ..
+ .
+)
+
+TARGET_LINK_LIBRARIES(rasterterrainplugin
+ qgis_core
+ qgis_gui
+)
+
+
+########################################################
+# Install
+
+INSTALL(TARGETS rasterterrainplugin
+ RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
+ LIBRARY DESTINATION ${QGIS_PLUGIN_DIR}
+ )
Added: trunk/qgis/src/plugins/raster_terrain_analysis/Makefile
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/Makefile (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/Makefile 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,291 @@
+#############################################################################
+# Makefile for building: libraster_terrain_analysis.so.1.0.0
+# Generated by qmake (2.01a) (Qt 4.5.0) on: Fr. Aug 21 16:16:23 2009
+# Project: raster_terrain_analysis.pro
+# Template: lib
+# Command: /usr/bin/qmake-qt4 -unix -o Makefile raster_terrain_analysis.pro
+#############################################################################
+
+####### Compiler, tools and options
+
+CC = gcc
+CXX = g++
+DEFINES = -DGUI_EXPORT= -DCORE_EXPORT= -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
+CFLAGS = -pipe -g -D_REENTRANT -Wall -W -fPIC $(DEFINES)
+CXXFLAGS = -pipe -g -D_REENTRANT -Wall -W -fPIC $(DEFINES)
+INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I../../../include/qgis -I../../../../gdal-1.6.0/include -I. -I.
+LINK = g++
+LFLAGS = -shared -Wl,-soname,libraster_terrain_analysis.so.1
+LIBS = $(SUBLIBS) -L/usr/lib -L/home/marco/src/qgis/lib -L/home/marco/src/gdal-1.6.0/lib -lqgis_core -lqgis_gui -lgdal -lQtGui -lQtCore -lpthread
+AR = ar cqs
+RANLIB =
+QMAKE = /usr/bin/qmake-qt4
+TAR = tar -cf
+COMPRESS = gzip -9f
+COPY = cp -f
+SED = sed
+COPY_FILE = $(COPY)
+COPY_DIR = $(COPY) -r
+INSTALL_FILE = install -m 644 -p
+INSTALL_DIR = $(COPY_DIR)
+INSTALL_PROGRAM = install -m 755 -p
+DEL_FILE = rm -f
+SYMLINK = ln -sf
+DEL_DIR = rmdir
+MOVE = mv -f
+CHK_DIR_EXISTS= test -d
+MKDIR = mkdir -p
+
+####### Output directory
+
+OBJECTS_DIR = ./
+
+####### Files
+
+SOURCES = qgsrasterterrainanalysisplugin.cpp \
+ qgsninecellfilter.cpp \
+ qgsruggednessfilter.cpp \
+ qgsderivativefilter.cpp \
+ qgsslopefilter.cpp \
+ qgsaspectfilter.cpp \
+ qgstotalcurvaturefilter.cpp \
+ qgsrasterterrainanalysisdialog.cpp moc_qgsrasterterrainanalysisplugin.cpp \
+ moc_qgsrasterterrainanalysisdialog.cpp \
+ qrc_resources.cpp
+OBJECTS = qgsrasterterrainanalysisplugin.o \
+ qgsninecellfilter.o \
+ qgsruggednessfilter.o \
+ qgsderivativefilter.o \
+ qgsslopefilter.o \
+ qgsaspectfilter.o \
+ qgstotalcurvaturefilter.o \
+ qgsrasterterrainanalysisdialog.o \
+ moc_qgsrasterterrainanalysisplugin.o \
+ moc_qgsrasterterrainanalysisdialog.o \
+ qrc_resources.o
+DIST = /usr/share/qt4/mkspecs/common/g++.conf \
+ /usr/share/qt4/mkspecs/common/unix.conf \
+ /usr/share/qt4/mkspecs/common/linux.conf \
+ /usr/share/qt4/mkspecs/qconfig.pri \
+ /usr/share/qt4/mkspecs/features/qt_functions.prf \
+ /usr/share/qt4/mkspecs/features/qt_config.prf \
+ /usr/share/qt4/mkspecs/features/exclusive_builds.prf \
+ /usr/share/qt4/mkspecs/features/default_pre.prf \
+ /usr/share/qt4/mkspecs/features/debug.prf \
+ /usr/share/qt4/mkspecs/features/default_post.prf \
+ /usr/share/qt4/mkspecs/features/qt.prf \
+ /usr/share/qt4/mkspecs/features/unix/thread.prf \
+ /usr/share/qt4/mkspecs/features/moc.prf \
+ /usr/share/qt4/mkspecs/features/warn_on.prf \
+ /usr/share/qt4/mkspecs/features/resources.prf \
+ /usr/share/qt4/mkspecs/features/uic.prf \
+ /usr/share/qt4/mkspecs/features/yacc.prf \
+ /usr/share/qt4/mkspecs/features/lex.prf \
+ raster_terrain_analysis.pro
+QMAKE_TARGET = raster_terrain_analysis
+DESTDIR =
+TARGET = libraster_terrain_analysis.so.1.0.0
+TARGETA = libraster_terrain_analysis.a
+TARGETD = libraster_terrain_analysis.so.1.0.0
+TARGET0 = libraster_terrain_analysis.so
+TARGET1 = libraster_terrain_analysis.so.1
+TARGET2 = libraster_terrain_analysis.so.1.0
+
+first: all
+####### Implicit rules
+
+.SUFFIXES: .o .c .cpp .cc .cxx .C
+
+.cpp.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.cc.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.cxx.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.C.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.c.o:
+ $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
+
+####### Build rules
+
+all: Makefile $(TARGET)
+
+$(TARGET): ui_qgsrasterterrainanalysisdialogbase.h $(OBJECTS) $(SUBLIBS) $(OBJCOMP)
+ -$(DEL_FILE) $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2)
+ $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS) $(OBJCOMP)
+ -ln -s $(TARGET) $(TARGET0)
+ -ln -s $(TARGET) $(TARGET1)
+ -ln -s $(TARGET) $(TARGET2)
+
+
+
+staticlib: $(TARGETA)
+
+$(TARGETA): ui_qgsrasterterrainanalysisdialogbase.h $(OBJECTS) $(OBJCOMP)
+ -$(DEL_FILE) $(TARGETA)
+ $(AR) $(TARGETA) $(OBJECTS)
+
+Makefile: raster_terrain_analysis.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \
+ /usr/share/qt4/mkspecs/common/unix.conf \
+ /usr/share/qt4/mkspecs/common/linux.conf \
+ /usr/share/qt4/mkspecs/qconfig.pri \
+ /usr/share/qt4/mkspecs/features/qt_functions.prf \
+ /usr/share/qt4/mkspecs/features/qt_config.prf \
+ /usr/share/qt4/mkspecs/features/exclusive_builds.prf \
+ /usr/share/qt4/mkspecs/features/default_pre.prf \
+ /usr/share/qt4/mkspecs/features/debug.prf \
+ /usr/share/qt4/mkspecs/features/default_post.prf \
+ /usr/share/qt4/mkspecs/features/qt.prf \
+ /usr/share/qt4/mkspecs/features/unix/thread.prf \
+ /usr/share/qt4/mkspecs/features/moc.prf \
+ /usr/share/qt4/mkspecs/features/warn_on.prf \
+ /usr/share/qt4/mkspecs/features/resources.prf \
+ /usr/share/qt4/mkspecs/features/uic.prf \
+ /usr/share/qt4/mkspecs/features/yacc.prf \
+ /usr/share/qt4/mkspecs/features/lex.prf \
+ /usr/lib/libQtGui.prl \
+ /usr/lib/libQtCore.prl
+ $(QMAKE) -unix -o Makefile raster_terrain_analysis.pro
+/usr/share/qt4/mkspecs/common/g++.conf:
+/usr/share/qt4/mkspecs/common/unix.conf:
+/usr/share/qt4/mkspecs/common/linux.conf:
+/usr/share/qt4/mkspecs/qconfig.pri:
+/usr/share/qt4/mkspecs/features/qt_functions.prf:
+/usr/share/qt4/mkspecs/features/qt_config.prf:
+/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
+/usr/share/qt4/mkspecs/features/default_pre.prf:
+/usr/share/qt4/mkspecs/features/debug.prf:
+/usr/share/qt4/mkspecs/features/default_post.prf:
+/usr/share/qt4/mkspecs/features/qt.prf:
+/usr/share/qt4/mkspecs/features/unix/thread.prf:
+/usr/share/qt4/mkspecs/features/moc.prf:
+/usr/share/qt4/mkspecs/features/warn_on.prf:
+/usr/share/qt4/mkspecs/features/resources.prf:
+/usr/share/qt4/mkspecs/features/uic.prf:
+/usr/share/qt4/mkspecs/features/yacc.prf:
+/usr/share/qt4/mkspecs/features/lex.prf:
+/usr/lib/libQtGui.prl:
+/usr/lib/libQtCore.prl:
+qmake: FORCE
+ @$(QMAKE) -unix -o Makefile raster_terrain_analysis.pro
+
+dist:
+ @$(CHK_DIR_EXISTS) .tmp/raster_terrain_analysis1.0.0 || $(MKDIR) .tmp/raster_terrain_analysis1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/raster_terrain_analysis1.0.0/ && $(COPY_FILE) --parents qgsrasterterrainanalysisplugin.h qgsninecellfilter.h qgsruggednessfilter.h qgsderivativefilter.h qgsslopefilter.h qgsaspectfilter.h qgsrasterterrainanalysisdialog.h .tmp/raster_terrain_analysis1.0.0/ && $(COPY_FILE) --parents resources.qrc .tmp/raster_terrain_analysis1.0.0/ && $(COPY_FILE) --parents qgsrasterterrainanalysisplugin.cpp qgsninecellfilter.cpp qgsruggednessfilter.cpp qgsderivativefilter.cpp qgsslopefilter.cpp qgsaspectfilter.cpp qgstotalcurvaturefilter.cpp qgsrasterterrainanalysisdialog.cpp .tmp/raster_terrain_analysis1.0.0/ && $(COPY_FILE) --parents qgsrasterterrainanalysisdialogbase.ui .tmp/raster_terrain_analysis1.0.0/ && (cd `dirname .tmp/raster_terrain_analysis1.0.0` && $(TAR) raster_terrain_analysis1.0.0.tar raster_terrain_analysis1.0.0 && $(COMPRESS) raster_terrain_analysis1.0.0.tar) && $(MOVE) `dirname .tmp/raster_terrain_analysis1.0.0`/raster_terrain_analysis1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/raster_terrain_analysis1.0.0
+
+
+clean:compiler_clean
+ -$(DEL_FILE) $(OBJECTS)
+ -$(DEL_FILE) *~ core *.core
+
+
+####### Sub-libraries
+
+distclean: clean
+ -$(DEL_FILE) $(TARGET)
+ -$(DEL_FILE) $(TARGET0) $(TARGET1) $(TARGET2) $(TARGETA)
+ -$(DEL_FILE) Makefile
+
+
+mocclean: compiler_moc_header_clean compiler_moc_source_clean
+
+mocables: compiler_moc_header_make_all compiler_moc_source_make_all
+
+compiler_moc_header_make_all: moc_qgsrasterterrainanalysisplugin.cpp moc_qgsrasterterrainanalysisdialog.cpp
+compiler_moc_header_clean:
+ -$(DEL_FILE) moc_qgsrasterterrainanalysisplugin.cpp moc_qgsrasterterrainanalysisdialog.cpp
+moc_qgsrasterterrainanalysisplugin.cpp: qgsrasterterrainanalysisplugin.h
+ /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) qgsrasterterrainanalysisplugin.h -o moc_qgsrasterterrainanalysisplugin.cpp
+
+moc_qgsrasterterrainanalysisdialog.cpp: ui_qgsrasterterrainanalysisdialogbase.h \
+ qgsrasterterrainanalysisdialog.h
+ /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) qgsrasterterrainanalysisdialog.h -o moc_qgsrasterterrainanalysisdialog.cpp
+
+compiler_rcc_make_all: qrc_resources.cpp
+compiler_rcc_clean:
+ -$(DEL_FILE) qrc_resources.cpp
+qrc_resources.cpp: resources.qrc \
+ raster_terrain_icon.png
+ /usr/bin/rcc -name resources resources.qrc -o qrc_resources.cpp
+
+compiler_image_collection_make_all: qmake_image_collection.cpp
+compiler_image_collection_clean:
+ -$(DEL_FILE) qmake_image_collection.cpp
+compiler_moc_source_make_all:
+compiler_moc_source_clean:
+compiler_uic_make_all: ui_qgsrasterterrainanalysisdialogbase.h
+compiler_uic_clean:
+ -$(DEL_FILE) ui_qgsrasterterrainanalysisdialogbase.h
+ui_qgsrasterterrainanalysisdialogbase.h: qgsrasterterrainanalysisdialogbase.ui
+ /usr/bin/uic-qt4 qgsrasterterrainanalysisdialogbase.ui -o ui_qgsrasterterrainanalysisdialogbase.h
+
+compiler_yacc_decl_make_all:
+compiler_yacc_decl_clean:
+compiler_yacc_impl_make_all:
+compiler_yacc_impl_clean:
+compiler_lex_make_all:
+compiler_lex_clean:
+compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_uic_clean
+
+####### Compile
+
+qgsrasterterrainanalysisplugin.o: qgsrasterterrainanalysisplugin.cpp qgsrasterterrainanalysisplugin.h \
+ qgsaspectfilter.h \
+ qgsderivativefilter.h \
+ qgsninecellfilter.h \
+ qgsslopefilter.h \
+ qgsruggednessfilter.h \
+ qgsrasterterrainanalysisdialog.h \
+ ui_qgsrasterterrainanalysisdialogbase.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsrasterterrainanalysisplugin.o qgsrasterterrainanalysisplugin.cpp
+
+qgsninecellfilter.o: qgsninecellfilter.cpp qgsninecellfilter.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsninecellfilter.o qgsninecellfilter.cpp
+
+qgsruggednessfilter.o: qgsruggednessfilter.cpp qgsruggednessfilter.h \
+ qgsninecellfilter.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsruggednessfilter.o qgsruggednessfilter.cpp
+
+qgsderivativefilter.o: qgsderivativefilter.cpp qgsderivativefilter.h \
+ qgsninecellfilter.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsderivativefilter.o qgsderivativefilter.cpp
+
+qgsslopefilter.o: qgsslopefilter.cpp qgsslopefilter.h \
+ qgsderivativefilter.h \
+ qgsninecellfilter.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsslopefilter.o qgsslopefilter.cpp
+
+qgsaspectfilter.o: qgsaspectfilter.cpp qgsaspectfilter.h \
+ qgsderivativefilter.h \
+ qgsninecellfilter.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsaspectfilter.o qgsaspectfilter.cpp
+
+qgstotalcurvaturefilter.o: qgstotalcurvaturefilter.cpp qgstotalcurvaturefilter.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgstotalcurvaturefilter.o qgstotalcurvaturefilter.cpp
+
+qgsrasterterrainanalysisdialog.o: qgsrasterterrainanalysisdialog.cpp qgsrasterterrainanalysisdialog.h \
+ ui_qgsrasterterrainanalysisdialogbase.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsrasterterrainanalysisdialog.o qgsrasterterrainanalysisdialog.cpp
+
+moc_qgsrasterterrainanalysisplugin.o: moc_qgsrasterterrainanalysisplugin.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_qgsrasterterrainanalysisplugin.o moc_qgsrasterterrainanalysisplugin.cpp
+
+moc_qgsrasterterrainanalysisdialog.o: moc_qgsrasterterrainanalysisdialog.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_qgsrasterterrainanalysisdialog.o moc_qgsrasterterrainanalysisdialog.cpp
+
+qrc_resources.o: qrc_resources.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_resources.o qrc_resources.cpp
+
+####### Install
+
+install: FORCE
+
+uninstall: FORCE
+
+FORCE:
+
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.cpp (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.cpp 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,67 @@
+/***************************************************************************
+ 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 )
+ {
+ return mOutputNodataValue;
+ }
+
+ if ( derY < 0 && derX > 0 )
+ {
+ return 360 + ( atan( derX / derY ) * 180 / M_PI );
+ }
+ else if ( derY < 0 && derX < 0 )
+ {
+ return atan( derX / derY ) * 180 / M_PI;
+ }
+ else if ( derY > 0 )
+ {
+ return ( atan( derX / derY ) * 180 / M_PI ) + 180;
+ }
+ else if ( derX < 0 && derY == 0 )
+ {
+ return 90;
+ }
+ else if ( derX > 0 && derY == 0 )
+ {
+ return 270;
+ }
+ else if ( derX == 0 && derY == 0 )
+ {
+ return mOutputNodataValue;
+ }
+}
+
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.h (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsaspectfilter.h 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.cpp (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.cpp 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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 );
+}
+
+
+
+
+
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.h (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsderivativefilter.h 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.cpp (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.cpp 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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;
+}
+
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.h (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsninecellfilter.h 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.cpp 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,163 @@
+/***************************************************************************
+ qgsrasterterrainanalysisdialog.cpp - description
+ -------------------------------
+ begin : August 8th, 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 "qgsrasterterrainanalysisdialog.h"
+#include "qgsmaplayerregistry.h"
+#include "qgsrasterlayer.h"
+#include "cpl_string.h"
+#include "gdal.h"
+#include <QFileDialog>
+#include <QSettings>
+
+QgsRasterTerrainAnalysisDialog::QgsRasterTerrainAnalysisDialog( QgisInterface* iface, QWidget* parent ): QDialog( parent ), mIface( iface )
+{
+ setupUi( this );
+
+ //insert available methods
+ mAnalysisComboBox->addItem( tr( "Slope" ) );
+ mAnalysisComboBox->addItem( tr( "Aspect" ) );
+ mAnalysisComboBox->addItem( tr( "Ruggedness index" ) );
+ mAnalysisComboBox->addItem( tr( "Total curvature" ) );
+
+ //insert available raster layers
+ //enter available layers into the combo box
+ QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
+ QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin();
+
+ for ( ; layer_it != mapLayers.end(); ++layer_it )
+ {
+ QgsRasterLayer* rl = dynamic_cast<QgsRasterLayer*>( layer_it.value() );
+ if ( rl )
+ {
+ mInputLayerComboBox->addItem( rl->name(), QVariant( rl->getLayerID() ) );
+ }
+ }
+
+ //insert available drivers that support the create() operation
+ GDALAllRegister();
+
+ int nDrivers = GDALGetDriverCount();
+ for ( int i = 0; i < nDrivers; ++i )
+ {
+ GDALDriverH driver = GDALGetDriver( i );
+ if ( driver != NULL )
+ {
+ char** driverMetadata = GDALGetMetadata( driver, NULL );
+ if ( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, FALSE ) )
+ {
+ mOutputFormatComboBox->addItem( GDALGetDriverLongName( driver ), QVariant( GDALGetDriverShortName( driver ) ) );
+ }
+ }
+ }
+
+ //and set last used driver in combo box
+ QSettings s;
+ QString lastUsedDriver = s.value( "/RasterTerrainAnalysis/lastOutputFormat", "GeoTIFF" ).toString();
+ int lastDriverIndex = mOutputFormatComboBox->findText( lastUsedDriver );
+ if ( lastDriverIndex != -1 )
+ {
+ mOutputFormatComboBox->setCurrentIndex( lastDriverIndex );
+ }
+
+ QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
+ if ( okButton )
+ {
+ okButton->setEnabled( false );
+ }
+}
+
+QgsRasterTerrainAnalysisDialog::~QgsRasterTerrainAnalysisDialog()
+{
+
+}
+
+QString QgsRasterTerrainAnalysisDialog::selectedInputLayerId() const
+{
+ int index = mInputLayerComboBox->currentIndex();
+ if ( index == -1 )
+ {
+ return "";
+ }
+ return mInputLayerComboBox->itemData( index ).toString();
+}
+
+QString QgsRasterTerrainAnalysisDialog::selectedDriverKey() const
+{
+ int index = mOutputFormatComboBox->currentIndex();
+ if ( index == -1 )
+ {
+ return "";
+ }
+ return mOutputFormatComboBox->itemData( index ).toString();
+}
+
+QString QgsRasterTerrainAnalysisDialog::selectedOuputFilePath() const
+{
+ return mOutputLayerLineEdit->text();
+}
+
+bool QgsRasterTerrainAnalysisDialog::addLayerToProject() const
+{
+ if ( mAddResultToProjectCheckBox->checkState() == Qt::Checked )
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+void QgsRasterTerrainAnalysisDialog::on_mOutputLayerPushButton_clicked()
+{
+ QString saveFileName = QFileDialog::getSaveFileName( 0, tr( "Enter result file" ) );
+ if ( !saveFileName.isNull() )
+ {
+ mOutputLayerLineEdit->setText( saveFileName );
+ }
+}
+
+QString QgsRasterTerrainAnalysisDialog::selectedAnalysisMethod() const
+{
+ return mAnalysisComboBox->currentText();
+}
+
+void QgsRasterTerrainAnalysisDialog::on_mButtonBox_accepted()
+{
+ //save last output format
+ QSettings s;
+ s.setValue( "/RasterTerrainAnalysis/lastOutputFormat", QVariant( mOutputFormatComboBox->currentText() ) );
+}
+
+void QgsRasterTerrainAnalysisDialog::on_mOutputLayerLineEdit_textChanged( const QString& text )
+{
+ QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
+ if ( !okButton )
+ {
+ return;
+ }
+
+ QFileInfo fileInfo( text );
+ if ( mInputLayerComboBox->count() > 0 && fileInfo.dir().exists() )
+ {
+ okButton->setEnabled( true );
+ }
+ else
+ {
+ okButton->setEnabled( false );
+ }
+}
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.h (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialog.h 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,47 @@
+/***************************************************************************
+ qgsrasterterrainanalysisdialog.h - description
+ -----------------------------
+ begin : August 8th, 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 QGSRASTERTERRAINANALYSISDIALOG_H
+#define QGSRASTERTERRAINANALYSISDIALOG_H
+
+#include "ui_qgsrasterterrainanalysisdialogbase.h"
+
+class QgisInterface;
+
+class QgsRasterTerrainAnalysisDialog: public QDialog, private Ui::QgsRasterTerrainAnalysisDialogBase
+{
+ Q_OBJECT
+ public:
+ QgsRasterTerrainAnalysisDialog( QgisInterface* iface, QWidget* parent = 0 );
+ ~QgsRasterTerrainAnalysisDialog();
+
+ QString selectedInputLayerId() const;
+ QString selectedDriverKey() const;
+ QString selectedOuputFilePath() const;
+ QString selectedAnalysisMethod() const;
+ bool addLayerToProject() const;
+
+ private slots:
+ void on_mOutputLayerLineEdit_textChanged( const QString& text );
+ void on_mOutputLayerPushButton_clicked();
+ void on_mButtonBox_accepted();
+
+ private:
+ QgisInterface* mIface;
+};
+
+#endif // QGSRASTERTERRAINANALYSISDIALOG_H
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialogbase.ui
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialogbase.ui (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialogbase.ui 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,144 @@
+<ui version="4.0" >
+ <class>QgsRasterTerrainAnalysisDialogBase</class>
+ <widget class="QDialog" name="QgsRasterTerrainAnalysisDialogBase" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>355</width>
+ <height>318</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Raster based terrain analysis</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="0" >
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QLabel" name="mAnalysisLabel" >
+ <property name="text" >
+ <string>Analysis:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="mAnalysisComboBox" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="mInputLayerLabel" >
+ <property name="text" >
+ <string>Input layer:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QComboBox" name="mInputLayerComboBox" />
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="mOutputLayerLabel" >
+ <property name="text" >
+ <string>Output layer:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <item>
+ <widget class="QLineEdit" name="mOutputLayerLineEdit" />
+ </item>
+ <item>
+ <widget class="QPushButton" name="mOutputLayerPushButton" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize" >
+ <size>
+ <width>20</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text" >
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="5" column="0" >
+ <widget class="QLabel" name="mOutputFormatLabel" >
+ <property name="text" >
+ <string>Output format:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" >
+ <widget class="QComboBox" name="mOutputFormatComboBox" />
+ </item>
+ <item row="7" column="0" >
+ <widget class="QCheckBox" name="mAddResultToProjectCheckBox" >
+ <property name="text" >
+ <string>Add result to project</string>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="0" >
+ <widget class="QDialogButtonBox" name="mButtonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>mButtonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>QgsRasterTerrainAnalysisDialogBase</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>mButtonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>QgsRasterTerrainAnalysisDialogBase</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.cpp 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,155 @@
+/***************************************************************************
+ qgsrasterterrainanalysisplugin.cpp - 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 "qgsrasterterrainanalysisplugin.h"
+#include "qgis.h"
+#include "qgisinterface.h"
+#include "qgsmaplayer.h"
+#include "qgsmaplayerregistry.h"
+#include "qgsaspectfilter.h"
+#include "qgsslopefilter.h"
+#include "qgsruggednessfilter.h"
+#include "qgstotalcurvaturefilter.h"
+#include "qgsrasterterrainanalysisdialog.h"
+#include <QAction>
+#include <QProgressDialog>
+
+static const QString name_ = QObject::tr( "Raster Terrain Analysis plugin" );
+static const QString description_ = QObject::tr( "A plugin for raster based terrain analysis" );
+static const QString version_ = QObject::tr( "Version 0.1" );
+
+QgsRasterTerrainAnalysisPlugin::QgsRasterTerrainAnalysisPlugin( QgisInterface* iface ): mIface( iface ), mAction( 0 )
+{
+
+}
+
+QgsRasterTerrainAnalysisPlugin::~QgsRasterTerrainAnalysisPlugin()
+{
+
+}
+
+void QgsRasterTerrainAnalysisPlugin::initGui()
+{
+ //create Action
+ if ( mIface )
+ {
+ mAction = new QAction( QIcon( ":/raster/raster_terrain_icon.png" ), tr( "&Raster based terrain analysis..." ), 0 );
+ QObject::connect( mAction, SIGNAL( triggered() ), this, SLOT( run() ) );
+ mIface->addToolBarIcon( mAction );
+ mIface->addPluginToMenu( tr( "&Raster based terrain analysis..." ), mAction );
+ }
+}
+
+void QgsRasterTerrainAnalysisPlugin::unload()
+{
+ if ( mIface )
+ {
+ mIface->removePluginMenu( tr( "&Raster based terrain analysis..." ), mAction );
+ mIface ->removeToolBarIcon( mAction );
+ delete mAction;
+ }
+}
+
+void QgsRasterTerrainAnalysisPlugin::run()
+{
+ //testcode, remove it after debugging and show a dialog
+ //QgsRuggednessFilter r("/home/marco/geodaten/raster/albis/mmal25.agr", "/home/marco/tmp/ruggedtest.tif", "GTiff");
+ //QgsSlopeFilter slopeFilter("/home/marco/geodaten/raster/albis/mmal25.agr", "/home/marco/tmp/ruggedtest.tif", "GTiff");
+ //QgsAspectFilter aspectFilter("/home/marco/geodaten/raster/albis/mmal25.agr", "/home/marco/tmp/ruggedtest.tif", "GTiff");
+ //slopeFilter.processRaster(0);
+
+ QgsRasterTerrainAnalysisDialog d( mIface );
+ if ( d.exec() == QDialog::Accepted )
+ {
+ //get input layer from id
+ QString inputLayerId = d.selectedInputLayerId();
+ QgsMapLayer* inputLayer = QgsMapLayerRegistry::instance()->mapLayer( inputLayerId );
+ if ( !inputLayer )
+ {
+ return;
+ }
+ QString inputFilePath = inputLayer->source();
+
+ QString analysisMethod = d.selectedAnalysisMethod();
+ QString selectedFormat = d.selectedDriverKey();
+ QString outputFile = d.selectedOuputFilePath();
+ int returnValue;
+
+ QgsNineCellFilter* filter = 0;
+ if ( d.selectedAnalysisMethod() == tr( "Slope" ) )
+ {
+ filter = new QgsSlopeFilter( inputFilePath, outputFile, selectedFormat );
+ }
+ else if ( d.selectedAnalysisMethod() == tr( "Aspect" ) )
+ {
+ filter = new QgsAspectFilter( inputFilePath, outputFile, selectedFormat );
+ }
+ else if ( d.selectedAnalysisMethod() == tr( "Ruggedness index" ) )
+ {
+ filter = new QgsRuggednessFilter( inputFilePath, outputFile, selectedFormat );
+ }
+ else if ( d.selectedAnalysisMethod() == tr( "Total curvature" ) )
+ {
+ filter = new QgsTotalCurvatureFilter( inputFilePath, outputFile, selectedFormat );
+ }
+
+ if ( filter )
+ {
+ QProgressDialog p( tr( "Calculating " ) + d.selectedAnalysisMethod() + "...", tr( "Abort..." ), 0, 0 );
+ p.setWindowModality( Qt::WindowModal );
+ returnValue = filter->processRaster( &p );
+ delete filter;
+ if ( d.addLayerToProject() )
+ {
+ mIface->addRasterLayer( outputFile, d.selectedAnalysisMethod() );
+ }
+ }
+ }
+}
+
+//global methods for the plugin manager
+QGISEXTERN QgisPlugin* classFactory( QgisInterface * ifacePointer )
+{
+ return new QgsRasterTerrainAnalysisPlugin( ifacePointer );
+}
+
+QGISEXTERN QString name()
+{
+ return name_;
+}
+
+QGISEXTERN QString description()
+{
+ return description_;
+}
+
+QGISEXTERN QString version()
+{
+ return version_;
+}
+
+QGISEXTERN int type()
+{
+ return QgisPlugin::UI;
+}
+
+QGISEXTERN void unload( QgisPlugin* pluginPointer )
+{
+ delete pluginPointer;
+}
+
+
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.h (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisplugin.h 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,49 @@
+/***************************************************************************
+ qgsrasterterrainanalysisplugin.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 QGSRASTERTERRAINANALYSISPLUGIN_H
+#define QGSRASTERTERRAINANALYSISPLUGIN_H
+
+#include "qgisplugin.h"
+#include <QObject>
+
+class QgsInterface;
+class QAction;
+
+/**A plugin for raster based terrain analysis (e.g. slope, aspect, ruggedness)*/
+class QgsRasterTerrainAnalysisPlugin: public QObject, public QgisPlugin
+{
+ Q_OBJECT
+ public:
+ QgsRasterTerrainAnalysisPlugin( QgisInterface* iface );
+ ~QgsRasterTerrainAnalysisPlugin();
+
+ /**initialize connection to GUI*/
+ void initGui();
+ /**Unload the plugin and cleanup the GUI*/
+ void unload();
+
+ private slots:
+ /**Select input file, output file, format and analysis method*/
+ void run();
+
+ private:
+ QgisInterface* mIface;
+ QAction* mAction;
+};
+
+#endif // QGSRASTERTERRAINANALYSISPLUGIN_H
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.cpp (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.cpp 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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 );
+}
+
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.h (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessfilter.h 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessindex.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessindex.cpp (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsruggednessindex.cpp 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,19 @@
+/***************************************************************************
+ 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. *
+ * *
+ ***************************************************************************/
+
+#include "qgsruggednessindex.h"
+
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.cpp (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.cpp 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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;
+}
+
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.h (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgsslopefilter.h 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.cpp
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.cpp (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.cpp 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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;
+}
Added: trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.h (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/qgstotalcurvaturefilter.h 2009-08-26 12:28:15 UTC (rev 11510)
@@ -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
Added: trunk/qgis/src/plugins/raster_terrain_analysis/raster_terrain_icon.png
===================================================================
(Binary files differ)
Property changes on: trunk/qgis/src/plugins/raster_terrain_analysis/raster_terrain_icon.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/qgis/src/plugins/raster_terrain_analysis/resources.qrc
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/resources.qrc (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/resources.qrc 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,5 @@
+ <!DOCTYPE RCC><RCC version="1.0">
+ <qresource prefix="/raster">
+ <file>raster_terrain_icon.png</file>
+ </qresource>
+ </RCC>
\ No newline at end of file
Added: trunk/qgis/src/plugins/raster_terrain_analysis/ui_qgsrasterterrainanalysisdialogbase.h
===================================================================
--- trunk/qgis/src/plugins/raster_terrain_analysis/ui_qgsrasterterrainanalysisdialogbase.h (rev 0)
+++ trunk/qgis/src/plugins/raster_terrain_analysis/ui_qgsrasterterrainanalysisdialogbase.h 2009-08-26 12:28:15 UTC (rev 11510)
@@ -0,0 +1,162 @@
+/********************************************************************************
+** Form generated from reading ui file 'qgsrasterterrainanalysisdialogbase.ui'
+**
+** Created: Fri Aug 21 16:16:26 2009
+** by: Qt User Interface Compiler version 4.5.0
+**
+** WARNING! All changes made in this file will be lost when recompiling ui file!
+********************************************************************************/
+
+#ifndef UI_QGSRASTERTERRAINANALYSISDIALOGBASE_H
+#define UI_QGSRASTERTERRAINANALYSISDIALOGBASE_H
+
+#include <QtCore/QVariant>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QButtonGroup>
+#include <QtGui/QCheckBox>
+#include <QtGui/QComboBox>
+#include <QtGui/QDialog>
+#include <QtGui/QDialogButtonBox>
+#include <QtGui/QGridLayout>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QHeaderView>
+#include <QtGui/QLabel>
+#include <QtGui/QLineEdit>
+#include <QtGui/QPushButton>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_QgsRasterTerrainAnalysisDialogBase
+{
+ public:
+ QGridLayout *gridLayout;
+ QHBoxLayout *horizontalLayout;
+ QLabel *mAnalysisLabel;
+ QComboBox *mAnalysisComboBox;
+ QLabel *mInputLayerLabel;
+ QComboBox *mInputLayerComboBox;
+ QLabel *mOutputLayerLabel;
+ QHBoxLayout *horizontalLayout_2;
+ QLineEdit *mOutputLayerLineEdit;
+ QPushButton *mOutputLayerPushButton;
+ QLabel *mOutputFormatLabel;
+ QComboBox *mOutputFormatComboBox;
+ QCheckBox *mAddResultToProjectCheckBox;
+ QDialogButtonBox *mButtonBox;
+
+ void setupUi( QDialog *QgsRasterTerrainAnalysisDialogBase )
+ {
+ if ( QgsRasterTerrainAnalysisDialogBase->objectName().isEmpty() )
+ QgsRasterTerrainAnalysisDialogBase->setObjectName( QString::fromUtf8( "QgsRasterTerrainAnalysisDialogBase" ) );
+ QgsRasterTerrainAnalysisDialogBase->resize( 355, 318 );
+ gridLayout = new QGridLayout( QgsRasterTerrainAnalysisDialogBase );
+ gridLayout->setObjectName( QString::fromUtf8( "gridLayout" ) );
+ horizontalLayout = new QHBoxLayout();
+ horizontalLayout->setObjectName( QString::fromUtf8( "horizontalLayout" ) );
+ mAnalysisLabel = new QLabel( QgsRasterTerrainAnalysisDialogBase );
+ mAnalysisLabel->setObjectName( QString::fromUtf8( "mAnalysisLabel" ) );
+
+ horizontalLayout->addWidget( mAnalysisLabel );
+
+ mAnalysisComboBox = new QComboBox( QgsRasterTerrainAnalysisDialogBase );
+ mAnalysisComboBox->setObjectName( QString::fromUtf8( "mAnalysisComboBox" ) );
+ QSizePolicy sizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+ sizePolicy.setHorizontalStretch( 0 );
+ sizePolicy.setVerticalStretch( 0 );
+ sizePolicy.setHeightForWidth( mAnalysisComboBox->sizePolicy().hasHeightForWidth() );
+ mAnalysisComboBox->setSizePolicy( sizePolicy );
+
+ horizontalLayout->addWidget( mAnalysisComboBox );
+
+
+ gridLayout->addLayout( horizontalLayout, 0, 0, 1, 1 );
+
+ mInputLayerLabel = new QLabel( QgsRasterTerrainAnalysisDialogBase );
+ mInputLayerLabel->setObjectName( QString::fromUtf8( "mInputLayerLabel" ) );
+
+ gridLayout->addWidget( mInputLayerLabel, 1, 0, 1, 1 );
+
+ mInputLayerComboBox = new QComboBox( QgsRasterTerrainAnalysisDialogBase );
+ mInputLayerComboBox->setObjectName( QString::fromUtf8( "mInputLayerComboBox" ) );
+
+ gridLayout->addWidget( mInputLayerComboBox, 2, 0, 1, 1 );
+
+ mOutputLayerLabel = new QLabel( QgsRasterTerrainAnalysisDialogBase );
+ mOutputLayerLabel->setObjectName( QString::fromUtf8( "mOutputLayerLabel" ) );
+
+ gridLayout->addWidget( mOutputLayerLabel, 3, 0, 1, 1 );
+
+ horizontalLayout_2 = new QHBoxLayout();
+ horizontalLayout_2->setObjectName( QString::fromUtf8( "horizontalLayout_2" ) );
+ mOutputLayerLineEdit = new QLineEdit( QgsRasterTerrainAnalysisDialogBase );
+ mOutputLayerLineEdit->setObjectName( QString::fromUtf8( "mOutputLayerLineEdit" ) );
+
+ horizontalLayout_2->addWidget( mOutputLayerLineEdit );
+
+ mOutputLayerPushButton = new QPushButton( QgsRasterTerrainAnalysisDialogBase );
+ mOutputLayerPushButton->setObjectName( QString::fromUtf8( "mOutputLayerPushButton" ) );
+ QSizePolicy sizePolicy1( QSizePolicy::Preferred, QSizePolicy::Fixed );
+ sizePolicy1.setHorizontalStretch( 0 );
+ sizePolicy1.setVerticalStretch( 0 );
+ sizePolicy1.setHeightForWidth( mOutputLayerPushButton->sizePolicy().hasHeightForWidth() );
+ mOutputLayerPushButton->setSizePolicy( sizePolicy1 );
+ mOutputLayerPushButton->setMinimumSize( QSize( 20, 0 ) );
+
+ horizontalLayout_2->addWidget( mOutputLayerPushButton );
+
+
+ gridLayout->addLayout( horizontalLayout_2, 4, 0, 1, 1 );
+
+ mOutputFormatLabel = new QLabel( QgsRasterTerrainAnalysisDialogBase );
+ mOutputFormatLabel->setObjectName( QString::fromUtf8( "mOutputFormatLabel" ) );
+
+ gridLayout->addWidget( mOutputFormatLabel, 5, 0, 1, 1 );
+
+ mOutputFormatComboBox = new QComboBox( QgsRasterTerrainAnalysisDialogBase );
+ mOutputFormatComboBox->setObjectName( QString::fromUtf8( "mOutputFormatComboBox" ) );
+
+ gridLayout->addWidget( mOutputFormatComboBox, 6, 0, 1, 1 );
+
+ mAddResultToProjectCheckBox = new QCheckBox( QgsRasterTerrainAnalysisDialogBase );
+ mAddResultToProjectCheckBox->setObjectName( QString::fromUtf8( "mAddResultToProjectCheckBox" ) );
+
+ gridLayout->addWidget( mAddResultToProjectCheckBox, 7, 0, 1, 1 );
+
+ mButtonBox = new QDialogButtonBox( QgsRasterTerrainAnalysisDialogBase );
+ mButtonBox->setObjectName( QString::fromUtf8( "mButtonBox" ) );
+ mButtonBox->setOrientation( Qt::Horizontal );
+ mButtonBox->setStandardButtons( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
+
+ gridLayout->addWidget( mButtonBox, 8, 0, 1, 1 );
+
+
+ retranslateUi( QgsRasterTerrainAnalysisDialogBase );
+ QObject::connect( mButtonBox, SIGNAL( accepted() ), QgsRasterTerrainAnalysisDialogBase, SLOT( accept() ) );
+ QObject::connect( mButtonBox, SIGNAL( rejected() ), QgsRasterTerrainAnalysisDialogBase, SLOT( reject() ) );
+
+ QMetaObject::connectSlotsByName( QgsRasterTerrainAnalysisDialogBase );
+ } // setupUi
+
+ void retranslateUi( QDialog *QgsRasterTerrainAnalysisDialogBase )
+ {
+ QgsRasterTerrainAnalysisDialogBase->setWindowTitle( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Raster based terrain analysis", 0, QApplication::UnicodeUTF8 ) );
+ mAnalysisLabel->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Analysis:", 0, QApplication::UnicodeUTF8 ) );
+ mInputLayerLabel->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Input layer:", 0, QApplication::UnicodeUTF8 ) );
+ mOutputLayerLabel->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Output layer:", 0, QApplication::UnicodeUTF8 ) );
+ mOutputLayerPushButton->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "...", 0, QApplication::UnicodeUTF8 ) );
+ mOutputFormatLabel->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Output format:", 0, QApplication::UnicodeUTF8 ) );
+ mAddResultToProjectCheckBox->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Add result to project", 0, QApplication::UnicodeUTF8 ) );
+ Q_UNUSED( QgsRasterTerrainAnalysisDialogBase );
+ } // retranslateUi
+
+};
+
+namespace Ui
+{
+ class QgsRasterTerrainAnalysisDialogBase: public Ui_QgsRasterTerrainAnalysisDialogBase {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_QGSRASTERTERRAINANALYSISDIALOGBASE_H
More information about the QGIS-commit
mailing list