root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / autoincrementValue / AutoincrementValueAlgorithm.java @ 59
History | View | Annotate | Download (2.8 KB)
1 |
package es.unex.sextante.vectorTools.autoincrementValue; |
---|---|
2 |
|
3 |
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer; |
4 |
import es.unex.sextante.core.GeoAlgorithm; |
5 |
import es.unex.sextante.core.Sextante; |
6 |
import es.unex.sextante.dataObjects.IFeature; |
7 |
import es.unex.sextante.dataObjects.IFeatureIterator; |
8 |
import es.unex.sextante.dataObjects.IRecord; |
9 |
import es.unex.sextante.dataObjects.IVectorLayer; |
10 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
11 |
import es.unex.sextante.exceptions.OptionalParentParameterException; |
12 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
13 |
import es.unex.sextante.exceptions.UndefinedParentParameterNameException; |
14 |
import es.unex.sextante.outputs.OutputVectorLayer; |
15 |
|
16 |
public class AutoincrementValueAlgorithm |
17 |
extends
|
18 |
GeoAlgorithm { |
19 |
|
20 |
public static final String LAYER = "LAYER"; |
21 |
public static final String FIELD = "FIELD"; |
22 |
public static final String RESULT = "RESULT"; |
23 |
|
24 |
|
25 |
@Override
|
26 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
27 |
|
28 |
int i = 0; |
29 |
|
30 |
final IVectorLayer layerIn = m_Parameters.getParameterValueAsVectorLayer(LAYER);
|
31 |
final int iField = m_Parameters.getParameterValueAsInt(FIELD); |
32 |
final IVectorLayer result = getNewVectorLayer(RESULT, Sextante.getText("Autoincrement_Value"), layerIn.getShapeType(), |
33 |
layerIn.getFieldTypes(), layerIn.getFieldNames()); |
34 |
|
35 |
final IFeatureIterator iter = layerIn.iterator();
|
36 |
final int iTotal = layerIn.getShapesCount(); |
37 |
while (iter.hasNext() && setProgress(i, iTotal)) {
|
38 |
final IFeature feature = iter.next();
|
39 |
final IRecord record = feature.getRecord();
|
40 |
final Object[] values = record.getValues(); |
41 |
values[iField] = i; |
42 |
result.addFeature(feature.getGeometry(), values); |
43 |
i++; |
44 |
} |
45 |
iter.close(); |
46 |
|
47 |
return !m_Task.isCanceled();
|
48 |
} |
49 |
|
50 |
|
51 |
@Override
|
52 |
public void defineCharacteristics() { |
53 |
|
54 |
setName(Sextante.getText("Autoincrement_Value"));
|
55 |
setGroup(Sextante.getText("Tools_for_vector_layers"));
|
56 |
setUserCanDefineAnalysisExtent(false);
|
57 |
|
58 |
try {
|
59 |
m_Parameters.addInputVectorLayer(LAYER, Sextante.getText("Input_layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true); |
60 |
m_Parameters.addTableField(FIELD, Sextante.getText("Attribute"), LAYER);
|
61 |
addOutputVectorLayer(RESULT, Sextante.getText("Autoincrement_Value"), OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
|
62 |
} |
63 |
catch (final RepeatedParameterNameException e) { |
64 |
Sextante.addErrorToLog(e); |
65 |
} |
66 |
catch (final UndefinedParentParameterNameException e) { |
67 |
Sextante.addErrorToLog(e); |
68 |
} |
69 |
catch (final OptionalParentParameterException e) { |
70 |
Sextante.addErrorToLog(e); |
71 |
} |
72 |
} |
73 |
|
74 |
} |