gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.algorithm / org.gvsig.sextante.app.algorithm.difference / src / main / java / org / gvsig / sextante / app / algorithm / difference / DifferenceAlgorithm.java @ 172
History | View | Annotate | Download (4.13 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2010 Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
*/
|
21 |
package org.gvsig.sextante.app.algorithm.difference; |
22 |
|
23 |
import es.unex.sextante.core.Sextante; |
24 |
import es.unex.sextante.dataObjects.IVectorLayer; |
25 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
26 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
27 |
import es.unex.sextante.outputs.OutputVectorLayer; |
28 |
|
29 |
import org.gvsig.fmap.dal.exception.DataException; |
30 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
31 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
32 |
import org.gvsig.fmap.dal.feature.FeatureType; |
33 |
import org.gvsig.geoprocess.core.gvGeoAlgorithm; |
34 |
import org.gvsig.geoprocess.core.gvVectorLayer; |
35 |
import org.gvsig.sextante.app.algorithm.base.core.GeometryOperation; |
36 |
import org.gvsig.sextante.app.algorithm.base.core.ScalableUnionOperation; |
37 |
|
38 |
/**
|
39 |
* Difference algorithm
|
40 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
41 |
*/
|
42 |
public class DifferenceAlgorithm extends gvGeoAlgorithm { |
43 |
public static final String RESULT = "RESULT"; |
44 |
public static final String LAYER = "LAYER"; |
45 |
public static final String DIF = "DIF"; |
46 |
public static final String CHECK = "CHECK"; |
47 |
|
48 |
public void defineCharacteristics(){ |
49 |
setName(Sextante.getText("Difference"));
|
50 |
setGroup(Sextante.getText("gvSIG_Algorithms"));
|
51 |
// setGeneratesUserDefinedRasterOutput(false);
|
52 |
|
53 |
try {
|
54 |
m_Parameters.addInputVectorLayer(LAYER, |
55 |
Sextante.getText("Input_layer"),
|
56 |
IVectorLayer.SHAPE_TYPE_WRONG, |
57 |
true);
|
58 |
m_Parameters.addInputVectorLayer(DIF, |
59 |
Sextante.getText("Overlays_layer"),
|
60 |
IVectorLayer.SHAPE_TYPE_WRONG, |
61 |
true);
|
62 |
m_Parameters.addBoolean(CHECK, Sextante.getText("Selected_geometries"), false); |
63 |
} catch (RepeatedParameterNameException e) {
|
64 |
Sextante.addErrorToLog(e); |
65 |
} |
66 |
addOutputVectorLayer(RESULT, |
67 |
Sextante.getText( "Difference"),
|
68 |
OutputVectorLayer.SHAPE_TYPE_UNDEFINED); |
69 |
} |
70 |
|
71 |
/*
|
72 |
* (non-Javadoc)
|
73 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
|
74 |
*/
|
75 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
76 |
org.gvsig.fmap.geom.Geometry overlayGeometry = null;
|
77 |
IVectorLayer dif = m_Parameters.getParameterValueAsVectorLayer(DIF); |
78 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
79 |
boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
|
80 |
|
81 |
try {
|
82 |
overlayGeometry = ScalableUnionOperation.joinLayerGeometries(dif); |
83 |
} catch (Exception e) { |
84 |
Sextante.addErrorToLog(e); |
85 |
return false; |
86 |
} |
87 |
|
88 |
FeatureStore storeLayer = null;
|
89 |
if(layer instanceof gvVectorLayer) |
90 |
storeLayer = ((gvVectorLayer)layer).getFeatureStore(); |
91 |
else
|
92 |
return false; |
93 |
|
94 |
try {
|
95 |
FeatureSet features = null;
|
96 |
features = storeLayer.getFeatureSet(); |
97 |
FeatureType featureType = features.getDefaultFeatureType(); |
98 |
FeatureStore outFeatStore = buildOutPutStore(featureType, layer.getShapeType(), Sextante.getText("Difference"), RESULT);
|
99 |
|
100 |
GeometryOperation operation = new DifferenceOperation(overlayGeometry);
|
101 |
operation.setProgressModel(this);
|
102 |
operation.computesGeometryOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
|
103 |
} catch (DataException e) {
|
104 |
Sextante.addErrorToLog(e); |
105 |
return false; |
106 |
} |
107 |
|
108 |
return true; |
109 |
} |
110 |
|
111 |
} |