root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / topology / nodeLines / NodeLinesAlgorithm.java @ 59
History | View | Annotate | Download (2.64 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.topology.nodeLines; |
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 NodeLinesAlgorithm |
20 |
extends
|
21 |
GeoAlgorithm { |
22 |
|
23 |
public static final String RESULT = "RESULT"; |
24 |
public static final String LINES = "LINES"; |
25 |
|
26 |
private IVectorLayer m_Output;
|
27 |
|
28 |
|
29 |
@Override
|
30 |
public void defineCharacteristics() { |
31 |
|
32 |
setName(Sextante.getText("Node_lines"));
|
33 |
setGroup(Sextante.getText("Topology"));
|
34 |
setUserCanDefineAnalysisExtent(true);
|
35 |
|
36 |
try {
|
37 |
m_Parameters.addInputVectorLayer(LINES, Sextante.getText("Lines"), AdditionalInfoVectorLayer.SHAPE_TYPE_LINE, true); |
38 |
addOutputVectorLayer(RESULT, Sextante.getText("Lines"), OutputVectorLayer.SHAPE_TYPE_LINE, LINES);
|
39 |
} |
40 |
catch (final RepeatedParameterNameException e) { |
41 |
Sextante.addErrorToLog(e); |
42 |
} |
43 |
|
44 |
} |
45 |
|
46 |
|
47 |
@Override
|
48 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
49 |
|
50 |
final IVectorLayer lines = m_Parameters.getParameterValueAsVectorLayer(LINES);
|
51 |
if (!m_bIsAutoExtent) {
|
52 |
lines.addFilter(new BoundingBoxFilter(m_AnalysisExtent));
|
53 |
} |
54 |
|
55 |
m_Output = getNewVectorLayer(RESULT, Sextante.getText("Result"), IVectorLayer.SHAPE_TYPE_LINE, lines.getFieldTypes(),
|
56 |
lines.getFieldNames()); |
57 |
|
58 |
int i = 0; |
59 |
final int iShapeCount = lines.getShapesCount(); |
60 |
IFeatureIterator iter = lines.iterator(); |
61 |
IFeature feature = iter.next(); |
62 |
Geometry geom = feature.getGeometry(); |
63 |
final Geometry merged = geom;
|
64 |
while (iter.hasNext() && setProgress(i, iShapeCount)) {
|
65 |
feature = iter.next(); |
66 |
geom = feature.getGeometry(); |
67 |
merged.union(geom); |
68 |
i++; |
69 |
} |
70 |
iter.close(); |
71 |
|
72 |
i = 0;
|
73 |
iter = lines.iterator(); |
74 |
while (iter.hasNext() && setProgress(i, iShapeCount)) {
|
75 |
feature = iter.next(); |
76 |
m_Output.addFeature(merged.getGeometryN(i), feature.getRecord().getValues()); |
77 |
i++; |
78 |
} |
79 |
iter.close(); |
80 |
|
81 |
return !m_Task.isCanceled();
|
82 |
|
83 |
} |
84 |
|
85 |
} |