Skip to content

Commit d896eff

Browse files
author
mhugent
committedAug 26, 2009
[FEATURE] Add the raster terrain plugin that does calculate of slope, aspect, ruggedness, total curvature from raster layers
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11510 c8812cc2-4d05-0410-92ff-de0c093fc19c

25 files changed

+2058
-0
lines changed
 

‎src/plugins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SUBDIRS (copyright_label
44
north_arrow
55
scale_bar
66
oracle_raster
7+
raster_terrain_analysis
78
)
89

910
IF (POSTGRES_FOUND)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
########################################################
2+
# Files
3+
4+
SET (RASTER_TERRAIN_SRCS
5+
qgsrasterterrainanalysisplugin.cpp
6+
qgsninecellfilter.cpp
7+
qgsruggednessfilter.cpp
8+
qgsderivativefilter.cpp
9+
qgsslopefilter.cpp
10+
qgsaspectfilter.cpp
11+
qgstotalcurvaturefilter.cpp
12+
qgsrasterterrainanalysisdialog.cpp
13+
)
14+
15+
SET (RASTER_TERRAIN_UIS
16+
qgsrasterterrainanalysisdialogbase.ui
17+
)
18+
19+
SET (RASTER_TERRAIN_MOC_HDRS
20+
qgsrasterterrainanalysisdialog.h
21+
qgsrasterterrainanalysisplugin.h
22+
)
23+
24+
SET (RASTER_TERRAIN_RCCS resources.qrc)
25+
########################################################
26+
# Build
27+
28+
QT4_WRAP_UI (RASTER_TERRAIN_UIS_H ${RASTER_TERRAIN_UIS})
29+
30+
QT4_WRAP_CPP (RASTER_TERRAIN_MOC_SRCS ${RASTER_TERRAIN_MOC_HDRS})
31+
32+
QT4_ADD_RESOURCES(RASTER_TERRAIN_RCC_SRCS ${RASTER_TERRAIN_RCCS})
33+
34+
ADD_LIBRARY (rasterterrainplugin MODULE
35+
${RASTER_TERRAIN_SRCS}
36+
${RASTER_TERRAIN_MOC_SRCS}
37+
${RASTER_TERRAIN_RCC_SRCS}
38+
${RASTER_TERRAIN_UIS_H})
39+
40+
INCLUDE_DIRECTORIES(
41+
${CMAKE_CURRENT_BINARY_DIR}
42+
${GDAL_INCLUDE_DIR}
43+
../../core
44+
../../core/raster
45+
../../gui
46+
..
47+
.
48+
)
49+
50+
TARGET_LINK_LIBRARIES(rasterterrainplugin
51+
qgis_core
52+
qgis_gui
53+
)
54+
55+
56+
########################################################
57+
# Install
58+
59+
INSTALL(TARGETS rasterterrainplugin
60+
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
61+
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR}
62+
)
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
#############################################################################
2+
# Makefile for building: libraster_terrain_analysis.so.1.0.0
3+
# Generated by qmake (2.01a) (Qt 4.5.0) on: Fr. Aug 21 16:16:23 2009
4+
# Project: raster_terrain_analysis.pro
5+
# Template: lib
6+
# Command: /usr/bin/qmake-qt4 -unix -o Makefile raster_terrain_analysis.pro
7+
#############################################################################
8+
9+
####### Compiler, tools and options
10+
11+
CC = gcc
12+
CXX = g++
13+
DEFINES = -DGUI_EXPORT= -DCORE_EXPORT= -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
14+
CFLAGS = -pipe -g -D_REENTRANT -Wall -W -fPIC $(DEFINES)
15+
CXXFLAGS = -pipe -g -D_REENTRANT -Wall -W -fPIC $(DEFINES)
16+
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.
17+
LINK = g++
18+
LFLAGS = -shared -Wl,-soname,libraster_terrain_analysis.so.1
19+
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
20+
AR = ar cqs
21+
RANLIB =
22+
QMAKE = /usr/bin/qmake-qt4
23+
TAR = tar -cf
24+
COMPRESS = gzip -9f
25+
COPY = cp -f
26+
SED = sed
27+
COPY_FILE = $(COPY)
28+
COPY_DIR = $(COPY) -r
29+
INSTALL_FILE = install -m 644 -p
30+
INSTALL_DIR = $(COPY_DIR)
31+
INSTALL_PROGRAM = install -m 755 -p
32+
DEL_FILE = rm -f
33+
SYMLINK = ln -sf
34+
DEL_DIR = rmdir
35+
MOVE = mv -f
36+
CHK_DIR_EXISTS= test -d
37+
MKDIR = mkdir -p
38+
39+
####### Output directory
40+
41+
OBJECTS_DIR = ./
42+
43+
####### Files
44+
45+
SOURCES = qgsrasterterrainanalysisplugin.cpp \
46+
qgsninecellfilter.cpp \
47+
qgsruggednessfilter.cpp \
48+
qgsderivativefilter.cpp \
49+
qgsslopefilter.cpp \
50+
qgsaspectfilter.cpp \
51+
qgstotalcurvaturefilter.cpp \
52+
qgsrasterterrainanalysisdialog.cpp moc_qgsrasterterrainanalysisplugin.cpp \
53+
moc_qgsrasterterrainanalysisdialog.cpp \
54+
qrc_resources.cpp
55+
OBJECTS = qgsrasterterrainanalysisplugin.o \
56+
qgsninecellfilter.o \
57+
qgsruggednessfilter.o \
58+
qgsderivativefilter.o \
59+
qgsslopefilter.o \
60+
qgsaspectfilter.o \
61+
qgstotalcurvaturefilter.o \
62+
qgsrasterterrainanalysisdialog.o \
63+
moc_qgsrasterterrainanalysisplugin.o \
64+
moc_qgsrasterterrainanalysisdialog.o \
65+
qrc_resources.o
66+
DIST = /usr/share/qt4/mkspecs/common/g++.conf \
67+
/usr/share/qt4/mkspecs/common/unix.conf \
68+
/usr/share/qt4/mkspecs/common/linux.conf \
69+
/usr/share/qt4/mkspecs/qconfig.pri \
70+
/usr/share/qt4/mkspecs/features/qt_functions.prf \
71+
/usr/share/qt4/mkspecs/features/qt_config.prf \
72+
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
73+
/usr/share/qt4/mkspecs/features/default_pre.prf \
74+
/usr/share/qt4/mkspecs/features/debug.prf \
75+
/usr/share/qt4/mkspecs/features/default_post.prf \
76+
/usr/share/qt4/mkspecs/features/qt.prf \
77+
/usr/share/qt4/mkspecs/features/unix/thread.prf \
78+
/usr/share/qt4/mkspecs/features/moc.prf \
79+
/usr/share/qt4/mkspecs/features/warn_on.prf \
80+
/usr/share/qt4/mkspecs/features/resources.prf \
81+
/usr/share/qt4/mkspecs/features/uic.prf \
82+
/usr/share/qt4/mkspecs/features/yacc.prf \
83+
/usr/share/qt4/mkspecs/features/lex.prf \
84+
raster_terrain_analysis.pro
85+
QMAKE_TARGET = raster_terrain_analysis
86+
DESTDIR =
87+
TARGET = libraster_terrain_analysis.so.1.0.0
88+
TARGETA = libraster_terrain_analysis.a
89+
TARGETD = libraster_terrain_analysis.so.1.0.0
90+
TARGET0 = libraster_terrain_analysis.so
91+
TARGET1 = libraster_terrain_analysis.so.1
92+
TARGET2 = libraster_terrain_analysis.so.1.0
93+
94+
first: all
95+
####### Implicit rules
96+
97+
.SUFFIXES: .o .c .cpp .cc .cxx .C
98+
99+
.cpp.o:
100+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
101+
102+
.cc.o:
103+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
104+
105+
.cxx.o:
106+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
107+
108+
.C.o:
109+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
110+
111+
.c.o:
112+
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
113+
114+
####### Build rules
115+
116+
all: Makefile $(TARGET)
117+
118+
$(TARGET): ui_qgsrasterterrainanalysisdialogbase.h $(OBJECTS) $(SUBLIBS) $(OBJCOMP)
119+
-$(DEL_FILE) $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2)
120+
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS) $(OBJCOMP)
121+
-ln -s $(TARGET) $(TARGET0)
122+
-ln -s $(TARGET) $(TARGET1)
123+
-ln -s $(TARGET) $(TARGET2)
124+
125+
126+
127+
staticlib: $(TARGETA)
128+
129+
$(TARGETA): ui_qgsrasterterrainanalysisdialogbase.h $(OBJECTS) $(OBJCOMP)
130+
-$(DEL_FILE) $(TARGETA)
131+
$(AR) $(TARGETA) $(OBJECTS)
132+
133+
Makefile: raster_terrain_analysis.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \
134+
/usr/share/qt4/mkspecs/common/unix.conf \
135+
/usr/share/qt4/mkspecs/common/linux.conf \
136+
/usr/share/qt4/mkspecs/qconfig.pri \
137+
/usr/share/qt4/mkspecs/features/qt_functions.prf \
138+
/usr/share/qt4/mkspecs/features/qt_config.prf \
139+
/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
140+
/usr/share/qt4/mkspecs/features/default_pre.prf \
141+
/usr/share/qt4/mkspecs/features/debug.prf \
142+
/usr/share/qt4/mkspecs/features/default_post.prf \
143+
/usr/share/qt4/mkspecs/features/qt.prf \
144+
/usr/share/qt4/mkspecs/features/unix/thread.prf \
145+
/usr/share/qt4/mkspecs/features/moc.prf \
146+
/usr/share/qt4/mkspecs/features/warn_on.prf \
147+
/usr/share/qt4/mkspecs/features/resources.prf \
148+
/usr/share/qt4/mkspecs/features/uic.prf \
149+
/usr/share/qt4/mkspecs/features/yacc.prf \
150+
/usr/share/qt4/mkspecs/features/lex.prf \
151+
/usr/lib/libQtGui.prl \
152+
/usr/lib/libQtCore.prl
153+
$(QMAKE) -unix -o Makefile raster_terrain_analysis.pro
154+
/usr/share/qt4/mkspecs/common/g++.conf:
155+
/usr/share/qt4/mkspecs/common/unix.conf:
156+
/usr/share/qt4/mkspecs/common/linux.conf:
157+
/usr/share/qt4/mkspecs/qconfig.pri:
158+
/usr/share/qt4/mkspecs/features/qt_functions.prf:
159+
/usr/share/qt4/mkspecs/features/qt_config.prf:
160+
/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
161+
/usr/share/qt4/mkspecs/features/default_pre.prf:
162+
/usr/share/qt4/mkspecs/features/debug.prf:
163+
/usr/share/qt4/mkspecs/features/default_post.prf:
164+
/usr/share/qt4/mkspecs/features/qt.prf:
165+
/usr/share/qt4/mkspecs/features/unix/thread.prf:
166+
/usr/share/qt4/mkspecs/features/moc.prf:
167+
/usr/share/qt4/mkspecs/features/warn_on.prf:
168+
/usr/share/qt4/mkspecs/features/resources.prf:
169+
/usr/share/qt4/mkspecs/features/uic.prf:
170+
/usr/share/qt4/mkspecs/features/yacc.prf:
171+
/usr/share/qt4/mkspecs/features/lex.prf:
172+
/usr/lib/libQtGui.prl:
173+
/usr/lib/libQtCore.prl:
174+
qmake: FORCE
175+
@$(QMAKE) -unix -o Makefile raster_terrain_analysis.pro
176+
177+
dist:
178+
@$(CHK_DIR_EXISTS) .tmp/raster_terrain_analysis1.0.0 || $(MKDIR) .tmp/raster_terrain_analysis1.0.0
179+
$(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
180+
181+
182+
clean:compiler_clean
183+
-$(DEL_FILE) $(OBJECTS)
184+
-$(DEL_FILE) *~ core *.core
185+
186+
187+
####### Sub-libraries
188+
189+
distclean: clean
190+
-$(DEL_FILE) $(TARGET)
191+
-$(DEL_FILE) $(TARGET0) $(TARGET1) $(TARGET2) $(TARGETA)
192+
-$(DEL_FILE) Makefile
193+
194+
195+
mocclean: compiler_moc_header_clean compiler_moc_source_clean
196+
197+
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
198+
199+
compiler_moc_header_make_all: moc_qgsrasterterrainanalysisplugin.cpp moc_qgsrasterterrainanalysisdialog.cpp
200+
compiler_moc_header_clean:
201+
-$(DEL_FILE) moc_qgsrasterterrainanalysisplugin.cpp moc_qgsrasterterrainanalysisdialog.cpp
202+
moc_qgsrasterterrainanalysisplugin.cpp: qgsrasterterrainanalysisplugin.h
203+
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) qgsrasterterrainanalysisplugin.h -o moc_qgsrasterterrainanalysisplugin.cpp
204+
205+
moc_qgsrasterterrainanalysisdialog.cpp: ui_qgsrasterterrainanalysisdialogbase.h \
206+
qgsrasterterrainanalysisdialog.h
207+
/usr/bin/moc-qt4 $(DEFINES) $(INCPATH) qgsrasterterrainanalysisdialog.h -o moc_qgsrasterterrainanalysisdialog.cpp
208+
209+
compiler_rcc_make_all: qrc_resources.cpp
210+
compiler_rcc_clean:
211+
-$(DEL_FILE) qrc_resources.cpp
212+
qrc_resources.cpp: resources.qrc \
213+
raster_terrain_icon.png
214+
/usr/bin/rcc -name resources resources.qrc -o qrc_resources.cpp
215+
216+
compiler_image_collection_make_all: qmake_image_collection.cpp
217+
compiler_image_collection_clean:
218+
-$(DEL_FILE) qmake_image_collection.cpp
219+
compiler_moc_source_make_all:
220+
compiler_moc_source_clean:
221+
compiler_uic_make_all: ui_qgsrasterterrainanalysisdialogbase.h
222+
compiler_uic_clean:
223+
-$(DEL_FILE) ui_qgsrasterterrainanalysisdialogbase.h
224+
ui_qgsrasterterrainanalysisdialogbase.h: qgsrasterterrainanalysisdialogbase.ui
225+
/usr/bin/uic-qt4 qgsrasterterrainanalysisdialogbase.ui -o ui_qgsrasterterrainanalysisdialogbase.h
226+
227+
compiler_yacc_decl_make_all:
228+
compiler_yacc_decl_clean:
229+
compiler_yacc_impl_make_all:
230+
compiler_yacc_impl_clean:
231+
compiler_lex_make_all:
232+
compiler_lex_clean:
233+
compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_uic_clean
234+
235+
####### Compile
236+
237+
qgsrasterterrainanalysisplugin.o: qgsrasterterrainanalysisplugin.cpp qgsrasterterrainanalysisplugin.h \
238+
qgsaspectfilter.h \
239+
qgsderivativefilter.h \
240+
qgsninecellfilter.h \
241+
qgsslopefilter.h \
242+
qgsruggednessfilter.h \
243+
qgsrasterterrainanalysisdialog.h \
244+
ui_qgsrasterterrainanalysisdialogbase.h
245+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsrasterterrainanalysisplugin.o qgsrasterterrainanalysisplugin.cpp
246+
247+
qgsninecellfilter.o: qgsninecellfilter.cpp qgsninecellfilter.h
248+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsninecellfilter.o qgsninecellfilter.cpp
249+
250+
qgsruggednessfilter.o: qgsruggednessfilter.cpp qgsruggednessfilter.h \
251+
qgsninecellfilter.h
252+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsruggednessfilter.o qgsruggednessfilter.cpp
253+
254+
qgsderivativefilter.o: qgsderivativefilter.cpp qgsderivativefilter.h \
255+
qgsninecellfilter.h
256+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsderivativefilter.o qgsderivativefilter.cpp
257+
258+
qgsslopefilter.o: qgsslopefilter.cpp qgsslopefilter.h \
259+
qgsderivativefilter.h \
260+
qgsninecellfilter.h
261+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsslopefilter.o qgsslopefilter.cpp
262+
263+
qgsaspectfilter.o: qgsaspectfilter.cpp qgsaspectfilter.h \
264+
qgsderivativefilter.h \
265+
qgsninecellfilter.h
266+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsaspectfilter.o qgsaspectfilter.cpp
267+
268+
qgstotalcurvaturefilter.o: qgstotalcurvaturefilter.cpp qgstotalcurvaturefilter.h
269+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgstotalcurvaturefilter.o qgstotalcurvaturefilter.cpp
270+
271+
qgsrasterterrainanalysisdialog.o: qgsrasterterrainanalysisdialog.cpp qgsrasterterrainanalysisdialog.h \
272+
ui_qgsrasterterrainanalysisdialogbase.h
273+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qgsrasterterrainanalysisdialog.o qgsrasterterrainanalysisdialog.cpp
274+
275+
moc_qgsrasterterrainanalysisplugin.o: moc_qgsrasterterrainanalysisplugin.cpp
276+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_qgsrasterterrainanalysisplugin.o moc_qgsrasterterrainanalysisplugin.cpp
277+
278+
moc_qgsrasterterrainanalysisdialog.o: moc_qgsrasterterrainanalysisdialog.cpp
279+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_qgsrasterterrainanalysisdialog.o moc_qgsrasterterrainanalysisdialog.cpp
280+
281+
qrc_resources.o: qrc_resources.cpp
282+
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_resources.o qrc_resources.cpp
283+
284+
####### Install
285+
286+
install: FORCE
287+
288+
uninstall: FORCE
289+
290+
FORCE:
291+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/***************************************************************************
2+
qgsaspectfilter.cpp - description
3+
-----------------------------------
4+
begin : August 7th, 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 "qgsaspectfilter.h"
19+
20+
QgsAspectFilter::QgsAspectFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
21+
QgsDerivativeFilter( inputFile, outputFile, outputFormat )
22+
{
23+
24+
}
25+
26+
QgsAspectFilter::~QgsAspectFilter()
27+
{
28+
29+
}
30+
31+
float QgsAspectFilter::processNineCellWindow( float* x11, float* x21, float* x31, float* x12, float* x22, \
32+
float* x32, float* x13, float* x23, float* x33 )
33+
{
34+
float derX = calcFirstDerX( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
35+
float derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
36+
37+
if ( derX == mOutputNodataValue || derY == mOutputNodataValue )
38+
{
39+
return mOutputNodataValue;
40+
}
41+
42+
if ( derY < 0 && derX > 0 )
43+
{
44+
return 360 + ( atan( derX / derY ) * 180 / M_PI );
45+
}
46+
else if ( derY < 0 && derX < 0 )
47+
{
48+
return atan( derX / derY ) * 180 / M_PI;
49+
}
50+
else if ( derY > 0 )
51+
{
52+
return ( atan( derX / derY ) * 180 / M_PI ) + 180;
53+
}
54+
else if ( derX < 0 && derY == 0 )
55+
{
56+
return 90;
57+
}
58+
else if ( derX > 0 && derY == 0 )
59+
{
60+
return 270;
61+
}
62+
else if ( derX == 0 && derY == 0 )
63+
{
64+
return mOutputNodataValue;
65+
}
66+
}
67+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/***************************************************************************
2+
qgsaspectfilter.h - description
3+
---------------------------------
4+
begin : August 7th, 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+
#ifndef QGSASPECTFILTER_H
19+
#define QGSASPECTFILTER_H
20+
21+
#include "qgsderivativefilter.h"
22+
23+
/**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*/
24+
class QgsAspectFilter: public QgsDerivativeFilter
25+
{
26+
public:
27+
QgsAspectFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
28+
~QgsAspectFilter();
29+
30+
protected:
31+
protected:
32+
/**Calculates output value from nine input values. The input values and the output value can be equal to the \
33+
nodata value if not present or outside of the border. Must be implemented by subclasses*/
34+
float processNineCellWindow( float* x11, float* x21, float* x31, \
35+
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
36+
};
37+
38+
#endif // QGSASPECTFILTER_H
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/***************************************************************************
2+
qgsderivativefilter.cpp - description
3+
-----------------------
4+
begin : August 7th, 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 "qgsderivativefilter.h"
19+
20+
QgsDerivativeFilter::QgsDerivativeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
21+
QgsNineCellFilter( inputFile, outputFile, outputFormat )
22+
{
23+
24+
}
25+
26+
QgsDerivativeFilter::~QgsDerivativeFilter()
27+
{
28+
29+
}
30+
31+
float QgsDerivativeFilter::calcFirstDerX( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
32+
{
33+
//the basic formula would be simple, but we need to test for nodata values...
34+
//return (( (*x31 - *x11) + 2 * (*x32 - *x12) + (*x33 - *x13) ) / (8 * mCellSizeX));
35+
36+
int weight = 0;
37+
double sum = 0;
38+
39+
//first row
40+
if ( *x31 != mInputNodataValue && *x11 != mInputNodataValue ) //the normal case
41+
{
42+
sum += ( *x31 - *x11 );
43+
weight += 2;
44+
}
45+
else if ( *x31 == mInputNodataValue && *x11 != mInputNodataValue && *x21 != mInputNodataValue ) //probably 3x3 window is at the border
46+
{
47+
sum += ( *x21 - *x11 );
48+
weight += 1;
49+
}
50+
else if ( *x11 == mInputNodataValue && *x31 != mInputNodataValue && *x21 != mInputNodataValue ) //probably 3x3 window is at the border
51+
{
52+
sum += ( *x31 - *x21 );
53+
weight += 1;
54+
}
55+
56+
//second row
57+
if ( *x32 != mInputNodataValue && *x12 != mInputNodataValue ) //the normal case
58+
{
59+
sum += 2 * ( *x32 - *x12 );
60+
weight += 4;
61+
}
62+
else if ( *x32 == mInputNodataValue && *x12 != mInputNodataValue && *x22 != mInputNodataValue )
63+
{
64+
sum += 2 * ( *x22 - *x12 );
65+
weight += 2;
66+
}
67+
else if ( *x12 == mInputNodataValue && *x32 != mInputNodataValue && *x22 != mInputNodataValue )
68+
{
69+
sum += 2 * ( *x32 - *x22 );
70+
weight += 2;
71+
}
72+
73+
//third row
74+
if ( *x33 != mInputNodataValue && *x13 != mInputNodataValue ) //the normal case
75+
{
76+
sum += ( *x33 - *x13 );
77+
weight += 2;
78+
}
79+
else if ( *x33 == mInputNodataValue && *x13 != mInputNodataValue && *x23 != mInputNodataValue )
80+
{
81+
sum += ( *x23 - *x13 );
82+
weight += 1;
83+
}
84+
else if ( *x13 == mInputNodataValue && *x33 != mInputNodataValue && *x23 != mInputNodataValue )
85+
{
86+
sum += ( *x33 - *x23 );
87+
weight += 1;
88+
}
89+
90+
if ( weight == 0 )
91+
{
92+
return mOutputNodataValue;
93+
}
94+
95+
return sum / ( weight * mCellSizeX );
96+
}
97+
98+
float QgsDerivativeFilter::calcFirstDerY( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
99+
{
100+
//the basic formula would be simple, but we need to test for nodata values...
101+
//return (((*x11 - *x13) + 2 * (*x21 - *x23) + (*x31 - *x33)) / ( 8 * mCellSizeY));
102+
103+
double sum = 0;
104+
int weight = 0;
105+
106+
//first row
107+
if ( *x11 != mInputNodataValue && *x13 != mInputNodataValue ) //normal case
108+
{
109+
sum += ( *x11 - *x13 );
110+
weight += 2;
111+
}
112+
else if ( *x11 == mInputNodataValue && *x13 != mInputNodataValue && *x12 != mInputNodataValue )
113+
{
114+
sum += ( *x12 - *x13 );
115+
weight += 1;
116+
}
117+
else if ( *x31 == mInputNodataValue && *x11 != mInputNodataValue && *x12 != mInputNodataValue )
118+
{
119+
sum += ( *x11 - *x12 );
120+
weight += 1;
121+
}
122+
123+
//second row
124+
if ( *x21 != mInputNodataValue && *x23 != mInputNodataValue )
125+
{
126+
sum += 2 * ( *x21 - *x23 );
127+
weight += 4;
128+
}
129+
else if ( *x21 == mInputNodataValue && *x23 != mInputNodataValue && *x22 != mInputNodataValue )
130+
{
131+
sum += 2 * ( *x22 - *x23 );
132+
weight += 2;
133+
}
134+
else if ( *x23 == mInputNodataValue && *x21 != mInputNodataValue && *x22 != mInputNodataValue )
135+
{
136+
sum += 2 * ( *x21 - *x22 );
137+
weight += 2;
138+
}
139+
140+
//third row
141+
if ( *x31 != mInputNodataValue && *x33 != mInputNodataValue )
142+
{
143+
sum += ( *x31 - *x33 );
144+
weight += 2;
145+
}
146+
else if ( *x31 == mInputNodataValue && *x33 != mInputNodataValue && *x32 != mInputNodataValue )
147+
{
148+
sum += ( *x32 - *x33 );
149+
weight += 1;
150+
}
151+
else if ( *x33 == mInputNodataValue && *x31 != mInputNodataValue && *x32 != mInputNodataValue )
152+
{
153+
sum += ( *x31 - *x32 );
154+
weight += 1;
155+
}
156+
157+
if ( weight == 0 )
158+
{
159+
return mOutputNodataValue;
160+
}
161+
162+
return sum / ( weight * mCellSizeY );
163+
}
164+
165+
166+
167+
168+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************
2+
qgsderivativefilter.h - description
3+
---------------------
4+
begin : August 7th, 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+
#ifndef QGSDERIVATIVEFILTER_H
19+
#define QGSDERIVATIVEFILTER_H
20+
21+
#include "qgsninecellfilter.h"
22+
23+
/**Adds the ability to calculate derivatives in x- and y-directions. Needs to be subclassed (e.g. for slope and aspect)*/
24+
class QgsDerivativeFilter: public QgsNineCellFilter
25+
{
26+
public:
27+
QgsDerivativeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
28+
virtual ~QgsDerivativeFilter();
29+
//to be implemented by subclasses
30+
virtual float processNineCellWindow( float* x11, float* x21, float* x31, float* x12, float* x22, \
31+
float* x32, float* x13, float* x23, float* x33 ) = 0;
32+
33+
protected:
34+
/**Calculates the first order derivative in x-direction according to Horn (1981)*/
35+
float calcFirstDerX( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
36+
/**Calculates the first order derivative in y-direction according to Horn (1981)*/
37+
float calcFirstDerY( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
38+
};
39+
40+
#endif // QGSDERIVATIVEFILTER_H
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
/***************************************************************************
2+
qgsninecellfilter.h - 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 "qgsninecellfilter.h"
19+
#include "cpl_string.h"
20+
#include <QProgressDialog>
21+
22+
23+
QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
24+
mInputFile( inputFile ), mOutputFile( outputFile ), mOutputFormat( outputFormat ), mCellSizeX( -1 ), mCellSizeY( -1 ), mInputNodataValue( -1 ), mOutputNodataValue( -1 )
25+
{
26+
27+
}
28+
29+
QgsNineCellFilter::QgsNineCellFilter()
30+
{
31+
32+
}
33+
34+
QgsNineCellFilter::~QgsNineCellFilter()
35+
{
36+
37+
}
38+
39+
int QgsNineCellFilter::processRaster( QProgressDialog* p )
40+
{
41+
GDALAllRegister();
42+
43+
//open input file
44+
int xSize, ySize;
45+
GDALDatasetH inputDataset = openInputFile( xSize, ySize );
46+
if ( inputDataset == NULL )
47+
{
48+
return 1; //opening of input file failed
49+
}
50+
51+
//output driver
52+
GDALDriverH outputDriver = openOutputDriver();
53+
if ( outputDriver == 0 )
54+
{
55+
return 2;
56+
}
57+
58+
GDALDatasetH outputDataset = openOutputFile( inputDataset, outputDriver );
59+
if ( outputDataset == NULL )
60+
{
61+
return 3; //create operation on output file failed
62+
}
63+
64+
//open first raster band for reading (operation is only for single band raster)
65+
GDALRasterBandH rasterBand = GDALGetRasterBand( inputDataset, 1 );
66+
if ( rasterBand == NULL )
67+
{
68+
GDALClose( inputDataset );
69+
GDALClose( outputDataset );
70+
return 4;
71+
}
72+
mInputNodataValue = GDALGetRasterNoDataValue( rasterBand, NULL );
73+
74+
GDALRasterBandH outputRasterBand = GDALGetRasterBand( outputDataset, 1 );
75+
if ( outputRasterBand == NULL )
76+
{
77+
GDALClose( inputDataset );
78+
GDALClose( outputDataset );
79+
return 5;
80+
}
81+
//try to set -9999 as nodata value
82+
GDALSetRasterNoDataValue( outputRasterBand, -9999 );
83+
mOutputNodataValue = GDALGetRasterNoDataValue( outputRasterBand, NULL );
84+
85+
if ( ySize < 3 ) //we require at least three rows (should be true for most datasets)
86+
{
87+
GDALClose( inputDataset );
88+
GDALClose( outputDataset );
89+
return 6;
90+
}
91+
92+
//keep only three scanlines in memory at a time
93+
float* scanLine1 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
94+
float* scanLine2 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
95+
float* scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
96+
97+
float* resultLine = ( float * ) CPLMalloc( sizeof( float ) * xSize );
98+
99+
if ( p )
100+
{
101+
p->setMaximum( ySize );
102+
}
103+
104+
//values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
105+
for ( int i = 0; i < ySize; ++i )
106+
{
107+
if ( p )
108+
{
109+
p->setValue( i );
110+
}
111+
112+
if ( p && p->wasCanceled() )
113+
{
114+
break;
115+
}
116+
117+
if ( i == 0 )
118+
{
119+
//fill scanline 1 with (input) nodata for the values above the first row and feed scanline2 with the first row
120+
for ( int a = 0; a < xSize; ++a )
121+
{
122+
scanLine1[a] = mInputNodataValue;
123+
}
124+
GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, scanLine2, xSize, 1, GDT_Float32, 0, 0 );
125+
}
126+
else
127+
{
128+
//normally fetch only scanLine3 and release scanline 1 if we move forward one row
129+
CPLFree( scanLine1 );
130+
scanLine1 = scanLine2;
131+
scanLine2 = scanLine3;
132+
scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * xSize );
133+
}
134+
135+
if ( i == ySize - 1 ) //fill the row below the bottom with nodata values
136+
{
137+
for ( int a = 0; a < xSize; ++a )
138+
{
139+
scanLine3[a] = mInputNodataValue;
140+
}
141+
}
142+
else
143+
{
144+
GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, scanLine3, xSize, 1, GDT_Float32, 0, 0 );
145+
}
146+
147+
for ( int j = 0; j < xSize; ++j )
148+
{
149+
if ( j == 0 )
150+
{
151+
resultLine[j] = processNineCellWindow( &mInputNodataValue, &scanLine1[j], &scanLine1[j+1], &mInputNodataValue, &scanLine2[j], \
152+
&scanLine2[j+1], &mInputNodataValue, &scanLine3[j], &scanLine3[j+1] );
153+
}
154+
else if ( j == xSize - 1 )
155+
{
156+
resultLine[j] = processNineCellWindow( &scanLine1[j-1], &scanLine1[j], &mInputNodataValue, &scanLine2[j-1], &scanLine2[j], \
157+
&mInputNodataValue, &scanLine3[j-1], &scanLine3[j], &mInputNodataValue );
158+
}
159+
else
160+
{
161+
resultLine[j] = processNineCellWindow( &scanLine1[j-1], &scanLine1[j], &scanLine1[j+1], &scanLine2[j-1], &scanLine2[j], \
162+
&scanLine2[j+1], &scanLine3[j-1], &scanLine3[j], &scanLine3[j+1] );
163+
}
164+
}
165+
166+
GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 );
167+
}
168+
169+
if ( p )
170+
{
171+
p->setValue( ySize );
172+
}
173+
174+
CPLFree( resultLine );
175+
CPLFree( scanLine1 );
176+
CPLFree( scanLine2 );
177+
CPLFree( scanLine3 );
178+
179+
GDALClose( inputDataset );
180+
181+
if ( p && p->wasCanceled() )
182+
{
183+
//delete the dataset without closing (because it is faster)
184+
GDALDeleteDataset( outputDriver, mOutputFile.toLocal8Bit().data() );
185+
return 7;
186+
}
187+
GDALClose( outputDataset );
188+
189+
return 0;
190+
}
191+
192+
GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
193+
{
194+
GDALDatasetH inputDataset = GDALOpen( mInputFile.toLocal8Bit().data(), GA_ReadOnly );
195+
if ( inputDataset != NULL )
196+
{
197+
nCellsX = GDALGetRasterXSize( inputDataset );
198+
nCellsY = GDALGetRasterYSize( inputDataset );
199+
200+
//we need at least one band
201+
if ( GDALGetRasterCount( inputDataset ) < 1 )
202+
{
203+
GDALClose( inputDataset );
204+
return NULL;
205+
}
206+
}
207+
return inputDataset;
208+
}
209+
210+
GDALDriverH QgsNineCellFilter::openOutputDriver()
211+
{
212+
char **driverMetadata;
213+
214+
//open driver
215+
GDALDriverH outputDriver = GDALGetDriverByName( mOutputFormat.toLocal8Bit().data() );
216+
217+
if ( outputDriver == NULL )
218+
{
219+
return outputDriver; //return NULL, driver does not exist
220+
}
221+
222+
driverMetadata = GDALGetMetadata( outputDriver, NULL );
223+
if ( !CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, FALSE ) )
224+
{
225+
return NULL; //driver exist, but it does not support the create operation
226+
}
227+
228+
return outputDriver;
229+
}
230+
231+
GDALDatasetH QgsNineCellFilter::openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver )
232+
{
233+
if ( inputDataset == NULL )
234+
{
235+
return NULL;
236+
}
237+
238+
int xSize = GDALGetRasterXSize( inputDataset );
239+
int ySize = GDALGetRasterYSize( inputDataset );;
240+
241+
//open output file
242+
char **papszOptions = NULL;
243+
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), xSize, ySize, 1, GDT_Float32, papszOptions );
244+
if ( outputDataset == NULL )
245+
{
246+
return outputDataset;
247+
}
248+
249+
//get geotransform from inputDataset
250+
double geotransform[6];
251+
if ( GDALGetGeoTransform( inputDataset, geotransform ) != CE_None )
252+
{
253+
GDALClose( outputDataset );
254+
return NULL;
255+
}
256+
GDALSetGeoTransform( outputDataset, geotransform );
257+
258+
//make sure mCellSizeX and mCellSizeY are always > 0
259+
mCellSizeX = geotransform[1];
260+
if ( mCellSizeX < 0 )
261+
{
262+
mCellSizeX = -mCellSizeX;
263+
}
264+
mCellSizeY = geotransform[5];
265+
if ( mCellSizeY < 0 )
266+
{
267+
mCellSizeY = -mCellSizeY;
268+
}
269+
270+
const char* projection = GDALGetProjectionRef( inputDataset );
271+
GDALSetProjection( outputDataset, projection );
272+
273+
return outputDataset;
274+
}
275+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/***************************************************************************
2+
qgsninecellfilter.h - 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+
#ifndef QGSNINECELLFILTER_H
19+
#define QGSNINECELLFILTER_H
20+
21+
#include <QString>
22+
#include "gdal.h"
23+
24+
class QProgressDialog;
25+
26+
/**Base class for raster analysis methods that work with a 3x3 cell filter and calculate the value of each cell based on \
27+
the cell value and the eight neighbour cells. Common examples are slope and aspect calculation in DEMs. Subclasses only implement \
28+
the method that calculates the new value from the nine values. Everything else (reading file, writing file) is done by this subclass*/
29+
30+
class QgsNineCellFilter
31+
{
32+
public:
33+
/**Constructor that takes input file, output file and output format (GDAL string)*/
34+
QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
35+
virtual ~QgsNineCellFilter();
36+
/**Starts the calculation, reads from mInputFile and stores the result in mOutputFile
37+
@param p progress dialog that receives update and that is checked for abort. 0 if no progress bar is needed.
38+
@return 0 in case of success*/
39+
int processRaster( QProgressDialog* p );
40+
41+
private:
42+
//default constructor forbidden. We need input file, output file and format obligatory
43+
QgsNineCellFilter();
44+
45+
/**Opens the input file and returns the dataset handle and the number of pixels in x-/y- direction*/
46+
GDALDatasetH openInputFile( int& nCellsX, int& nCellsY );
47+
/**Opens the output driver and tests if it supports the creation of a new dataset
48+
@return NULL on error and the driver handle on success*/
49+
GDALDriverH openOutputDriver();
50+
/**Opens the output file and sets the same geotransform and CRS as the input data
51+
@return the output dataset or NULL in case of error*/
52+
GDALDatasetH openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver );
53+
54+
protected:
55+
/**Calculates output value from nine input values. The input values and the output value can be equal to the \
56+
nodata value if not present or outside of the border. Must be implemented by subclasses*/
57+
virtual float processNineCellWindow( float* x11, float* x21, float* x31, \
58+
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 ) = 0;
59+
60+
QString mInputFile;
61+
QString mOutputFile;
62+
QString mOutputFormat;
63+
64+
double mCellSizeX;
65+
double mCellSizeY;
66+
/**The nodata value of the input layer*/
67+
float mInputNodataValue;
68+
/**The nodata value of the output layer*/
69+
float mOutputNodataValue;
70+
};
71+
72+
#endif // QGSNINECELLFILTER_H
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/***************************************************************************
2+
qgsrasterterrainanalysisdialog.cpp - description
3+
-------------------------------
4+
begin : August 8th, 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 "qgsrasterterrainanalysisdialog.h"
19+
#include "qgsmaplayerregistry.h"
20+
#include "qgsrasterlayer.h"
21+
#include "cpl_string.h"
22+
#include "gdal.h"
23+
#include <QFileDialog>
24+
#include <QSettings>
25+
26+
QgsRasterTerrainAnalysisDialog::QgsRasterTerrainAnalysisDialog( QgisInterface* iface, QWidget* parent ): QDialog( parent ), mIface( iface )
27+
{
28+
setupUi( this );
29+
30+
//insert available methods
31+
mAnalysisComboBox->addItem( tr( "Slope" ) );
32+
mAnalysisComboBox->addItem( tr( "Aspect" ) );
33+
mAnalysisComboBox->addItem( tr( "Ruggedness index" ) );
34+
mAnalysisComboBox->addItem( tr( "Total curvature" ) );
35+
36+
//insert available raster layers
37+
//enter available layers into the combo box
38+
QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
39+
QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin();
40+
41+
for ( ; layer_it != mapLayers.end(); ++layer_it )
42+
{
43+
QgsRasterLayer* rl = dynamic_cast<QgsRasterLayer*>( layer_it.value() );
44+
if ( rl )
45+
{
46+
mInputLayerComboBox->addItem( rl->name(), QVariant( rl->getLayerID() ) );
47+
}
48+
}
49+
50+
//insert available drivers that support the create() operation
51+
GDALAllRegister();
52+
53+
int nDrivers = GDALGetDriverCount();
54+
for ( int i = 0; i < nDrivers; ++i )
55+
{
56+
GDALDriverH driver = GDALGetDriver( i );
57+
if ( driver != NULL )
58+
{
59+
char** driverMetadata = GDALGetMetadata( driver, NULL );
60+
if ( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, FALSE ) )
61+
{
62+
mOutputFormatComboBox->addItem( GDALGetDriverLongName( driver ), QVariant( GDALGetDriverShortName( driver ) ) );
63+
}
64+
}
65+
}
66+
67+
//and set last used driver in combo box
68+
QSettings s;
69+
QString lastUsedDriver = s.value( "/RasterTerrainAnalysis/lastOutputFormat", "GeoTIFF" ).toString();
70+
int lastDriverIndex = mOutputFormatComboBox->findText( lastUsedDriver );
71+
if ( lastDriverIndex != -1 )
72+
{
73+
mOutputFormatComboBox->setCurrentIndex( lastDriverIndex );
74+
}
75+
76+
QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
77+
if ( okButton )
78+
{
79+
okButton->setEnabled( false );
80+
}
81+
}
82+
83+
QgsRasterTerrainAnalysisDialog::~QgsRasterTerrainAnalysisDialog()
84+
{
85+
86+
}
87+
88+
QString QgsRasterTerrainAnalysisDialog::selectedInputLayerId() const
89+
{
90+
int index = mInputLayerComboBox->currentIndex();
91+
if ( index == -1 )
92+
{
93+
return "";
94+
}
95+
return mInputLayerComboBox->itemData( index ).toString();
96+
}
97+
98+
QString QgsRasterTerrainAnalysisDialog::selectedDriverKey() const
99+
{
100+
int index = mOutputFormatComboBox->currentIndex();
101+
if ( index == -1 )
102+
{
103+
return "";
104+
}
105+
return mOutputFormatComboBox->itemData( index ).toString();
106+
}
107+
108+
QString QgsRasterTerrainAnalysisDialog::selectedOuputFilePath() const
109+
{
110+
return mOutputLayerLineEdit->text();
111+
}
112+
113+
bool QgsRasterTerrainAnalysisDialog::addLayerToProject() const
114+
{
115+
if ( mAddResultToProjectCheckBox->checkState() == Qt::Checked )
116+
{
117+
return true;
118+
}
119+
else
120+
{
121+
return false;
122+
}
123+
}
124+
125+
void QgsRasterTerrainAnalysisDialog::on_mOutputLayerPushButton_clicked()
126+
{
127+
QString saveFileName = QFileDialog::getSaveFileName( 0, tr( "Enter result file" ) );
128+
if ( !saveFileName.isNull() )
129+
{
130+
mOutputLayerLineEdit->setText( saveFileName );
131+
}
132+
}
133+
134+
QString QgsRasterTerrainAnalysisDialog::selectedAnalysisMethod() const
135+
{
136+
return mAnalysisComboBox->currentText();
137+
}
138+
139+
void QgsRasterTerrainAnalysisDialog::on_mButtonBox_accepted()
140+
{
141+
//save last output format
142+
QSettings s;
143+
s.setValue( "/RasterTerrainAnalysis/lastOutputFormat", QVariant( mOutputFormatComboBox->currentText() ) );
144+
}
145+
146+
void QgsRasterTerrainAnalysisDialog::on_mOutputLayerLineEdit_textChanged( const QString& text )
147+
{
148+
QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
149+
if ( !okButton )
150+
{
151+
return;
152+
}
153+
154+
QFileInfo fileInfo( text );
155+
if ( mInputLayerComboBox->count() > 0 && fileInfo.dir().exists() )
156+
{
157+
okButton->setEnabled( true );
158+
}
159+
else
160+
{
161+
okButton->setEnabled( false );
162+
}
163+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/***************************************************************************
2+
qgsrasterterrainanalysisdialog.h - description
3+
-----------------------------
4+
begin : August 8th, 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+
#ifndef QGSRASTERTERRAINANALYSISDIALOG_H
19+
#define QGSRASTERTERRAINANALYSISDIALOG_H
20+
21+
#include "ui_qgsrasterterrainanalysisdialogbase.h"
22+
23+
class QgisInterface;
24+
25+
class QgsRasterTerrainAnalysisDialog: public QDialog, private Ui::QgsRasterTerrainAnalysisDialogBase
26+
{
27+
Q_OBJECT
28+
public:
29+
QgsRasterTerrainAnalysisDialog( QgisInterface* iface, QWidget* parent = 0 );
30+
~QgsRasterTerrainAnalysisDialog();
31+
32+
QString selectedInputLayerId() const;
33+
QString selectedDriverKey() const;
34+
QString selectedOuputFilePath() const;
35+
QString selectedAnalysisMethod() const;
36+
bool addLayerToProject() const;
37+
38+
private slots:
39+
void on_mOutputLayerLineEdit_textChanged( const QString& text );
40+
void on_mOutputLayerPushButton_clicked();
41+
void on_mButtonBox_accepted();
42+
43+
private:
44+
QgisInterface* mIface;
45+
};
46+
47+
#endif // QGSRASTERTERRAINANALYSISDIALOG_H

‎src/plugins/raster_terrain_analysis/qgsrasterterrainanalysisdialogbase.h

Whitespace-only changes.
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<ui version="4.0" >
2+
<class>QgsRasterTerrainAnalysisDialogBase</class>
3+
<widget class="QDialog" name="QgsRasterTerrainAnalysisDialogBase" >
4+
<property name="geometry" >
5+
<rect>
6+
<x>0</x>
7+
<y>0</y>
8+
<width>355</width>
9+
<height>318</height>
10+
</rect>
11+
</property>
12+
<property name="windowTitle" >
13+
<string>Raster based terrain analysis</string>
14+
</property>
15+
<layout class="QGridLayout" name="gridLayout" >
16+
<item row="0" column="0" >
17+
<layout class="QHBoxLayout" name="horizontalLayout" >
18+
<item>
19+
<widget class="QLabel" name="mAnalysisLabel" >
20+
<property name="text" >
21+
<string>Analysis:</string>
22+
</property>
23+
</widget>
24+
</item>
25+
<item>
26+
<widget class="QComboBox" name="mAnalysisComboBox" >
27+
<property name="sizePolicy" >
28+
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
29+
<horstretch>0</horstretch>
30+
<verstretch>0</verstretch>
31+
</sizepolicy>
32+
</property>
33+
</widget>
34+
</item>
35+
</layout>
36+
</item>
37+
<item row="1" column="0" >
38+
<widget class="QLabel" name="mInputLayerLabel" >
39+
<property name="text" >
40+
<string>Input layer:</string>
41+
</property>
42+
</widget>
43+
</item>
44+
<item row="2" column="0" >
45+
<widget class="QComboBox" name="mInputLayerComboBox" />
46+
</item>
47+
<item row="3" column="0" >
48+
<widget class="QLabel" name="mOutputLayerLabel" >
49+
<property name="text" >
50+
<string>Output layer:</string>
51+
</property>
52+
</widget>
53+
</item>
54+
<item row="4" column="0" >
55+
<layout class="QHBoxLayout" name="horizontalLayout_2" >
56+
<item>
57+
<widget class="QLineEdit" name="mOutputLayerLineEdit" />
58+
</item>
59+
<item>
60+
<widget class="QPushButton" name="mOutputLayerPushButton" >
61+
<property name="sizePolicy" >
62+
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
63+
<horstretch>0</horstretch>
64+
<verstretch>0</verstretch>
65+
</sizepolicy>
66+
</property>
67+
<property name="minimumSize" >
68+
<size>
69+
<width>20</width>
70+
<height>0</height>
71+
</size>
72+
</property>
73+
<property name="text" >
74+
<string>...</string>
75+
</property>
76+
</widget>
77+
</item>
78+
</layout>
79+
</item>
80+
<item row="5" column="0" >
81+
<widget class="QLabel" name="mOutputFormatLabel" >
82+
<property name="text" >
83+
<string>Output format:</string>
84+
</property>
85+
</widget>
86+
</item>
87+
<item row="6" column="0" >
88+
<widget class="QComboBox" name="mOutputFormatComboBox" />
89+
</item>
90+
<item row="7" column="0" >
91+
<widget class="QCheckBox" name="mAddResultToProjectCheckBox" >
92+
<property name="text" >
93+
<string>Add result to project</string>
94+
</property>
95+
</widget>
96+
</item>
97+
<item row="8" column="0" >
98+
<widget class="QDialogButtonBox" name="mButtonBox" >
99+
<property name="orientation" >
100+
<enum>Qt::Horizontal</enum>
101+
</property>
102+
<property name="standardButtons" >
103+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
104+
</property>
105+
</widget>
106+
</item>
107+
</layout>
108+
</widget>
109+
<resources/>
110+
<connections>
111+
<connection>
112+
<sender>mButtonBox</sender>
113+
<signal>accepted()</signal>
114+
<receiver>QgsRasterTerrainAnalysisDialogBase</receiver>
115+
<slot>accept()</slot>
116+
<hints>
117+
<hint type="sourcelabel" >
118+
<x>248</x>
119+
<y>254</y>
120+
</hint>
121+
<hint type="destinationlabel" >
122+
<x>157</x>
123+
<y>274</y>
124+
</hint>
125+
</hints>
126+
</connection>
127+
<connection>
128+
<sender>mButtonBox</sender>
129+
<signal>rejected()</signal>
130+
<receiver>QgsRasterTerrainAnalysisDialogBase</receiver>
131+
<slot>reject()</slot>
132+
<hints>
133+
<hint type="sourcelabel" >
134+
<x>316</x>
135+
<y>260</y>
136+
</hint>
137+
<hint type="destinationlabel" >
138+
<x>286</x>
139+
<y>274</y>
140+
</hint>
141+
</hints>
142+
</connection>
143+
</connections>
144+
</ui>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/***************************************************************************
2+
qgsrasterterrainanalysisplugin.h - 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+
#ifndef QGSRASTERTERRAINANALYSISPLUGIN_H
19+
#define QGSRASTERTERRAINANALYSISPLUGIN_H
20+
21+
#include "qgisplugin.h"
22+
#include <QObject>
23+
24+
class QgsInterface;
25+
class QAction;
26+
27+
/**A plugin for raster based terrain analysis (e.g. slope, aspect, ruggedness)*/
28+
class QgsRasterTerrainAnalysisPlugin: public QObject, public QgisPlugin
29+
{
30+
Q_OBJECT
31+
public:
32+
QgsRasterTerrainAnalysisPlugin( QgisInterface* iface );
33+
~QgsRasterTerrainAnalysisPlugin();
34+
35+
/**initialize connection to GUI*/
36+
void initGui();
37+
/**Unload the plugin and cleanup the GUI*/
38+
void unload();
39+
40+
private slots:
41+
/**Select input file, output file, format and analysis method*/
42+
void run();
43+
44+
private:
45+
QgisInterface* mIface;
46+
QAction* mAction;
47+
};
48+
49+
#endif // QGSRASTERTERRAINANALYSISPLUGIN_H
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/***************************************************************************
2+
qgsruggednessfilter.cpp - description
3+
-----------------------
4+
begin : August 7th, 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 "qgsruggednessfilter.h"
19+
20+
QgsRuggednessFilter::QgsRuggednessFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): QgsNineCellFilter( inputFile, outputFile, outputFormat )
21+
{
22+
23+
}
24+
25+
QgsRuggednessFilter::QgsRuggednessFilter(): QgsNineCellFilter( "", "", "" )
26+
{
27+
28+
}
29+
30+
31+
QgsRuggednessFilter::~QgsRuggednessFilter()
32+
{
33+
34+
}
35+
36+
float QgsRuggednessFilter::processNineCellWindow( float* x11, float* x21, float* x31, \
37+
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
38+
{
39+
//the formula would be that easy without nodata values...
40+
/*
41+
//return *x22; //test: write the raster value of the middle cell
42+
float diff1 = *x11 - *x22;
43+
float diff2 = *x21 - *x22;
44+
float diff3 = *x31 - *x22;
45+
float diff4 = *x12 - *x22;
46+
float diff5 = *x32 - *x22;
47+
float diff6 = *x13 - *x22;
48+
float diff7 = *x23 - *x22;
49+
float diff8 = *x33 - *x22;
50+
return sqrt(diff1 * diff1 + diff2 * diff2 + diff3 * diff3 + diff4 * diff4 + diff5 * diff5 + diff6 * diff6 + diff7 * diff7 + diff8 * diff8);
51+
*/
52+
53+
if ( *x22 == mInputNodataValue )
54+
{
55+
return mOutputNodataValue;
56+
}
57+
58+
double sum = 0;
59+
if ( *x11 != mInputNodataValue )
60+
{
61+
sum += ( *x11 - *x22 ) * ( *x11 - *x22 );
62+
}
63+
if ( *x21 != mInputNodataValue )
64+
{
65+
sum += ( *x21 - *x22 ) * ( *x21 - *x22 );
66+
}
67+
if ( *x31 != mInputNodataValue )
68+
{
69+
sum += ( *x31 - *x22 ) * ( *x31 - *x22 );
70+
}
71+
if ( *x12 != mInputNodataValue )
72+
{
73+
sum += ( *x12 - *x22 ) * ( *x12 - *x22 );
74+
}
75+
if ( *x32 != mInputNodataValue )
76+
{
77+
sum += ( *x32 - *x22 ) * ( *x32 - *x22 );
78+
}
79+
if ( *x13 != mInputNodataValue )
80+
{
81+
sum += ( *x13 - *x22 ) * ( *x13 - *x22 );
82+
}
83+
if ( *x23 != mInputNodataValue )
84+
{
85+
sum += ( *x23 - *x22 ) * ( *x23 - *x22 );
86+
}
87+
if ( *x33 != mInputNodataValue )
88+
{
89+
sum += ( *x33 - *x22 ) * ( *x33 - *x22 );
90+
}
91+
92+
return sqrt( sum );
93+
}
94+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************
2+
qgsruggednessfilter.h - description
3+
---------------------
4+
begin : August 7th, 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+
#ifndef QGSRUGGEDNESSFILTER_H
19+
#define QGSRUGGEDNESSFILTER_H
20+
21+
#include "qgsninecellfilter.h"
22+
23+
/**Calculates the ruggedness index based on a 3x3 moving window*/
24+
class QgsRuggednessFilter: public QgsNineCellFilter
25+
{
26+
public:
27+
QgsRuggednessFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
28+
~QgsRuggednessFilter();
29+
30+
protected:
31+
/**Calculates output value from nine input values. The input values and the output value can be equal to the \
32+
nodata value if not present or outside of the border. Must be implemented by subclasses*/
33+
float processNineCellWindow( float* x11, float* x21, float* x31, \
34+
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
35+
36+
private:
37+
QgsRuggednessFilter();
38+
};
39+
40+
#endif // QGSRUGGEDNESSFILTER_H
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/***************************************************************************
2+
qgsruggednessfilter.h - description
3+
---------------------
4+
begin : August 7th, 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 "qgsruggednessindex.h"
19+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/***************************************************************************
2+
qgsslopefilter.h - description
3+
--------------------------------
4+
begin : August 7th, 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 "qgsslopefilter.h"
19+
20+
QgsSlopeFilter::QgsSlopeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
21+
QgsDerivativeFilter( inputFile, outputFile, outputFormat )
22+
{
23+
24+
}
25+
26+
QgsSlopeFilter::~QgsSlopeFilter()
27+
{
28+
29+
}
30+
31+
float QgsSlopeFilter::processNineCellWindow( float* x11, float* x21, float* x31, \
32+
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
33+
{
34+
float derX = calcFirstDerX( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
35+
float derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33 );
36+
37+
if ( derX == mOutputNodataValue || derY == mOutputNodataValue )
38+
{
39+
return mOutputNodataValue;
40+
}
41+
42+
return atan( sqrt( derX * derX + derY * derY ) ) * 180.0 / M_PI;
43+
}
44+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/***************************************************************************
2+
qgsslopefilter.h - description
3+
--------------------------------
4+
begin : August 7th, 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+
#ifndef QGSSLOPEFILTER_H
19+
#define QGSSLOPEFILTER_H
20+
21+
#include "qgsderivativefilter.h"
22+
23+
/**Calculates slope values in a window of 3x3 cells based on first order derivatives in x- and y- directions*/
24+
class QgsSlopeFilter: public QgsDerivativeFilter
25+
{
26+
public:
27+
QgsSlopeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
28+
~QgsSlopeFilter();
29+
30+
protected:
31+
/**Calculates output value from nine input values. The input values and the output value can be equal to the \
32+
nodata value if not present or outside of the border. Must be implemented by subclasses*/
33+
float processNineCellWindow( float* x11, float* x21, float* x31, \
34+
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
35+
};
36+
37+
#endif // QGSSLOPEFILTER_H
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/***************************************************************************
2+
qgstotalcurvaturefilter.h - description
3+
-------------------
4+
begin : August 21th, 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 "qgstotalcurvaturefilter.h"
19+
20+
QgsTotalCurvatureFilter::QgsTotalCurvatureFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
21+
QgsNineCellFilter( inputFile, outputFile, outputFormat )
22+
{
23+
24+
}
25+
26+
QgsTotalCurvatureFilter::~QgsTotalCurvatureFilter()
27+
{
28+
29+
}
30+
31+
float QgsTotalCurvatureFilter::processNineCellWindow( float* x11, float* x21, float* x31, float* x12, \
32+
float* x22, float* x32, float* x13, float* x23, float* x33 )
33+
{
34+
//return nodata if one value is the nodata value
35+
if ( *x11 == mInputNodataValue || *x21 == mInputNodataValue || *x31 == mInputNodataValue || *x12 == mInputNodataValue \
36+
|| *x22 == mInputNodataValue || *x32 == mInputNodataValue || *x13 == mInputNodataValue || *x23 == mInputNodataValue \
37+
|| *x33 == mInputNodataValue )
38+
{
39+
return mOutputNodataValue;
40+
}
41+
42+
double cellSizeAvg = ( mCellSizeX + mCellSizeY ) / 2.0;
43+
double dxx = ( *x32 - 2 * *x22 + *x12 ) / ( mCellSizeX * mCellSizeX );
44+
double dyy = ( -*x11 + *x31 + *x13 - *x33 ) / ( 4 * cellSizeAvg * cellSizeAvg );
45+
double dxy = ( *x21 - 2 * *x22 + *x23 ) / ( mCellSizeY * mCellSizeY );
46+
47+
return dxx*dxx + 2*dxy*dxy + dyy*dyy;
48+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/***************************************************************************
2+
qgstotalcurvaturefilter.h - description
3+
-------------------
4+
begin : August 21th, 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+
#ifndef QGSTOTALCURVATUREFILTER_H
19+
#define QGSTOTALCURVATUREFILTER_H
20+
21+
#include "qgsninecellfilter.h"
22+
23+
/**Calculates total curvature as described by Wilson, Gallant (2000): terrain analysis*/
24+
class QgsTotalCurvatureFilter: public QgsNineCellFilter
25+
{
26+
public:
27+
QgsTotalCurvatureFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
28+
~QgsTotalCurvatureFilter();
29+
30+
protected:
31+
/**Calculates total curvature from nine input values. The input values and the output value can be equal to the \
32+
nodata value if not present or outside of the border. Must be implemented by subclasses*/
33+
float processNineCellWindow( float* x11, float* x21, float* x31, \
34+
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 );
35+
};
36+
37+
#endif // QGSTOTALCURVATUREFILTER_H
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE RCC><RCC version="1.0">
2+
<qresource prefix="/raster">
3+
<file>raster_terrain_icon.png</file>
4+
</qresource>
5+
</RCC>
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/********************************************************************************
2+
** Form generated from reading ui file 'qgsrasterterrainanalysisdialogbase.ui'
3+
**
4+
** Created: Fri Aug 21 16:16:26 2009
5+
** by: Qt User Interface Compiler version 4.5.0
6+
**
7+
** WARNING! All changes made in this file will be lost when recompiling ui file!
8+
********************************************************************************/
9+
10+
#ifndef UI_QGSRASTERTERRAINANALYSISDIALOGBASE_H
11+
#define UI_QGSRASTERTERRAINANALYSISDIALOGBASE_H
12+
13+
#include <QtCore/QVariant>
14+
#include <QtGui/QAction>
15+
#include <QtGui/QApplication>
16+
#include <QtGui/QButtonGroup>
17+
#include <QtGui/QCheckBox>
18+
#include <QtGui/QComboBox>
19+
#include <QtGui/QDialog>
20+
#include <QtGui/QDialogButtonBox>
21+
#include <QtGui/QGridLayout>
22+
#include <QtGui/QHBoxLayout>
23+
#include <QtGui/QHeaderView>
24+
#include <QtGui/QLabel>
25+
#include <QtGui/QLineEdit>
26+
#include <QtGui/QPushButton>
27+
28+
QT_BEGIN_NAMESPACE
29+
30+
class Ui_QgsRasterTerrainAnalysisDialogBase
31+
{
32+
public:
33+
QGridLayout *gridLayout;
34+
QHBoxLayout *horizontalLayout;
35+
QLabel *mAnalysisLabel;
36+
QComboBox *mAnalysisComboBox;
37+
QLabel *mInputLayerLabel;
38+
QComboBox *mInputLayerComboBox;
39+
QLabel *mOutputLayerLabel;
40+
QHBoxLayout *horizontalLayout_2;
41+
QLineEdit *mOutputLayerLineEdit;
42+
QPushButton *mOutputLayerPushButton;
43+
QLabel *mOutputFormatLabel;
44+
QComboBox *mOutputFormatComboBox;
45+
QCheckBox *mAddResultToProjectCheckBox;
46+
QDialogButtonBox *mButtonBox;
47+
48+
void setupUi( QDialog *QgsRasterTerrainAnalysisDialogBase )
49+
{
50+
if ( QgsRasterTerrainAnalysisDialogBase->objectName().isEmpty() )
51+
QgsRasterTerrainAnalysisDialogBase->setObjectName( QString::fromUtf8( "QgsRasterTerrainAnalysisDialogBase" ) );
52+
QgsRasterTerrainAnalysisDialogBase->resize( 355, 318 );
53+
gridLayout = new QGridLayout( QgsRasterTerrainAnalysisDialogBase );
54+
gridLayout->setObjectName( QString::fromUtf8( "gridLayout" ) );
55+
horizontalLayout = new QHBoxLayout();
56+
horizontalLayout->setObjectName( QString::fromUtf8( "horizontalLayout" ) );
57+
mAnalysisLabel = new QLabel( QgsRasterTerrainAnalysisDialogBase );
58+
mAnalysisLabel->setObjectName( QString::fromUtf8( "mAnalysisLabel" ) );
59+
60+
horizontalLayout->addWidget( mAnalysisLabel );
61+
62+
mAnalysisComboBox = new QComboBox( QgsRasterTerrainAnalysisDialogBase );
63+
mAnalysisComboBox->setObjectName( QString::fromUtf8( "mAnalysisComboBox" ) );
64+
QSizePolicy sizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
65+
sizePolicy.setHorizontalStretch( 0 );
66+
sizePolicy.setVerticalStretch( 0 );
67+
sizePolicy.setHeightForWidth( mAnalysisComboBox->sizePolicy().hasHeightForWidth() );
68+
mAnalysisComboBox->setSizePolicy( sizePolicy );
69+
70+
horizontalLayout->addWidget( mAnalysisComboBox );
71+
72+
73+
gridLayout->addLayout( horizontalLayout, 0, 0, 1, 1 );
74+
75+
mInputLayerLabel = new QLabel( QgsRasterTerrainAnalysisDialogBase );
76+
mInputLayerLabel->setObjectName( QString::fromUtf8( "mInputLayerLabel" ) );
77+
78+
gridLayout->addWidget( mInputLayerLabel, 1, 0, 1, 1 );
79+
80+
mInputLayerComboBox = new QComboBox( QgsRasterTerrainAnalysisDialogBase );
81+
mInputLayerComboBox->setObjectName( QString::fromUtf8( "mInputLayerComboBox" ) );
82+
83+
gridLayout->addWidget( mInputLayerComboBox, 2, 0, 1, 1 );
84+
85+
mOutputLayerLabel = new QLabel( QgsRasterTerrainAnalysisDialogBase );
86+
mOutputLayerLabel->setObjectName( QString::fromUtf8( "mOutputLayerLabel" ) );
87+
88+
gridLayout->addWidget( mOutputLayerLabel, 3, 0, 1, 1 );
89+
90+
horizontalLayout_2 = new QHBoxLayout();
91+
horizontalLayout_2->setObjectName( QString::fromUtf8( "horizontalLayout_2" ) );
92+
mOutputLayerLineEdit = new QLineEdit( QgsRasterTerrainAnalysisDialogBase );
93+
mOutputLayerLineEdit->setObjectName( QString::fromUtf8( "mOutputLayerLineEdit" ) );
94+
95+
horizontalLayout_2->addWidget( mOutputLayerLineEdit );
96+
97+
mOutputLayerPushButton = new QPushButton( QgsRasterTerrainAnalysisDialogBase );
98+
mOutputLayerPushButton->setObjectName( QString::fromUtf8( "mOutputLayerPushButton" ) );
99+
QSizePolicy sizePolicy1( QSizePolicy::Preferred, QSizePolicy::Fixed );
100+
sizePolicy1.setHorizontalStretch( 0 );
101+
sizePolicy1.setVerticalStretch( 0 );
102+
sizePolicy1.setHeightForWidth( mOutputLayerPushButton->sizePolicy().hasHeightForWidth() );
103+
mOutputLayerPushButton->setSizePolicy( sizePolicy1 );
104+
mOutputLayerPushButton->setMinimumSize( QSize( 20, 0 ) );
105+
106+
horizontalLayout_2->addWidget( mOutputLayerPushButton );
107+
108+
109+
gridLayout->addLayout( horizontalLayout_2, 4, 0, 1, 1 );
110+
111+
mOutputFormatLabel = new QLabel( QgsRasterTerrainAnalysisDialogBase );
112+
mOutputFormatLabel->setObjectName( QString::fromUtf8( "mOutputFormatLabel" ) );
113+
114+
gridLayout->addWidget( mOutputFormatLabel, 5, 0, 1, 1 );
115+
116+
mOutputFormatComboBox = new QComboBox( QgsRasterTerrainAnalysisDialogBase );
117+
mOutputFormatComboBox->setObjectName( QString::fromUtf8( "mOutputFormatComboBox" ) );
118+
119+
gridLayout->addWidget( mOutputFormatComboBox, 6, 0, 1, 1 );
120+
121+
mAddResultToProjectCheckBox = new QCheckBox( QgsRasterTerrainAnalysisDialogBase );
122+
mAddResultToProjectCheckBox->setObjectName( QString::fromUtf8( "mAddResultToProjectCheckBox" ) );
123+
124+
gridLayout->addWidget( mAddResultToProjectCheckBox, 7, 0, 1, 1 );
125+
126+
mButtonBox = new QDialogButtonBox( QgsRasterTerrainAnalysisDialogBase );
127+
mButtonBox->setObjectName( QString::fromUtf8( "mButtonBox" ) );
128+
mButtonBox->setOrientation( Qt::Horizontal );
129+
mButtonBox->setStandardButtons( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
130+
131+
gridLayout->addWidget( mButtonBox, 8, 0, 1, 1 );
132+
133+
134+
retranslateUi( QgsRasterTerrainAnalysisDialogBase );
135+
QObject::connect( mButtonBox, SIGNAL( accepted() ), QgsRasterTerrainAnalysisDialogBase, SLOT( accept() ) );
136+
QObject::connect( mButtonBox, SIGNAL( rejected() ), QgsRasterTerrainAnalysisDialogBase, SLOT( reject() ) );
137+
138+
QMetaObject::connectSlotsByName( QgsRasterTerrainAnalysisDialogBase );
139+
} // setupUi
140+
141+
void retranslateUi( QDialog *QgsRasterTerrainAnalysisDialogBase )
142+
{
143+
QgsRasterTerrainAnalysisDialogBase->setWindowTitle( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Raster based terrain analysis", 0, QApplication::UnicodeUTF8 ) );
144+
mAnalysisLabel->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Analysis:", 0, QApplication::UnicodeUTF8 ) );
145+
mInputLayerLabel->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Input layer:", 0, QApplication::UnicodeUTF8 ) );
146+
mOutputLayerLabel->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Output layer:", 0, QApplication::UnicodeUTF8 ) );
147+
mOutputLayerPushButton->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "...", 0, QApplication::UnicodeUTF8 ) );
148+
mOutputFormatLabel->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Output format:", 0, QApplication::UnicodeUTF8 ) );
149+
mAddResultToProjectCheckBox->setText( QApplication::translate( "QgsRasterTerrainAnalysisDialogBase", "Add result to project", 0, QApplication::UnicodeUTF8 ) );
150+
Q_UNUSED( QgsRasterTerrainAnalysisDialogBase );
151+
} // retranslateUi
152+
153+
};
154+
155+
namespace Ui
156+
{
157+
class QgsRasterTerrainAnalysisDialogBase: public Ui_QgsRasterTerrainAnalysisDialogBase {};
158+
} // namespace Ui
159+
160+
QT_END_NAMESPACE
161+
162+
#endif // UI_QGSRASTERTERRAINANALYSISDIALOGBASE_H

0 commit comments

Comments
 (0)
Please sign in to comment.