root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / dissolve / fmap / FunctionSummarizer.java @ 6497
History | View | Annotate | Download (4.5 KB)
1 |
/*
|
---|---|
2 |
* Created on 22-may-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: FunctionSummarizer.java 5918 2006-06-20 18:20:45Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1 2006-06-20 18:20:45 azabala
|
49 |
* first version in cvs
|
50 |
*
|
51 |
* Revision 1.1 2006/05/24 21:11:14 azabala
|
52 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
53 |
*
|
54 |
*
|
55 |
*/
|
56 |
package com.iver.cit.gvsig.geoprocess.impl.dissolve.fmap; |
57 |
|
58 |
import java.util.ArrayList; |
59 |
import java.util.Iterator; |
60 |
import java.util.List; |
61 |
import java.util.Map; |
62 |
|
63 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
64 |
import com.hardcode.gdbms.engine.values.NumericValue; |
65 |
import com.hardcode.gdbms.engine.values.Value; |
66 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
67 |
import com.iver.cit.gvsig.geoprocess.core.fmap.SummarizationFunction; |
68 |
|
69 |
/**
|
70 |
* For a given key set of numeric fields to summarize, and the summarization
|
71 |
* functions selected by user, it computes this summarization values.
|
72 |
*
|
73 |
*
|
74 |
* @author azabala
|
75 |
*
|
76 |
*/
|
77 |
public class FunctionSummarizer { |
78 |
/**
|
79 |
* Relates each numeric field with its sumarization functions
|
80 |
*/
|
81 |
Map numericField_functions;
|
82 |
/**
|
83 |
* Reads field values, to compute sumarization functions
|
84 |
*/
|
85 |
SelectableDataSource recordset; |
86 |
/**
|
87 |
* Contains results of sumarization functions computations
|
88 |
*/
|
89 |
List sumarizedValues;
|
90 |
|
91 |
/**
|
92 |
* Constructor
|
93 |
* @param numericField_functions
|
94 |
* @param recordset
|
95 |
*/
|
96 |
public FunctionSummarizer(Map numericField_functions, |
97 |
SelectableDataSource recordset){ |
98 |
this.numericField_functions = numericField_functions;
|
99 |
this.recordset = recordset;
|
100 |
sumarizedValues = new ArrayList(); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Resets sumarization functions state, and clear list of results
|
105 |
*
|
106 |
*/
|
107 |
public void resetFunctions() { |
108 |
if (numericField_functions == null) |
109 |
return;
|
110 |
Iterator fieldsIt = numericField_functions.keySet().iterator();
|
111 |
while (fieldsIt.hasNext()) {
|
112 |
String field = (String) fieldsIt.next(); |
113 |
SummarizationFunction[] functions =
|
114 |
(SummarizationFunction[]) numericField_functions
|
115 |
.get(field); |
116 |
for (int i = 0; i < functions.length; i++) { |
117 |
functions[i].reset(); |
118 |
}// for
|
119 |
}// while
|
120 |
|
121 |
sumarizedValues.clear(); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Reads field values of the feature of index "recordIndex", and applies
|
126 |
* sumarization functions for them
|
127 |
* @param recordIndex
|
128 |
* @throws DriverException
|
129 |
*/
|
130 |
public void applySumarizeFunction(int recordIndex) |
131 |
throws DriverException {
|
132 |
if (numericField_functions == null) |
133 |
return;
|
134 |
Iterator fieldsIt = numericField_functions.keySet().iterator();
|
135 |
while (fieldsIt.hasNext()) {
|
136 |
String field = (String) fieldsIt.next(); |
137 |
int fieldIndex = recordset.getFieldIndexByName(field);
|
138 |
Value valToSumarize = recordset.getFieldValue(recordIndex, |
139 |
fieldIndex); |
140 |
SummarizationFunction[] functions =
|
141 |
(SummarizationFunction[]) numericField_functions
|
142 |
.get(field); |
143 |
for (int i = 0; i < functions.length; i++) { |
144 |
functions[i].process((NumericValue) valToSumarize); |
145 |
}// for
|
146 |
}// while
|
147 |
} |
148 |
|
149 |
public List getValues(){ |
150 |
Iterator fieldsIt = numericField_functions.keySet().iterator();
|
151 |
while(fieldsIt.hasNext()){
|
152 |
String field = (String) fieldsIt.next(); |
153 |
SummarizationFunction[] functions =
|
154 |
(SummarizationFunction[]) numericField_functions
|
155 |
.get(field); |
156 |
for (int i = 0; i < functions.length; i++) { |
157 |
sumarizedValues.add(functions[i].getSumarizeValue()); |
158 |
}// for
|
159 |
}//while
|
160 |
return sumarizedValues;
|
161 |
} |
162 |
|
163 |
|
164 |
} |
165 |
|