root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / boundingbox / BoundingBoxAlgorithm.java @ 59
History | View | Annotate | Download (2.48 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.vectorTools.boundingbox; |
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 BoundingBoxAlgorithm |
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 |
int i = 0; |
31 |
|
32 |
final IVectorLayer layerIn = m_Parameters.getParameterValueAsVectorLayer(LAYER);
|
33 |
if (!m_bIsAutoExtent) {
|
34 |
layerIn.addFilter(new BoundingBoxFilter(m_AnalysisExtent));
|
35 |
} |
36 |
|
37 |
final IVectorLayer result = getNewVectorLayer(RESULT, Sextante.getText("Bounding Box"), IVectorLayer.SHAPE_TYPE_POLYGON, |
38 |
layerIn.getFieldTypes(), layerIn.getFieldNames()); |
39 |
|
40 |
final IFeatureIterator iter = layerIn.iterator();
|
41 |
final int iTotal = layerIn.getShapesCount(); |
42 |
while (iter.hasNext() && setProgress(i, iTotal)) {
|
43 |
final IFeature feature = iter.next();
|
44 |
final Geometry bbox = getBBox(feature.getGeometry());
|
45 |
result.addFeature(bbox, feature.getRecord().getValues()); |
46 |
setProgress(i, iTotal); |
47 |
i++; |
48 |
} |
49 |
iter.close(); |
50 |
|
51 |
return !m_Task.isCanceled();
|
52 |
} |
53 |
|
54 |
|
55 |
@Override
|
56 |
public void defineCharacteristics() { |
57 |
|
58 |
setName(Sextante.getText("Bounding_Box"));
|
59 |
setGroup(Sextante.getText("Tools_for_vector_layers"));
|
60 |
setUserCanDefineAnalysisExtent(true);
|
61 |
|
62 |
try {
|
63 |
m_Parameters.addInputVectorLayer(LAYER, Sextante.getText("Layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true); |
64 |
addOutputVectorLayer(RESULT, Sextante.getText("Bounding_Box"), OutputVectorLayer.SHAPE_TYPE_POLYGON);
|
65 |
} |
66 |
catch (final RepeatedParameterNameException e) { |
67 |
Sextante.addErrorToLog(e); |
68 |
} |
69 |
|
70 |
} |
71 |
|
72 |
|
73 |
private Geometry getBBox(final Geometry geometry) { |
74 |
|
75 |
return geometry.getEnvelope();
|
76 |
|
77 |
} |
78 |
|
79 |
} |