1 /**********************************************************
2 * Version $Id$
3 *********************************************************/
4
5 ///////////////////////////////////////////////////////////
6 // //
7 // SAGA //
8 // //
9 // System for Automated Geoscientific Analyses //
10 // //
11 // Tool Library //
12 // grid_analysis //
13 // //
14 //-------------------------------------------------------//
15 // //
16 // Fragmentation_Classify.cpp //
17 // //
18 // Copyright (C) 2008 by //
19 // Olaf Conrad //
20 // //
21 //-------------------------------------------------------//
22 // //
23 // This file is part of 'SAGA - System for Automated //
24 // Geoscientific Analyses'. SAGA is free software; you //
25 // can redistribute it and/or modify it under the terms //
26 // of the GNU General Public License as published by the //
27 // Free Software Foundation, either version 2 of the //
28 // License, or (at your option) any later version. //
29 // //
30 // SAGA is distributed in the hope that it will be //
31 // useful, but WITHOUT ANY WARRANTY; without even the //
32 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
33 // PARTICULAR PURPOSE. See the GNU General Public //
34 // License for more details. //
35 // //
36 // You should have received a copy of the GNU General //
37 // Public License along with this program; if not, see //
38 // <http://www.gnu.org/licenses/>. //
39 // //
40 //-------------------------------------------------------//
41 // //
42 // e-mail: oconrad@saga-gis.org //
43 // //
44 // contact: Olaf Conrad //
45 // Institute of Geography //
46 // University of Goettingen //
47 // Goldschmidtstr. 5 //
48 // 37077 Goettingen //
49 // Germany //
50 // //
51 ///////////////////////////////////////////////////////////
52
53 //---------------------------------------------------------
54
55
56 ///////////////////////////////////////////////////////////
57 // //
58 // //
59 // //
60 ///////////////////////////////////////////////////////////
61
62 //---------------------------------------------------------
63 #include "fragmentation_classify.h"
64
65
66 ///////////////////////////////////////////////////////////
67 // //
68 // //
69 // //
70 ///////////////////////////////////////////////////////////
71
72 //---------------------------------------------------------
CFragmentation_Classify(void)73 CFragmentation_Classify::CFragmentation_Classify(void)
74 {
75 Parameters.Create(this, SG_T(""), SG_T(""), SG_T(""), true);
76
77 //-----------------------------------------------------
78 Set_Name (_TL("Fragmentation Classes from Density and Connectivity"));
79
80 Set_Author ("O.Conrad (c) 2008");
81
82 Set_Description (_TW(
83 "Fragmentation classes:\n"
84 "(1) interior, if Density = 1.0\n"
85 "(2) undetermined, if Density > 0.6 and Density = Connectivity\n"
86 "(3) perforated, if Density > 0.6 and Density - Connectivity > 0\n"
87 "(4) edge, if Density > 0.6 and Density - Connectivity < 0\n"
88 "(5) transitional, if 0.4 < Density < 0.6\n"
89 "(6) patch, if Density < 0.4\n"
90 ));
91
92 Add_Reference("Riitters, K., Wickham, J., O'Neill, R., Jones, B., Smith, E.", "2000",
93 "Global-scale patterns of forest fragmentation",
94 "Conservation Ecology 4(2):3.",
95 SG_T("http://www.ecologyandsociety.org/vol4/iss2/art3/")
96 );
97
98 //-----------------------------------------------------
99 Parameters.Add_Grid(
100 "", "DENSITY" , _TL("Density [Percent]"),
101 _TL("Density Index (Pf)."),
102 PARAMETER_INPUT
103 );
104
105 Parameters.Add_Grid(
106 "", "CONNECTIVITY" , _TL("Connectivity [Percent]"),
107 _TL("Connectivity Index (Pff)."),
108 PARAMETER_INPUT
109 );
110
111 Parameters.Add_Grid(
112 "", "FRAGMENTATION" , _TL("Fragmentation"),
113 _TL("Fragmentation Index"),
114 PARAMETER_OUTPUT, true, SG_DATATYPE_Byte
115 );
116
117 Parameters.Add_Bool(
118 "", "BORDER" , _TL("Add Border"),
119 _TL(""),
120 false
121 );
122
123 Parameters.Add_Double(
124 "", "WEIGHT" , _TL("Connectivity Weighting"),
125 _TL(""),
126 1.1, 0.0, true
127 );
128
129 Parameters.Add_Double(
130 "", "DENSITY_MIN" , _TL("Minimum Density [Percent]"),
131 _TL(""),
132 10.0, 0.0, true, 100.0, true
133 );
134
135 Parameters.Add_Double(
136 "", "DENSITY_INT" , _TL("Minimum Density for Interior Forest [Percent]"),
137 _TL("if less than 100, it is distinguished between interior and core forest"),
138 99.0, 0.0, true, 100.0, true
139 );
140 }
141
142
143 ///////////////////////////////////////////////////////////
144 // //
145 ///////////////////////////////////////////////////////////
146
147 //---------------------------------------------------------
On_Execute(void)148 bool CFragmentation_Classify::On_Execute(void)
149 {
150 CSG_Grid *pDensity = Parameters("DENSITY" )->asGrid();
151 CSG_Grid *pConnectivity = Parameters("CONNECTIVITY" )->asGrid();
152 CSG_Grid *pFragmentation = Parameters("FRAGMENTATION")->asGrid();
153
154 Set_Classification(pFragmentation);
155
156 m_Weight = Parameters("WEIGHT" )->asDouble();
157 m_Density_Min = Parameters("DENSITY_MIN" )->asDouble() / 100.0;
158 m_Density_Interior = Parameters("DENSITY_INT" )->asDouble() / 100.0;
159
160 //-----------------------------------------------------
161 for(int y=0; y<Get_NY() && Set_Progress(y); y++)
162 {
163 #pragma omp parallel for
164 for(int x=0; x<Get_NX(); x++)
165 {
166 if( !pDensity->is_NoData(x, y) && !pConnectivity->is_NoData(x, y) )
167 {
168 double Density = pDensity ->asDouble(x, y) / 100.0;
169 double Connectivity = pConnectivity->asDouble(x, y) / 100.0;
170
171 // pFragmentation->Set_Value (x, y, 100.0 * Density * Connectivity);
172 pFragmentation->Set_Value (x, y, Get_Classification(Density, Connectivity));
173 }
174 else
175 {
176 pFragmentation->Set_NoData(x, y);
177 }
178 }
179 }
180
181 //-----------------------------------------------------
182 if( Parameters("BORDER")->asBool() )
183 {
184 Add_Border(pFragmentation);
185 }
186
187 return( true );
188 }
189
190
191 ///////////////////////////////////////////////////////////
192 // //
193 // //
194 // //
195 ///////////////////////////////////////////////////////////
196
197 //---------------------------------------------------------
198