1 /**********************************************************
2  * Version $Id$
3  *********************************************************/
4 /*******************************************************************************
5     CoveredDistance.cpp
6     Copyright (C) Victor Olaya
7 
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12 
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA
21 *******************************************************************************/
22 #include "CoveredDistance.h"
23 
CCoveredDistance(void)24 CCoveredDistance::CCoveredDistance(void)
25 {
26 	Set_Name		(_TL("Covered Distance"));
27 
28 	Set_Author		(SG_T("V. Olaya (c) 2005"));
29 
30 	Set_Description	(_TW(
31 		""
32 	));
33 
34 	Parameters.Add_Grid_List(
35 		NULL, "INPUT"	, _TL("Grids"),
36 		_TL(""), PARAMETER_INPUT
37 	);
38 
39 	Parameters.Add_Grid(
40 		NULL, "RESULT"	, _TL("Covered Distance"),
41 		_TL(""),
42 		PARAMETER_OUTPUT
43 	);
44 }//constructor
45 
46 
On_Execute(void)47 bool CCoveredDistance::On_Execute(void)
48 {
49 	CSG_Parameter_Grid_List	*pGrids		= Parameters("INPUT")	->asGridList();
50 	CSG_Grid				*pResult	= Parameters("RESULT")	->asGrid();
51 
52 	pResult->Assign(0.0);
53 
54 	for(int y=0; y<Get_NY() && Set_Progress(y); y++)
55 	{
56 		for(int x=0; x<Get_NX(); x++)
57 		{
58 			bool	bNoData	= false;
59 			double	dDifSum	= 0.0;
60 
61 			for(int i=0, j=1; j<pGrids->Get_Grid_Count() && !bNoData; i++, j++)
62 			{
63 				if( pGrids->Get_Grid(i)->is_NoData(x, y) || pGrids->Get_Grid(j)->is_NoData(x, y) )
64 				{
65 					bNoData	= true;
66 				}
67 				else
68 				{
69 					dDifSum	+= fabs(pGrids->Get_Grid(i)->asDouble(x, y) - pGrids->Get_Grid(j)->asDouble(x, y));
70 				}
71 			}//for
72 
73 			if( bNoData )
74 			{
75 				pResult->Set_NoData(x, y);
76 			}
77 			else
78 			{
79 				pResult->Set_Value(x, y, dDifSum);
80 			}
81 		}//for
82 	}//for
83 
84 	return true;
85 }
86