Revision 21144 branches/v2_0_0_prep/libraries/libFMap/src/org/gvsig/fmap/mapcontext/rendering/legend/AbstractIntervalLegend.java
AbstractIntervalLegend.java | ||
---|---|---|
94 | 94 |
|
95 | 95 |
import org.apache.log4j.Logger; |
96 | 96 |
import org.gvsig.data.ReadException; |
97 |
import org.gvsig.data.vectorial.Feature; |
|
98 |
import org.gvsig.data.vectorial.FeatureID; |
|
99 |
import org.gvsig.data.vectorial.FeatureStore; |
|
100 |
import org.gvsig.data.vectorial.FeatureType; |
|
97 | 101 |
import org.gvsig.fmap.mapcontext.Messages; |
98 | 102 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
99 | 103 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
... | ... | |
150 | 154 |
protected String[] fieldNames; |
151 | 155 |
protected int fieldId; |
152 | 156 |
protected ISymbol defaultSymbol; |
153 |
protected DataSource dataSource;
|
|
157 |
protected FeatureStore featureStore;
|
|
154 | 158 |
protected int intervalType = NATURAL_INTERVALS; |
155 | 159 |
protected boolean useDefaultSymbol = false; |
156 | 160 |
|
... | ... | |
165 | 169 |
/* |
166 | 170 |
* @see com.iver.cit.gvsig.fmap.rendering.IVectorialLegend#getSymbol(int) |
167 | 171 |
*/ |
168 |
public ISymbol getSymbol(int recordIndex) throws ReadException {
|
|
169 |
Value val = dataSource.getFieldValue(recordIndex, fieldId);
|
|
172 |
public ISymbol getSymbol(FeatureID featureID) throws ReadException {
|
|
173 |
Object val = featureStore.getFeatureByID(featureID).get(fieldId);
|
|
170 | 174 |
IInterval interval = getInterval(val); |
171 | 175 |
ISymbol theSymbol = getSymbolByInterval(interval); |
172 | 176 |
|
... | ... | |
181 | 185 |
} |
182 | 186 |
|
183 | 187 |
|
184 |
public ISymbol getSymbolByFeature(IFeature feat) { |
|
185 |
Value val = feat.getAttribute(FLyrVect.forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD |
|
186 |
? 0 :fieldId); |
|
188 |
public ISymbol getSymbolByFeature(Feature feat) { |
|
189 |
Object val = feat.get(fieldId); |
|
187 | 190 |
IInterval interval = getInterval(val); |
188 | 191 |
ISymbol theSymbol = getSymbolByInterval(interval); |
189 | 192 |
|
... | ... | |
208 | 211 |
} |
209 | 212 |
|
210 | 213 |
|
211 |
public FInterval[] calculateIntervals(DataSource recordSet, String fieldName, int numIntervalos, int shapeType)
|
|
214 |
public FInterval[] calculateIntervals(FeatureStore featureStore, String fieldName, int numIntervalos, int shapeType)
|
|
212 | 215 |
throws ReadException, LegendLayerException { |
213 | 216 |
logger.debug("elRs.start()"); |
214 |
recordSet.start(); |
|
217 |
// recordSet.start();
|
|
215 | 218 |
|
216 | 219 |
int idField = -1; |
217 | 220 |
|
218 | 221 |
setClassifyingFieldNames(new String[] {fieldName}); |
219 | 222 |
|
220 | 223 |
String[] fieldNames = getClassifyingFieldNames(); |
224 |
Iterator iterator=featureStore.getDataCollection(new String[]{fieldName},null,null).iterator(); |
|
221 | 225 |
|
222 | 226 |
|
223 |
for (int i = 0; i < recordSet.getFieldCount(); i++) { |
|
224 |
String nomAux = recordSet.getFieldName(i).trim(); |
|
227 |
// for (int i = 0; i < recordSet.getFieldCount(); i++) { |
|
228 |
// String nomAux = recordSet.getFieldName(i).trim(); |
|
229 |
// |
|
230 |
// if (fieldNames[0].compareToIgnoreCase(nomAux) == 0) { |
|
231 |
// idField = i; |
|
232 |
// |
|
233 |
// break; |
|
234 |
// } |
|
235 |
// } |
|
225 | 236 |
|
226 |
if (fieldNames[0].compareToIgnoreCase(nomAux) == 0) { |
|
227 |
idField = i; |
|
228 |
|
|
229 |
break; |
|
230 |
} |
|
231 |
} |
|
232 |
|
|
233 | 237 |
if (idField == -1) { |
234 | 238 |
logger.error("Campo no reconocido " + fieldNames); |
235 | 239 |
|
... | ... | |
244 | 248 |
|
245 | 249 |
Object clave; |
246 | 250 |
|
247 |
for (int j = 0; j < recordSet.getRowCount(); j++) {
|
|
248 |
clave = recordSet.getFieldValue(j, idField);
|
|
251 |
while (iterator.hasNext()) {
|
|
252 |
Feature feature = (Feature) iterator.next();
|
|
249 | 253 |
|
254 |
// for (int j = 0; j < recordSet.getRowCount(); j++) { |
|
255 |
clave = feature.get(idField); |
|
256 |
|
|
250 | 257 |
IInterval interval = auxLegend.getInterval(clave); |
251 | 258 |
|
252 | 259 |
////Comprobar que no esta repetido y no hace falta introducir en el hashtable el campo junto con el simbolo. |
... | ... | |
285 | 292 |
break; |
286 | 293 |
|
287 | 294 |
case VectorialIntervalLegend.NATURAL_INTERVALS: |
288 |
intervalArray = calculateNaturalIntervals(recordSet, numIntervalos,
|
|
295 |
intervalArray = calculateNaturalIntervals(featureStore, numIntervalos,
|
|
289 | 296 |
minValue, maxValue, fieldName); |
290 | 297 |
|
291 | 298 |
break; |
292 | 299 |
|
293 | 300 |
case VectorialIntervalLegend.QUANTILE_INTERVALS: |
294 |
intervalArray = calculateQuantileIntervals(recordSet, numIntervalos,
|
|
301 |
intervalArray = calculateQuantileIntervals(featureStore, numIntervalos,
|
|
295 | 302 |
minValue, maxValue, fieldName); |
296 | 303 |
|
297 | 304 |
break; |
298 | 305 |
} |
299 |
recordSet.stop(); |
|
306 |
// recordSet.stop();
|
|
300 | 307 |
return intervalArray; |
301 | 308 |
} |
302 | 309 |
|
... | ... | |
345 | 352 |
* @return Array con los intervalos. |
346 | 353 |
* @throws LegendLayerException |
347 | 354 |
*/ |
348 |
private FInterval[] calculateNaturalIntervals(DataSource recordSet, int numIntervals, double minValue,
|
|
355 |
private FInterval[] calculateNaturalIntervals(FeatureStore featureStore, int numIntervals, double minValue,
|
|
349 | 356 |
double maxValue, String fieldName) throws LegendLayerException { |
350 | 357 |
NaturalIntervalGenerator intervalGenerator = new NaturalIntervalGenerator( |
351 |
recordSet, fieldName, numIntervals);
|
|
358 |
featureStore, fieldName, numIntervals);
|
|
352 | 359 |
|
353 | 360 |
try { |
354 | 361 |
intervalGenerator.generarIntervalos(); |
... | ... | |
397 | 404 |
* @return Array con los intervalos. |
398 | 405 |
* @throws LegendLayerException |
399 | 406 |
*/ |
400 |
private FInterval[] calculateQuantileIntervals(DataSource recordSet, int numIntervals, double minValue,
|
|
407 |
private FInterval[] calculateQuantileIntervals(FeatureStore featureStore, int numIntervals, double minValue,
|
|
401 | 408 |
double maxValue, String fieldName) throws LegendLayerException { |
402 | 409 |
QuantileIntervalGenerator intervalGenerator = new QuantileIntervalGenerator( |
403 |
recordSet, fieldName, numIntervals);
|
|
410 |
featureStore, fieldName, numIntervals);
|
|
404 | 411 |
|
405 | 412 |
try { |
406 | 413 |
intervalGenerator.generarIntervalos(); |
... | ... | |
493 | 500 |
} |
494 | 501 |
|
495 | 502 |
|
496 |
public void setDataSource(DataSource ds) |
|
497 |
throws FieldNotFoundException, ReadException { |
|
498 |
if (!FLyrVect.forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD) { |
|
503 |
public void setFeatureStore(FeatureStore featureStore) |
|
504 |
throws ReadException { |
|
499 | 505 |
/* |
500 | 506 |
* when we move definitely to feature iterators this |
501 | 507 |
* method |
502 | 508 |
*/ |
503 |
dataSource = ds; |
|
504 |
ds.start(); |
|
505 |
fieldId = ds.getFieldIndexByName(fieldNames[0]); |
|
506 |
ds.stop(); |
|
507 |
} |
|
509 |
this.featureStore = featureStore; |
|
510 |
// ds.start(); |
|
511 |
fieldId = ((FeatureType)featureStore.getFeatureTypes().get(0)).getFieldIndex(fieldNames[0]); |
|
512 |
// ds.stop(); |
|
508 | 513 |
} |
509 | 514 |
|
510 | 515 |
|
Also available in: Unified diff