Revision 28 org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.convexhull/src/main/java/org/gvsig/sextante/app/algorithm/convexhull/ConvexHullAlgorithm.java
ConvexHullAlgorithm.java | ||
---|---|---|
3 | 3 |
import java.util.Iterator; |
4 | 4 |
import java.util.List; |
5 | 5 |
|
6 |
import org.gvsig.fmap.dal.DataSet; |
|
6 | 7 |
import org.gvsig.fmap.dal.exception.DataException; |
7 | 8 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
8 | 9 |
import org.gvsig.fmap.dal.feature.Feature; |
9 | 10 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
10 | 11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
12 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection; |
|
11 | 13 |
import org.gvsig.fmap.geom.Geometry; |
12 | 14 |
import org.gvsig.fmap.geom.util.Converter; |
15 |
import org.gvsig.sextante.app.algorithm.base.panel.AlgorithmOutputPanel; |
|
13 | 16 |
import org.gvsig.sextante.app.extension.core.gvVectorLayer; |
14 | 17 |
|
15 | 18 |
import es.unex.sextante.core.GeoAlgorithm; |
... | ... | |
24 | 27 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
25 | 28 |
*/ |
26 | 29 |
public class ConvexHullAlgorithm extends GeoAlgorithm { |
27 |
public static final String LAYER = "LAYER"; |
|
28 |
public static final String RESULT = "RESULT"; |
|
30 |
public static final String LAYER = "LAYER"; |
|
31 |
public static final String RESULT = "RESULT"; |
|
32 |
public static final String CHECK = "CHECK"; |
|
29 | 33 |
|
30 | 34 |
public void defineCharacteristics(){ |
31 | 35 |
setName(Sextante.getText("Convex Hull")); |
... | ... | |
38 | 42 |
true); |
39 | 43 |
addOutputVectorLayer(RESULT, |
40 | 44 |
Sextante.getText("ConvexHull"), |
41 |
OutputVectorLayer.SHAPE_TYPE_UNDEFINED); |
|
42 |
setExternalParameters((Object)new ConvexHullOutputPanel()); |
|
45 |
OutputVectorLayer.SHAPE_TYPE_POLYGON); |
|
46 |
m_Parameters.addBoolean(CHECK, Sextante.getText("Selected_geometries"), false); |
|
47 |
setExternalParameters((Object)new AlgorithmOutputPanel()); |
|
43 | 48 |
} catch (RepeatedParameterNameException e) { |
44 | 49 |
Sextante.addErrorToLog(e); |
45 | 50 |
} |
... | ... | |
52 | 57 |
@SuppressWarnings("unchecked") |
53 | 58 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
54 | 59 |
IVectorLayer input = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
60 |
boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean(); |
|
55 | 61 |
|
56 | 62 |
FeatureStore store = null; |
57 | 63 |
|
... | ... | |
65 | 71 |
FeatureSet features = null; |
66 | 72 |
try { |
67 | 73 |
features = store.getFeatureSet(); |
68 |
DisposableIterator it = features.iterator(); |
|
74 |
|
|
75 |
DisposableIterator it = null; |
|
76 |
if(selectedGeom) { |
|
77 |
DataSet ds = store.getSelection(); |
|
78 |
it = ((DefaultFeatureSelection)ds).iterator(); |
|
79 |
} else |
|
80 |
it = features.iterator(); |
|
81 |
|
|
69 | 82 |
while( it.hasNext() ) { |
70 | 83 |
Feature feature = (Feature)it.next(); |
71 | 84 |
List geomList = feature.getGeometries(); |
... | ... | |
86 | 99 |
Class [] types = {Integer.class}; |
87 | 100 |
IVectorLayer output = getNewVectorLayer(RESULT, |
88 | 101 |
Sextante.getText("ConvexHull"), |
89 |
input.getShapeType(), types, sNames);
|
|
102 |
OutputVectorLayer.SHAPE_TYPE_POLYGON, types, sNames);
|
|
90 | 103 |
output.addFeature(Converter.geometryToJts(g), new Object[]{new Integer(0)}); |
91 | 104 |
it.dispose(); |
92 | 105 |
} catch (DataException e) { |
Also available in: Unified diff