root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / cleanVectorLayer / CleanVectorLayerAlgorithm.java @ 59
History | View | Annotate | Download (2.33 KB)
1 |
package es.unex.sextante.vectorTools.cleanVectorLayer; |
---|---|
2 |
|
3 |
|
4 |
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer; |
5 |
import es.unex.sextante.core.GeoAlgorithm; |
6 |
import es.unex.sextante.core.Sextante; |
7 |
import es.unex.sextante.dataObjects.IFeature; |
8 |
import es.unex.sextante.dataObjects.IFeatureIterator; |
9 |
import es.unex.sextante.dataObjects.IVectorLayer; |
10 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
11 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
12 |
import es.unex.sextante.outputs.OutputVectorLayer; |
13 |
|
14 |
public class CleanVectorLayerAlgorithm |
15 |
extends
|
16 |
GeoAlgorithm { |
17 |
|
18 |
private static final String LAYER = "LAYER"; |
19 |
private static final String RESULT = "RESULT"; |
20 |
|
21 |
|
22 |
@Override
|
23 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
24 |
|
25 |
int iWrongShapes = 0; |
26 |
final IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
|
27 |
|
28 |
final IVectorLayer output = getNewVectorLayer(RESULT, Sextante.getText("Result"), layer.getShapeType(), |
29 |
layer.getFieldTypes(), layer.getFieldNames()); |
30 |
final int iShapeCount = layer.getShapesCount(); |
31 |
int i = 0; |
32 |
final IFeatureIterator iter = layer.iterator();
|
33 |
while (iter.hasNext() && setProgress(i, iShapeCount)) {
|
34 |
try {
|
35 |
final IFeature feature = iter.next();
|
36 |
output.addFeature(feature); |
37 |
} |
38 |
catch (final Exception e) { |
39 |
iWrongShapes++; |
40 |
} |
41 |
i++; |
42 |
} |
43 |
|
44 |
String sInfo = Sextante.getText("Eliminados_N_Registros_erroneos)"); |
45 |
sInfo = sInfo.replace("XXX", Integer.toString(iWrongShapes)); |
46 |
Sextante.addInfoToLog(sInfo); |
47 |
|
48 |
return !m_Task.isCanceled();
|
49 |
|
50 |
} |
51 |
|
52 |
|
53 |
@Override
|
54 |
public void defineCharacteristics() { |
55 |
|
56 |
setName(Sextante.getText("Clean_vector_layer"));
|
57 |
setGroup(Sextante.getText("Tools_for_vector_layers"));
|
58 |
setUserCanDefineAnalysisExtent(false);
|
59 |
|
60 |
try {
|
61 |
m_Parameters.addInputVectorLayer(LAYER, Sextante.getText("Layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true); |
62 |
addOutputVectorLayer(RESULT, Sextante.getText("Result"), OutputVectorLayer.SHAPE_TYPE_UNDEFINED, LAYER);
|
63 |
} |
64 |
catch (final RepeatedParameterNameException e) { |
65 |
Sextante.addErrorToLog(e); |
66 |
} |
67 |
|
68 |
} |
69 |
|
70 |
} |