root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / splitMultipart / SplitMultipartAlgorithm.java @ 59
History | View | Annotate | Download (2.63 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.vectorTools.splitMultipart; |
4 |
|
5 |
import com.vividsolutions.jts.geom.Geometry; |
6 |
|
7 |
import es.unex.sextante.additionalInfo.AdditionalInfoVectorLayer; |
8 |
import es.unex.sextante.core.GeoAlgorithm; |
9 |
import es.unex.sextante.core.Sextante; |
10 |
import es.unex.sextante.dataObjects.IFeature; |
11 |
import es.unex.sextante.dataObjects.IFeatureIterator; |
12 |
import es.unex.sextante.dataObjects.IVectorLayer; |
13 |
import es.unex.sextante.dataObjects.vectorFilters.BoundingBoxFilter; |
14 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
15 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
16 |
import es.unex.sextante.outputs.OutputVectorLayer; |
17 |
|
18 |
|
19 |
public class SplitMultipartAlgorithm |
20 |
extends
|
21 |
GeoAlgorithm { |
22 |
|
23 |
public static final String INPUT = "INPUT"; |
24 |
public static final String RESULT = "RESULT"; |
25 |
|
26 |
private IVectorLayer m_Output;
|
27 |
private IVectorLayer m_Input;
|
28 |
|
29 |
|
30 |
@Override
|
31 |
public void defineCharacteristics() { |
32 |
|
33 |
setName(Sextante.getText("Separate_multi-part_features"));
|
34 |
setGroup(Sextante.getText("Tools_for_vector_layers"));
|
35 |
setUserCanDefineAnalysisExtent(true);
|
36 |
|
37 |
try {
|
38 |
m_Parameters.addInputVectorLayer(INPUT, Sextante.getText("Layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true); |
39 |
addOutputVectorLayer(RESULT, Sextante.getText("Result"), OutputVectorLayer.SHAPE_TYPE_UNDEFINED, INPUT);
|
40 |
} |
41 |
catch (final RepeatedParameterNameException e) { |
42 |
Sextante.addErrorToLog(e); |
43 |
} |
44 |
|
45 |
} |
46 |
|
47 |
|
48 |
@Override
|
49 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
50 |
|
51 |
int i;
|
52 |
|
53 |
m_Input = m_Parameters.getParameterValueAsVectorLayer(INPUT); |
54 |
if (!m_bIsAutoExtent) {
|
55 |
m_Input.addFilter(new BoundingBoxFilter(m_AnalysisExtent));
|
56 |
} |
57 |
|
58 |
m_Output = getNewVectorLayer(RESULT, Sextante.getText("Result"), m_Input.getShapeType(), m_Input.getFieldTypes(),
|
59 |
m_Input.getFieldNames()); |
60 |
|
61 |
if (m_Input.getShapesCount() == 0) { |
62 |
return false; |
63 |
} |
64 |
|
65 |
i = 0;
|
66 |
final int iShapeCount = m_Input.getShapesCount(); |
67 |
final IFeatureIterator iter = m_Input.iterator();
|
68 |
while (iter.hasNext() && setProgress(i, iShapeCount)) {
|
69 |
final IFeature feature = iter.next();
|
70 |
final Geometry geom = feature.getGeometry();
|
71 |
final Object[] values = feature.getRecord().getValues(); |
72 |
for (int j = 0; j < geom.getNumGeometries(); j++) { |
73 |
final Geometry subgeom = geom.getGeometryN(j);
|
74 |
m_Output.addFeature(subgeom, values); |
75 |
} |
76 |
} |
77 |
|
78 |
return !m_Task.isCanceled();
|
79 |
|
80 |
} |
81 |
|
82 |
} |