1 /**********************************************************
2  * Version $Id$
3  *********************************************************/
4 
5 ///////////////////////////////////////////////////////////
6 //                                                       //
7 //                         SAGA                          //
8 //                                                       //
9 //      System for Automated Geoscientific Analyses      //
10 //                                                       //
11 //                     Tool Library                      //
12 //                      Grid_Tools                       //
13 //                                                       //
14 //-------------------------------------------------------//
15 //                                                       //
16 //               Grid_Value_Reclassify.cpp               //
17 //                                                       //
18 //                 Copyright (C) 2005 by                 //
19 //                    Volker Wichmann                    //
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:     wichmann@laserdata                     //
43 //                                                       //
44 //    contact:    Volker Wichmann                        //
45 //                LASERDATA GmbH                         //
46 //                Management and analysis of             //
47 //                laserscanning data                     //
48 //                Innsbruck, Austria                     //
49 //                                                       //
50 ///////////////////////////////////////////////////////////
51 
52 //---------------------------------------------------------
53 
54 
55 ///////////////////////////////////////////////////////////
56 //														 //
57 //														 //
58 //														 //
59 ///////////////////////////////////////////////////////////
60 
61 //---------------------------------------------------------
62 #include "Grid_Value_Reclassify.h"
63 
64 
65 ///////////////////////////////////////////////////////////
66 //														 //
67 //				Construction/Destruction				 //
68 //														 //
69 ///////////////////////////////////////////////////////////
70 
71 //---------------------------------------------------------
CGrid_Value_Reclassify(void)72 CGrid_Value_Reclassify::CGrid_Value_Reclassify(void)
73 {
74 	CSG_Parameter	*pNode;
75 
76 	//-----------------------------------------------------
77 	Set_Name(_TL("Reclassify Grid Values"));
78 
79 	Set_Author(_TL("V. Wichmann (c) 2005-19"));
80 
81 	Set_Description	(_TW(
82 		"The tool can be used to reclassify the values of a grid. It provides three different options:\n"
83 		"(a) reclassification of single values\n"
84 		"(b) reclassification of a range of values\n"
85 		"(c) reclassification of value ranges specified in a lookup table (simple or user supplied table)\n\n"
86 		"In addition to these methods, two special cases (No Data values and values not included in the "
87 		"reclassification setup) are supported.\n"
88 		"With reclassification mode (a) and (b), the 'No Data' option is evaluated before the 'Method' "
89 		"settings. In reclassification mode (c) the option is evaluated only if the No Data value is not "
90 		"included in the lookup table.\n"
91 		"The 'Other Values' option is always evaluated after checking the 'Method' settings.\n\n"
92 		"The tool also provides options to control the data storage type and No Data value of the "
93 		"output grid.\n\n"
94 	));
95 
96 
97 	//-----------------------------------------------------
98 	Parameters.Add_Grid("",
99 		"INPUT"		,_TL("Grid"),
100 		_TL("Grid to reclassify."),
101 		PARAMETER_INPUT
102 	);
103 
104 	Parameters.Add_Grid("",
105 		"RESULT"	, _TL("Reclassified Grid"),
106 		_TL("Reclassified grid."),
107 		PARAMETER_OUTPUT
108 	);
109 
110 	Parameters.Add_Choice("",
111 		"METHOD"	, _TL("Method"),
112 		_TL("Select the desired method: (1) a single value or a range defined by a single value is reclassified, (2) a range of values is reclassified, (3) and (4) a lookup table is used to reclassify the grid."),
113 		_TL("single|range|simple table|user supplied table"), 0
114 	);
115 
116 
117 	//-----------------------------------------------------
118 	Parameters.Add_Value("",
119 		"OLD"	, _TL("Old Value"),
120 		_TL("Value to reclassify."),
121 		PARAMETER_TYPE_Double, 0.0
122 	);
123 
124 	Parameters.Add_Value("",
125 		"NEW"	, _TL("New Value"),
126 		_TL("The value to assign (with method 'single value')."),
127 		PARAMETER_TYPE_Double, 1.0
128 	);
129 
130 	Parameters.Add_Choice("",
131 		"SOPERATOR"	, _TL("Operator"),
132 		_TL("Select the desired operator; it is possible to define a range above or below the old value."),
133 		CSG_String::Format(SG_T("%s|%s|%s|%s|%s"),
134 			SG_T("="),
135 			SG_T("<"),
136 			SG_T("<="),
137 			SG_T(">="),
138 			SG_T(">")
139 		), 0
140 	);
141 
142 	//-----------------------------------------------------
143 	Parameters.Add_Value("",
144 		"MIN"	, _TL("Minimum Value"),
145 		_TL("The minimum value of the range to be reclassified."),
146 		PARAMETER_TYPE_Double, 0.0
147 	);
148 
149 	Parameters.Add_Value("",
150 		"MAX"	, _TL("Maximum Value"),
151 		_TL("The maximum value of the range to be reclassified."),
152 		PARAMETER_TYPE_Double, 10.0
153 	);
154 
155 	Parameters.Add_Value("",
156 		"RNEW"	, _TL("New Value"),
157 		_TL("The value to assign (with method 'range')."),
158 		PARAMETER_TYPE_Double, 5.0
159 	);
160 
161 	Parameters.Add_Choice("",
162 		"ROPERATOR"	, _TL("Operator"),
163 		_TL("Select the desired operator (for method 'range'): eg. min < value < max."),
164 		CSG_String::Format(SG_T("%s|%s"),
165 			SG_T("<="),
166 			SG_T("<")
167 		), 0
168 	);
169 
170 	//-----------------------------------------------------
171 	Parameters.Add_FixedTable("",
172 		"RETAB"		, _TL("Lookup Table"),
173 		_TL("The lookup table used with method 'table'.")
174 	);
175 
176 	Parameters.Add_Choice("",
177 		"TOPERATOR"	, _TL("Operator"),
178 		_TL("Select the desired operator (for method 'table')."),
179 		CSG_String::Format(SG_T("%s|%s|%s|%s|"),
180 			_TL("min <= value < max"),
181 			_TL("min <= value <= max"),
182 			_TL("min < value <= max"),
183 			_TL("min < value < max")
184 		), 0
185 	);
186 
187 	//-----------------------------------------------------
188 	pNode	= Parameters.Add_Table("",
189 		"RETAB_2"	, _TL("Lookup Table"),
190 		_TL("The lookup table used with method 'user supplied table'."),
191 		PARAMETER_INPUT_OPTIONAL
192 	);
193 
194 	Parameters.Add_Table_Field(pNode,
195 		"F_MIN"		, _TL("Minimum Value"),
196 		_TL("The table field with the minimum value.")
197 	);
198 
199 	Parameters.Add_Table_Field(pNode,
200 		"F_MAX"		, _TL("Maximum Value"),
201 		_TL("The table field with the maximum value.")
202 	);
203 
204 	Parameters.Add_Table_Field(pNode,
205 		"F_CODE"	, _TL("New Value"),
206 		_TL("The table field with the value to assign.")
207 	);
208 
209 	//-----------------------------------------------------
210 	pNode	= Parameters.Add_Node("",
211 		"OPTIONS"	, _TL("Special Cases"),
212 		_TL("Parameter settings for the special cases (a) No-Data values and (b) values not included in the reclassification setup.")
213 	);
214 
215 	Parameters.Add_Value(pNode,
216 		"NODATAOPT"	, _TL("No Data Values"),
217 		_TL("Use this option to reclassify No Data values independently of the method settings."),
218 		PARAMETER_TYPE_Bool, false
219 	);
220 
221 	Parameters.Add_Value(Parameters("NODATAOPT"),
222 		"NODATA"	, _TL("New Value"),
223 		_TL("The value to assign to No Data values."),
224 		PARAMETER_TYPE_Double, 0.0
225 	);
226 
227 	Parameters.Add_Value(pNode,
228 		"OTHEROPT"	, _TL("Other Values"),
229 		_TL("Use this option to reclassify all values that are not included in the reclassification setup."),
230 		PARAMETER_TYPE_Bool, false
231 	);
232 
233 	Parameters.Add_Value(Parameters("OTHEROPT"),
234 		"OTHERS"	, _TL("New Value"),
235 		_TL("The value to assign to all values not included in the reclassification setup."),
236 		PARAMETER_TYPE_Double, 0.0
237 	);
238 
239 	//-----------------------------------------------------
240 	pNode	= Parameters.Add_Node("",
241 		"OPT_RESULT"	, _TL("Output Grid"),
242 		_TL("The parameter settings for the output grid.")
243 	);
244 
245 	Parameters.Add_Choice(pNode,
246 		"RESULT_TYPE"	, _TL("Data Storage Type"),
247 		_TL("The data storage type of the output grid."),
248 		CSG_String::Format("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s",
249 			_TL("1 bit"                     ),
250 			_TL("1 byte unsigned integer"   ),
251 			_TL("1 byte signed integer"     ),
252 			_TL("2 byte unsigned integer"   ),
253 			_TL("2 byte signed integer"     ),
254 			_TL("4 byte unsigned integer"   ),
255 			_TL("4 byte signed integer"     ),
256 			_TL("4 byte floating point"     ),
257 			_TL("8 byte floating point"     ),
258 			_TL("same as input grid"		)
259 		), 9
260 	);
261 
262 	Parameters.Add_Choice(pNode,
263 		"RESULT_NODATA_CHOICE"	, _TL("No Data Value"),
264 		_TL("Choose how to handle the No Data value of the output grid."),
265 		CSG_String::Format(SG_T("%s|%s|%s"),
266 			_TL("No Data value of input grid"),
267 			_TL("user defined No Data value"),
268 			_TL("No Data value of data storage type")
269 		), 0
270 	);
271 
272 	Parameters.Add_Value(Parameters("RESULT_NODATA_CHOICE"),
273 		"RESULT_NODATA_VALUE"		, _TL("No Data Value"),
274 		_TL("User defined No Data value for output grid."),
275 		PARAMETER_TYPE_Double, -99999.0
276 	);
277 
278 	//-----------------------------------------------------
279 	CSG_Table			*pLookup;
280 	CSG_Table_Record	*pRecord;
281 
282 	pLookup	= Parameters("RETAB")->asTable();
283 
284 	pLookup->Add_Field(_TL("minimum")	, SG_DATATYPE_Double);
285 	pLookup->Add_Field(_TL("maximum")	, SG_DATATYPE_Double);
286 	pLookup->Add_Field(_TL("new")		, SG_DATATYPE_Double);
287 
288 	pRecord	= pLookup->Add_Record();	pRecord->Set_Value(0,  0.0);	pRecord->Set_Value(1, 10.0);	pRecord->Set_Value(2, 1.0);
289 	pRecord	= pLookup->Add_Record();	pRecord->Set_Value(0, 10.0);	pRecord->Set_Value(1, 20.0);	pRecord->Set_Value(2, 2.0);
290 }
291 
292 //---------------------------------------------------------
~CGrid_Value_Reclassify(void)293 CGrid_Value_Reclassify::~CGrid_Value_Reclassify(void)
294 {}
295 
296 
297 ///////////////////////////////////////////////////////////
298 //														 //
299 //														 //
300 //														 //
301 ///////////////////////////////////////////////////////////
302 
303 //---------------------------------------------------------
On_Execute(void)304 bool CGrid_Value_Reclassify::On_Execute(void)
305 {
306 	int		method;
307 	bool    bSuccess = false;
308 
309 	pInput		= Parameters("INPUT")->asGrid();
310 	pResult		= Parameters("RESULT")->asGrid();
311 	method		= Parameters("METHOD")->asInt();
312 
313 	//---------------------------------------------------------
314 	switch( Parameters("RESULT_TYPE")->asInt() )
315 	{
316 	case 0:		pResult->Create(pInput, SG_DATATYPE_Bit);		break;
317 	case 1:		pResult->Create(pInput, SG_DATATYPE_Byte);		break;
318 	case 2:		pResult->Create(pInput, SG_DATATYPE_Char);		break;
319 	case 3:		pResult->Create(pInput, SG_DATATYPE_Word);		break;
320 	case 4:		pResult->Create(pInput, SG_DATATYPE_Short);		break;
321 	case 5:		pResult->Create(pInput, SG_DATATYPE_DWord);		break;
322 	case 6:		pResult->Create(pInput, SG_DATATYPE_Int);		break;
323 	case 7:		pResult->Create(pInput, SG_DATATYPE_Float);		break;
324 	case 8:		pResult->Create(pInput, SG_DATATYPE_Double);	break;
325 	case 9:
326 	default:	pResult->Create(pInput, pInput->Get_Type());	break;
327 	}
328 
329 
330 	//---------------------------------------------------------
331 	switch( method )
332 	{
333 	case 0:
334 	default:	bSuccess = ReclassSingle();			break;
335 	case 1:		bSuccess = ReclassRange();			break;
336 	case 2:		bSuccess = ReclassTable(false);		break;
337 	case 3:		bSuccess = ReclassTable(true);		break;
338 	}
339 
340 
341 	//---------------------------------------------------------
342 	if( bSuccess )
343 	{
344 		switch( Parameters("RESULT_NODATA_CHOICE")->asInt() )
345 		{
346 		case 0:
347 		default:		pResult->Set_NoData_Value(pInput->Get_NoData_Value());							break;
348 		case 1:			pResult->Set_NoData_Value(Parameters("RESULT_NODATA_VALUE")->asDouble());		break;
349 		case 2:
350 						switch( pResult->Get_Type() )
351 						{
352                         case SG_DATATYPE_Bit   : pResult->Set_NoData_Value(          0.);	break;
353                         case SG_DATATYPE_Byte  : pResult->Set_NoData_Value(          0.);	break;
354                         case SG_DATATYPE_Char  : pResult->Set_NoData_Value(       -127.);	break;
355                         case SG_DATATYPE_Word  : pResult->Set_NoData_Value(      65535.);	break;
356                         case SG_DATATYPE_Short : pResult->Set_NoData_Value(     -32767.);	break;
357                         case SG_DATATYPE_DWord : pResult->Set_NoData_Value( 4294967295.);	break;
358                         case SG_DATATYPE_Int   : pResult->Set_NoData_Value(-2147483647.);	break;
359                         case SG_DATATYPE_ULong : pResult->Set_NoData_Value( 4294967295.);	break;
360                         case SG_DATATYPE_Long  : pResult->Set_NoData_Value(-2147483647.);	break;
361                         case SG_DATATYPE_Float : pResult->Set_NoData_Value(     -99999.);	break;
362                         case SG_DATATYPE_Double: pResult->Set_NoData_Value(     -99999.);	break;
363                         case SG_DATATYPE_Color : pResult->Set_NoData_Value( 4294967295.);	break;
364 						default:	pResult->Set_NoData_Value(pInput->Get_NoData_Value());	break;
365 						}
366 
367 						break;
368 		}
369 
370 
371 	    pResult->Fmt_Name("%s (%s)", pInput->Get_Name(), _TL("Reclassified"));
372 
373 	    return( true );
374 	}
375 	else
376 	{
377         return( false );
378 	}
379 }
380 
381 
382 ///////////////////////////////////////////////////////////
383 //														 //
384 //														 //
385 //														 //
386 ///////////////////////////////////////////////////////////
387 
388 //---------------------------------------------------------
ReclassRange(void)389 bool CGrid_Value_Reclassify::ReclassRange(void)
390 {
391 	bool	otherOpt, noDataOpt, floating;
392 	int		opera;
393 	double	minValue, maxValue, others, noData, noDataValue, newValue;
394 
395 
396 	minValue	= Parameters("MIN")->asDouble();
397 	maxValue	= Parameters("MAX")->asDouble();
398 	newValue	= Parameters("RNEW")->asDouble();
399 	others		= Parameters("OTHERS")->asDouble();
400 	noData		= Parameters("NODATA")->asDouble();
401 	otherOpt	= Parameters("OTHEROPT")->asBool();
402 	noDataOpt	= Parameters("NODATAOPT")->asBool();
403 	opera		= Parameters("ROPERATOR")->asInt();
404 
405 	noDataValue = pInput->Get_NoData_Value();
406 
407 	if( (pInput->Get_Type() == SG_DATATYPE_Double) || (pInput->Get_Type() == SG_DATATYPE_Float) )
408 		floating = true;
409 	else
410 		floating = false;
411 
412 	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
413 	{
414 		#pragma omp parallel for
415 		for(int x=0; x<Get_NX(); x++)
416 		{
417 			double	value;
418 
419 			if( floating == true )
420 				value = pInput->asDouble(x, y);
421 			else
422 				value = pInput->asInt(x, y);
423 
424 			if( opera == 0 )												// operator <=
425 			{
426 				if( noDataOpt == true && value == noDataValue )				// noData option
427 					pResult->Set_Value(x, y, noData);
428 				else if( minValue <= value && value <= maxValue )			// reclass old range
429 					pResult->Set_Value(x, y, newValue);
430 				else if( otherOpt == true && value != noDataValue )			// other values option
431 					pResult->Set_Value(x, y, others);
432 				else
433 					pResult->Set_Value(x, y, value);						// or original value
434 			}
435 
436 			if( opera == 1 )												// operator <
437 			{
438 				if( noDataOpt == true && value == noDataValue )				// noData option
439 					pResult->Set_Value(x, y, noData);
440 				else if( minValue < value && value < maxValue )				// reclass old range
441 					pResult->Set_Value(x, y, newValue);
442 				else if( otherOpt == true && value != noDataValue )			// other values option
443 					pResult->Set_Value(x, y, others);
444 				else
445 					pResult->Set_Value(x, y, value);						// or original value
446 			}
447 		}
448 	}
449 
450 	return( true );
451 }
452 
453 //---------------------------------------------------------
ReclassSingle(void)454 bool CGrid_Value_Reclassify::ReclassSingle(void)
455 {
456 	bool	otherOpt, noDataOpt, floating;
457 	int		opera;
458 	double	oldValue, newValue, others, noData, noDataValue;
459 
460 
461 	oldValue	= Parameters("OLD")->asDouble();
462 	newValue	= Parameters("NEW")->asDouble();
463 	others		= Parameters("OTHERS")->asDouble();
464 	noData		= Parameters("NODATA")->asDouble();
465 	otherOpt	= Parameters("OTHEROPT")->asBool();
466 	noDataOpt	= Parameters("NODATAOPT")->asBool();
467 	opera		= Parameters("SOPERATOR")->asInt();
468 
469 	noDataValue = pInput->Get_NoData_Value();
470 
471 	if( (pInput->Get_Type() == SG_DATATYPE_Double) || (pInput->Get_Type() == SG_DATATYPE_Float) )
472 		floating = true;
473 	else
474 		floating = false;
475 
476 	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
477 	{
478 		#pragma omp parallel for
479 		for(int x=0; x<Get_NX(); x++)
480 		{
481 			double	value;
482 
483 			if( floating == true )
484 				value = pInput->asDouble(x, y);
485 			else
486 				value = pInput->asInt(x, y);
487 
488 			if( opera == 0 )												// operator =
489 			{
490 				if( noDataOpt == true && value == noDataValue )				// noData option
491 					pResult->Set_Value(x, y, noData);
492 				else if( value == oldValue )								// reclass old value
493 					pResult->Set_Value(x, y, newValue);
494 				else if( otherOpt == true && value != noDataValue )			// other values option
495 					pResult->Set_Value(x, y, others);
496 				else
497 					pResult->Set_Value(x, y, value);						// or original value
498 			}
499 
500 			if( opera == 1 )												// operator <
501 			{
502 				if( noDataOpt == true && value == noDataValue )				// noData option
503 					pResult->Set_Value(x, y, noData);
504 				else if( value < oldValue )									// reclass old value
505 					pResult->Set_Value(x, y, newValue);
506 				else if( otherOpt == true && value != noDataValue )			// other values option
507 					pResult->Set_Value(x, y, others);
508 				else
509 					pResult->Set_Value(x, y, value);						// or original value
510 			}
511 
512 			if( opera == 2 )												// operator <=
513 			{
514 				if( noDataOpt == true && value == noDataValue )				// noData option
515 						pResult->Set_Value(x, y, noData);
516 				else if( value <= oldValue )								// reclass old value
517 					pResult->Set_Value(x, y, newValue);
518 				else if( otherOpt == true && value != noDataValue )			// other values option
519 					pResult->Set_Value(x, y, others);
520 				else
521 					pResult->Set_Value(x, y, value);						// or original value
522 			}
523 
524 			if( opera == 3 )												// operator >=
525 			{
526 				if( noDataOpt == true && value == noDataValue )				// noData option
527 						pResult->Set_Value(x, y, noData);
528 				else if( value >= oldValue )								// reclass old value
529 					pResult->Set_Value(x, y, newValue);
530 				else if( otherOpt == true && value != noDataValue )			// other values option
531 					pResult->Set_Value(x, y, others);
532 				else
533 					pResult->Set_Value(x, y, value);						// or original value
534 			}
535 
536 			if( opera == 4 )												// operator >
537 			{
538 				if( noDataOpt == true && value == noDataValue )				// noData option
539 						pResult->Set_Value(x, y, noData);
540 				else if( value > oldValue )									// reclass old value
541 					pResult->Set_Value(x, y, newValue);
542 				else if( otherOpt == true && value != noDataValue )			// other values option
543 					pResult->Set_Value(x, y, others);
544 				else
545 					pResult->Set_Value(x, y, value);						// or original value
546 			}
547 		}
548 	}
549 
550 	return( true );
551 }
552 
553 
554 //---------------------------------------------------------
ReclassTable(bool bUser)555 bool CGrid_Value_Reclassify::ReclassTable(bool bUser)
556 {
557 	bool			otherOpt, noDataOpt;
558 	int				opera, field_Min, field_Max, field_Code;
559 	double			others, noData, noDataValue;
560 
561 	CSG_Table			*pReTab;
562 
563 	if( bUser )
564 	{
565 		pReTab		= Parameters("RETAB_2")	->asTable();
566 		field_Min	= Parameters("F_MIN")	->asInt();
567 		field_Max	= Parameters("F_MAX")	->asInt();
568 		field_Code	= Parameters("F_CODE")	->asInt();
569 	}
570 	else
571 	{
572 		pReTab		= Parameters("RETAB")	->asTable();
573 		field_Min	= 0;
574 		field_Max	= 1;
575 		field_Code	= 2;
576 	}
577 
578 	others		= Parameters("OTHERS")->asDouble();
579 	noData		= Parameters("NODATA")->asDouble();
580 	otherOpt	= Parameters("OTHEROPT")->asBool();
581 	noDataOpt	= Parameters("NODATAOPT")->asBool();
582 	opera		= Parameters("TOPERATOR")->asInt();
583 
584 	noDataValue = pInput->Get_NoData_Value();
585 
586 
587 	if( pReTab == NULL )
588 	{
589 		Error_Set(_TL("You must specify a reclass table with a minimium (field 1), a maximum (field 2) and a code value (field 3)!\n"));
590 		return( false );
591 	}
592 
593 	if( pReTab->Get_Record_Count() == 0 )
594 	{
595 		Error_Set(_TL("You must specify a reclass table with a minimium of one record!\n"));
596 		return( false );
597 	}
598 
599 
600 	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
601 	{
602 		#pragma omp parallel for
603 		for(int x=0; x<Get_NX(); x++)
604 		{
605 			double	value	= pInput->asDouble(x, y);
606 			bool	set		= false;
607 
608 			for(int iRecord=0; iRecord<pReTab->Get_Record_Count(); iRecord++)									// reclass
609 			{
610 				CSG_Table_Record	*pRecord = pReTab->Get_Record(iRecord);
611 
612 				if( opera == 0 )										// min <= value < max
613 				{
614 					if( value >= pRecord->asDouble(field_Min) && value < pRecord->asDouble(field_Max) )
615 					{
616 						pResult->Set_Value(x, y, pRecord->asDouble(field_Code));
617 						set = true;
618 						break;
619 					}
620 				}
621 				else if( opera == 1 )									// min <= value <= max
622 				{
623 					if( value >= pRecord->asDouble(field_Min) && value <= pRecord->asDouble(field_Max) )
624 					{
625 						pResult->Set_Value(x, y, pRecord->asDouble(field_Code));
626 						set = true;
627 						break;
628 					}
629 				}
630 				else if( opera == 2 )									// min < value <= max
631 				{
632 					if( value > pRecord->asDouble(field_Min) && value <= pRecord->asDouble(field_Max) )
633 					{
634 						pResult->Set_Value(x, y, pRecord->asDouble(field_Code));
635 						set = true;
636 						break;
637 					}
638 				}
639 				else if( opera == 3 )									// min < value < max
640 				{
641 					if( value > pRecord->asDouble(field_Min) && value < pRecord->asDouble(field_Max) )
642 					{
643 						pResult->Set_Value(x, y, pRecord->asDouble(field_Code));
644 						set = true;
645 						break;
646 					}
647 				}
648 			}
649 
650 			if( set == false )
651 			{
652 				if( noDataOpt == true && value == noDataValue )			// noData option
653 					pResult->Set_Value(x, y, noData);
654 				else if( otherOpt == true && value != noDataValue)		// other values option
655 					pResult->Set_Value(x, y, others);
656 				else
657 					pResult->Set_Value(x, y, value);					// or original value
658 			}
659 		}
660 	}
661 
662 	return (true);
663 }
664 
665 
666 //---------------------------------------------------------
On_Parameters_Enable(CSG_Parameters * pParameters,CSG_Parameter * pParameter)667 int CGrid_Value_Reclassify::On_Parameters_Enable(CSG_Parameters *pParameters, CSG_Parameter *pParameter)
668 {
669 	if(	pParameter->Cmp_Identifier(SG_T("METHOD")) )
670 	{
671 		int		Value	= pParameter->asInt();
672 
673 		// single
674 		pParameters->Get_Parameter("OLD"		)->Set_Enabled(Value == 0);
675 		pParameters->Get_Parameter("NEW"		)->Set_Enabled(Value == 0);
676 		pParameters->Get_Parameter("SOPERATOR"	)->Set_Enabled(Value == 0);
677 
678 		// range
679 		pParameters->Get_Parameter("MIN"		)->Set_Enabled(Value == 1);
680 		pParameters->Get_Parameter("MAX"		)->Set_Enabled(Value == 1);
681 		pParameters->Get_Parameter("RNEW"		)->Set_Enabled(Value == 1);
682 		pParameters->Get_Parameter("ROPERATOR"	)->Set_Enabled(Value == 1);
683 
684 		// simple table
685 		pParameters->Get_Parameter("RETAB"		)->Set_Enabled(Value == 2);
686 
687 		// user supplied table
688 		pParameters->Get_Parameter("RETAB_2"	)->Set_Enabled(Value == 3);
689 
690 		pParameters->Get_Parameter("TOPERATOR"	)->Set_Enabled(Value == 2 || Value == 3);
691 	}
692 
693 	if(	pParameter->Cmp_Identifier(SG_T("NODATAOPT")) )
694 	{
695 		pParameters->Get_Parameter("NODATA"		)->Set_Enabled(pParameter->asInt() > 0);
696 	}
697 
698 	if(	pParameter->Cmp_Identifier(SG_T("OTHEROPT")) )
699 	{
700 		pParameters->Get_Parameter("OTHERS"		)->Set_Enabled(pParameter->asInt() > 0);
701 	}
702 
703 	if(	pParameter->Cmp_Identifier(SG_T("RESULT_NODATA_CHOICE")) )
704 	{
705 		pParameters->Get_Parameter("RESULT_NODATA_VALUE")->Set_Enabled(pParameter->asInt() == 1);
706 	}
707 
708 	//-----------------------------------------------------
709 	return (1);
710 }
711 
712 ///////////////////////////////////////////////////////////
713 //														 //
714 //														 //
715 //														 //
716 ///////////////////////////////////////////////////////////
717 
718 //---------------------------------------------------------
719