root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / exportVector / ExportVectorAlgorithm.java @ 59
History | View | Annotate | Download (2.8 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.vectorTools.exportVector; |
4 |
|
5 |
|
6 |
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer; |
7 |
import es.unex.sextante.core.GeoAlgorithm; |
8 |
import es.unex.sextante.core.Sextante; |
9 |
import es.unex.sextante.dataObjects.IFeature; |
10 |
import es.unex.sextante.dataObjects.IFeatureIterator; |
11 |
import es.unex.sextante.dataObjects.IVectorLayer; |
12 |
import es.unex.sextante.dataObjects.vectorFilters.BoundingBoxFilter; |
13 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
14 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
15 |
import es.unex.sextante.outputs.FileOutputChannel; |
16 |
import es.unex.sextante.outputs.Output; |
17 |
|
18 |
|
19 |
public class ExportVectorAlgorithm |
20 |
extends
|
21 |
GeoAlgorithm { |
22 |
|
23 |
public static final String LAYER = "LAYER"; |
24 |
public static final String RESULT = "RESULT"; |
25 |
|
26 |
|
27 |
@Override
|
28 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
29 |
|
30 |
final IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
|
31 |
Output out = m_OutputObjects.getOutput(RESULT); |
32 |
final String sFilename = ((FileOutputChannel) out.getOutputChannel()).getFilename(); |
33 |
|
34 |
if (!m_bIsAutoExtent) {
|
35 |
layer.addFilter(new BoundingBoxFilter(m_AnalysisExtent));
|
36 |
} |
37 |
|
38 |
if (sFilename != null) { |
39 |
final IVectorLayer output = getNewVectorLayer(RESULT, Sextante.getText("Result"), layer.getShapeType(), |
40 |
layer.getFieldTypes(), layer.getFieldNames()); |
41 |
final int iShapeCount = layer.getShapesCount(); |
42 |
int i = 0; |
43 |
final IFeatureIterator iter = layer.iterator();
|
44 |
while (iter.hasNext() && setProgress(i, iShapeCount)) {
|
45 |
final IFeature feature = iter.next();
|
46 |
output.addFeature(feature); |
47 |
i++; |
48 |
} |
49 |
try {
|
50 |
output.postProcess(); |
51 |
} |
52 |
catch (final Exception e) { |
53 |
throw new GeoAlgorithmExecutionException(e.getMessage()); |
54 |
} |
55 |
} |
56 |
|
57 |
//We do not want the result to be added to the view
|
58 |
out = m_OutputObjects.getOutput(RESULT); |
59 |
out.setOutputObject(null);
|
60 |
|
61 |
return !m_Task.isCanceled();
|
62 |
|
63 |
} |
64 |
|
65 |
|
66 |
@Override
|
67 |
public void defineCharacteristics() { |
68 |
|
69 |
setName(Sextante.getText("Export_vector_layer"));
|
70 |
setGroup(Sextante.getText("Tools_for_vector_layers"));
|
71 |
setUserCanDefineAnalysisExtent(true);
|
72 |
|
73 |
try {
|
74 |
m_Parameters.addInputVectorLayer(LAYER, Sextante.getText("Layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true); |
75 |
addOutputVectorLayer(RESULT, Sextante.getText("Result"));
|
76 |
} |
77 |
catch (final RepeatedParameterNameException e) { |
78 |
Sextante.addErrorToLog(e); |
79 |
} |
80 |
|
81 |
} |
82 |
|
83 |
|
84 |
@Override
|
85 |
public boolean isSuitableForModelling() { |
86 |
|
87 |
return false; |
88 |
|
89 |
} |
90 |
|
91 |
|
92 |
} |