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