gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.difference / src / main / java / org / gvsig / geoprocess / algorithm / difference / DifferenceAlgorithm.java @ 271
History | View | Annotate | Download (4.53 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.geoprocess.algorithm.difference; |
25 |
|
26 |
import org.gvsig.fmap.dal.exception.DataException; |
27 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
28 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
29 |
import org.gvsig.fmap.dal.feature.FeatureType; |
30 |
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation; |
31 |
import org.gvsig.geoprocess.algorithm.base.core.ScalableUnionOperation; |
32 |
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess; |
33 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer; |
34 |
|
35 |
import es.unex.sextante.core.Sextante; |
36 |
import es.unex.sextante.dataObjects.IVectorLayer; |
37 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
38 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
39 |
import es.unex.sextante.outputs.OutputVectorLayer; |
40 |
|
41 |
/**
|
42 |
* Difference algorithm
|
43 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
44 |
*/
|
45 |
public class DifferenceAlgorithm extends AbstractSextanteGeoProcess { |
46 |
|
47 |
public static final String RESULT = "RESULT"; |
48 |
public static final String LAYER = "LAYER"; |
49 |
public static final String DIF = "DIF"; |
50 |
public static final String CHECK = "CHECK"; |
51 |
|
52 |
public void defineCharacteristics(){ |
53 |
setName(getTranslation("Difference"));
|
54 |
setGroup(getTranslation("basic_vect_algorithms"));
|
55 |
// setGeneratesUserDefinedRasterOutput(false);
|
56 |
|
57 |
try {
|
58 |
m_Parameters.addInputVectorLayer(LAYER, |
59 |
getTranslation("Input_layer"),
|
60 |
IVectorLayer.SHAPE_TYPE_WRONG, |
61 |
true);
|
62 |
m_Parameters.addInputVectorLayer(DIF, |
63 |
getTranslation("Overlays_layer"),
|
64 |
IVectorLayer.SHAPE_TYPE_WRONG, |
65 |
true);
|
66 |
m_Parameters.addBoolean(CHECK, |
67 |
getTranslation("Selected_geometries"), false); |
68 |
} catch (RepeatedParameterNameException e) {
|
69 |
Sextante.addErrorToLog(e); |
70 |
} |
71 |
addOutputVectorLayer(RESULT, |
72 |
getTranslation("Difference"),
|
73 |
OutputVectorLayer.SHAPE_TYPE_UNDEFINED); |
74 |
} |
75 |
|
76 |
/*
|
77 |
* (non-Javadoc)
|
78 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
|
79 |
*/
|
80 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
81 |
if(existsOutPutFile(DifferenceAlgorithm.RESULT, 0)) { |
82 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
83 |
} |
84 |
org.gvsig.fmap.geom.Geometry overlayGeometry = null;
|
85 |
IVectorLayer dif = m_Parameters.getParameterValueAsVectorLayer(DIF); |
86 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
87 |
boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
|
88 |
|
89 |
try {
|
90 |
overlayGeometry = ScalableUnionOperation.joinLayerGeometries(dif); |
91 |
} catch (Exception e) { |
92 |
Sextante.addErrorToLog(e); |
93 |
return false; |
94 |
} |
95 |
|
96 |
FeatureStore storeLayer = null;
|
97 |
if(layer instanceof FlyrVectIVectorLayer) |
98 |
storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore(); |
99 |
else
|
100 |
return false; |
101 |
|
102 |
try {
|
103 |
FeatureSet features = null;
|
104 |
features = storeLayer.getFeatureSet(); |
105 |
FeatureType featureType = features.getDefaultFeatureType(); |
106 |
FeatureStore outFeatStore = |
107 |
buildOutPutStore(featureType, layer.getShapeType(), |
108 |
getTranslation("Difference"), RESULT);
|
109 |
|
110 |
GeometryOperation operation = new DifferenceOperation(overlayGeometry);
|
111 |
operation.setTaskStatus(getStatus()); |
112 |
operation.computesGeometryOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
|
113 |
} catch (DataException e) {
|
114 |
Sextante.addErrorToLog(e); |
115 |
return false; |
116 |
} |
117 |
|
118 |
return true; |
119 |
} |
120 |
|
121 |
} |