root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / removeRepeatedGeometries / RemoveRepeatedGeometriesAlgorithm.java @ 59
History | View | Annotate | Download (2.7 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.vectorTools.removeRepeatedGeometries; |
4 |
|
5 |
import java.util.HashMap; |
6 |
|
7 |
import com.vividsolutions.jts.geom.Geometry; |
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 RemoveRepeatedGeometriesAlgorithm |
22 |
extends
|
23 |
GeoAlgorithm { |
24 |
|
25 |
public static final String LAYER = "LAYER"; |
26 |
public static final String RESULT = "RESULT"; |
27 |
|
28 |
|
29 |
@Override
|
30 |
public void defineCharacteristics() { |
31 |
|
32 |
setName(Sextante.getText("Remove_repeated_geometries"));
|
33 |
setGroup(Sextante.getText("Tools_for_vector_layers"));
|
34 |
setUserCanDefineAnalysisExtent(true);
|
35 |
|
36 |
try {
|
37 |
m_Parameters.addInputVectorLayer(LAYER, Sextante.getText("Input_layer"), AdditionalInfoVectorLayer.SHAPE_TYPE_ANY, true); |
38 |
addOutputVectorLayer(RESULT, Sextante.getText("Unique_Geometries"), OutputVectorLayer.SHAPE_TYPE_UNDEFINED, LAYER);
|
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 |
int i = 0; |
51 |
final IVectorLayer layerIn = m_Parameters.getParameterValueAsVectorLayer(RemoveRepeatedGeometriesAlgorithm.LAYER);
|
52 |
if (!m_bIsAutoExtent) {
|
53 |
layerIn.addFilter(new BoundingBoxFilter(m_AnalysisExtent));
|
54 |
} |
55 |
|
56 |
final IVectorLayer driver = getNewVectorLayer(RemoveRepeatedGeometriesAlgorithm.RESULT,
|
57 |
Sextante.getText("Unique_Geometries"), layerIn.getShapeType(), layerIn.getFieldTypes(), layerIn.getFieldNames());
|
58 |
|
59 |
//Map geometries using WKT format to index
|
60 |
final HashMap geomHashMap = new HashMap(); |
61 |
|
62 |
final int iTotal = layerIn.getShapesCount(); |
63 |
final IFeatureIterator iter = layerIn.iterator();
|
64 |
|
65 |
while (iter.hasNext() && setProgress(i, iTotal)) {
|
66 |
final IFeature feat = iter.next();
|
67 |
final Geometry geom = feat.getGeometry();
|
68 |
final Object[] values = feat.getRecord().getValues(); |
69 |
if (geomHashMap.containsKey(geom.toText())) {
|
70 |
continue;
|
71 |
} |
72 |
else {
|
73 |
geomHashMap.put(geom.toText(), true);
|
74 |
} |
75 |
driver.addFeature(geom, values); |
76 |
i++; |
77 |
} |
78 |
iter.close(); |
79 |
|
80 |
return !m_Task.isCanceled();
|
81 |
|
82 |
} |
83 |
|
84 |
} |