Revision 10626 trunk/extensions/extGeoProcessing/src/com/iver/cit/gvsig/geoprocess/impl/dissolve/fmap/SingleFieldDissolveCriteria.java

View differences:

SingleFieldDissolveCriteria.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.2  2006-08-11 16:27:46  azabala
48
* Revision 1.3  2007-03-06 16:47:58  caballero
49
* Exceptions
50
*
51
* Revision 1.2  2006/08/11 16:27:46  azabala
49 52
* *** empty log message ***
50 53
*
51 54
* Revision 1.1  2006/06/20 18:20:45  azabala
......
63 66
import java.util.List;
64 67
import java.util.Map;
65 68

  
69
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
66 70
import com.hardcode.gdbms.engine.data.driver.DriverException;
67 71
import com.hardcode.gdbms.engine.values.Value;
68 72
import com.hardcode.gdbms.engine.values.ValueFactory;
......
73 77
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
74 78
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
75 79
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
76
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
77 80
import com.iver.cit.gvsig.geoprocess.core.fmap.DefinitionUtils;
78 81
import com.iver.cit.gvsig.geoprocess.core.fmap.SummarizationFunction;
79 82
import com.iver.cit.gvsig.geoprocess.core.fmap.XTypes;
......
81 84
 * Decides if dissolve two features based in an alphanumeric criteria:
82 85
 * two features will be dissolved if they have the same value for
83 86
 * a given (and single) field.
84
 * 
85
 * 
87
 *
88
 *
86 89
 * @author azabala
87 90
 *
88 91
 */
......
92 95
	 * decide if dissolve two features
93 96
	 */
94 97
	protected String dissolveField;
95
	
98

  
96 99
	protected FLyrVect layer;
97 100
	/**
98 101
	 * Dissolve field value for the 'seed' feature
99 102
	 */
100 103
	protected Value cachedDissolveValue;
101
	
104

  
102 105
	/**
103 106
	 * Builds features resulting of dissolving with
104 107
	 * this IDissolveCriteria
105 108
	 */
106 109
	protected SingleFieldFeatureBuilder builder;
107
	
108
	
110

  
111

  
109 112
	public SingleFieldDissolveCriteria(String dissolveField,
110 113
			FLyrVect layer) throws DriverException{
111 114
		this.dissolveField = dissolveField;
112 115
		this.layer = layer;
113 116
		builder = new SingleFieldFeatureBuilder();
114
		
117

  
115 118
	}
116 119

  
117 120
	public IDissolvedFeatureBuilder getFeatureBuilder() {
118 121
		return builder;
119 122
	}
120
	
123

  
121 124
	class SingleFieldFeatureBuilder implements IDissolvedFeatureBuilder{
122 125

  
123 126
		public IFeature createFeature(IGeometry g, int index, int fid) {
......
128 131
			return new DefaultFeature(g, values);
129 132
		}
130 133

  
131
		public IFeature createFeature(IGeometry newGeometry, 
132
				List sumarizedValues, 
133
				int newFid, 
134
		public IFeature createFeature(IGeometry newGeometry,
135
				List sumarizedValues,
136
				int newFid,
134 137
				int index) {
135 138
			int numNumericFields = sumarizedValues.size();
136 139
			Value[] values = new Value[numNumericFields + 2];
......
146 149
			values[idx] = cachedDissolveValue;
147 150
			return new DefaultFeature(newGeometry, values);
148 151
		}
149
		
152

  
150 153
	}
151
	
154

  
152 155
	private void fetchDissolveValue(int index){
153 156
		if(cachedDissolveValue == null){
154 157
			try {
155
				int fieldIndex = 
158
				int fieldIndex =
156 159
					layer.getRecordset().getFieldIndexByName(dissolveField);
157
				
160

  
158 161
				cachedDissolveValue = layer.getRecordset().
159
								getFieldValue(index, 
162
								getFieldValue(index,
160 163
										fieldIndex);
161
			} catch (DriverException e) {
164
			} catch (ReadDriverException e) {
162 165
				// TODO Auto-generated catch block
163 166
				e.printStackTrace();
164
			} catch (com.iver.cit.gvsig.fmap.DriverException e) {
165
				// TODO Auto-generated catch block
166
				e.printStackTrace();
167 167
			}
168
			
168

  
169 169
		}
170 170
	}
171 171

  
......
177 177
			Value value2 = layer.getRecordset().
178 178
				getFieldValue(featureIndex2, fieldIndex);
179 179
			return value2.doEquals(cachedDissolveValue);
180
		} catch (DriverException e) {
180
		} catch (ReadDriverException e) {
181 181
			//Ver que hacer con la excepcion
182 182
			e.printStackTrace();
183 183
			return false;
184
		} catch (com.iver.cit.gvsig.fmap.DriverException e) {
185
			// TODO Auto-generated catch block
186
			e.printStackTrace();
187
			return false;
188 184
		}
189
		
185

  
190 186
	}
191 187

  
192 188
	public void clear() {
......
204 200
		fidFd.setFieldType(XTypes.INTEGER);
205 201
		fidFd.setFieldDecimalCount(0);
206 202
		fields.add(fidFd);
207
		
203

  
208 204
		if(numFields_SumFunc != null){
209 205
			//sumarization of numeric attributes
210 206
			Iterator fieldsIt = numFields_SumFunc.keySet().iterator();
......
213 209
				SummarizationFunction[] functions =
214 210
					(SummarizationFunction[]) numFields_SumFunc.get(field);
215 211
				for(int i = 0; i < functions.length; i++){
216
					FieldDescription description = 
212
					FieldDescription description =
217 213
						new FieldDescription();
218 214
					description.setFieldLength(10);
219 215
					description.setFieldDecimalCount(4);
......
247 243
				description.setFieldDecimalCount(DefinitionUtils.NUM_DECIMALS);
248 244
			}
249 245
			fields.add(description);
250
		} catch (DriverException e) {
246
		} catch (ReadDriverException e) {
251 247
			// TODO Auto-generated catch block
252 248
			e.printStackTrace();
253
		} catch (com.iver.cit.gvsig.fmap.DriverException e) {
254
			// TODO Auto-generated catch block
255
			e.printStackTrace();
256 249
		}
257
		
250

  
258 251
		FieldDescription[] fieldsDesc = null;
259 252
		if(fields.size() == 0){
260 253
			fieldsDesc = new FieldDescription[0];
......
264 257
		}
265 258
		resultLayerDefinition.setFieldsDesc(fieldsDesc);
266 259
		return resultLayerDefinition;
267
		
260

  
268 261
	}
269
	
270 262

  
271
	
272
	
273
	
274 263

  
275
		
276
	   
277
		
278 264

  
265

  
266

  
267

  
268

  
269

  
270

  
271

  
279 272
}
280 273

  

Also available in: Unified diff