Statistics
| Revision:

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 @ 237

History | View | Annotate | Download (4.19 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
package org.gvsig.geoprocess.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.algorithm.base.core.GeometryOperation;
34
import org.gvsig.geoprocess.algorithm.base.core.ScalableUnionOperation;
35
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
36
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
37

    
38
/**
39
 * Difference algorithm
40
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
41
 */
42
public class DifferenceAlgorithm extends AbstractSextanteGeoProcess {
43

    
44
        public static final String  RESULT    = "RESULT";
45
        public static final String  LAYER     = "LAYER";
46
        public static final String  DIF       = "DIF";
47
        public static final String  CHECK     = "CHECK";
48

    
49
        public void defineCharacteristics(){
50
                setName(Sextante.getText("Difference"));
51
                setGroup(Sextante.getText("gvSIG_Algorithms"));
52
        // setGeneratesUserDefinedRasterOutput(false);
53
                
54
                try {
55
                        m_Parameters.addInputVectorLayer(LAYER, 
56
                                                                                                Sextante.getText("Input_layer"), 
57
                                                                                                IVectorLayer.SHAPE_TYPE_WRONG, 
58
                                                                                                true);
59
                        m_Parameters.addInputVectorLayer(DIF, 
60
                                                                                                Sextante.getText("Overlays_layer"), 
61
                                                                                                IVectorLayer.SHAPE_TYPE_WRONG, 
62
                                                                                                true);
63
                        m_Parameters.addBoolean(CHECK, Sextante.getText("Selected_geometries"), false);
64
                } catch (RepeatedParameterNameException e) {
65
                        Sextante.addErrorToLog(e);
66
                }
67
                addOutputVectorLayer(RESULT,
68
                                                                Sextante.getText( "Difference"),
69
                                                                OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
70
        }
71
        
72
        /*
73
         * (non-Javadoc)
74
         * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
75
         */
76
        public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
77
                org.gvsig.fmap.geom.Geometry overlayGeometry = null;
78
                IVectorLayer dif = m_Parameters.getParameterValueAsVectorLayer(DIF);
79
                IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
80
                boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
81
                
82
                try {
83
                        overlayGeometry = ScalableUnionOperation.joinLayerGeometries(dif);
84
                } catch (Exception e) {
85
                        Sextante.addErrorToLog(e);
86
                        return false;
87
                }
88
                
89
                FeatureStore storeLayer = null;
90
                if(layer instanceof FlyrVectIVectorLayer)
91
                        storeLayer = ((FlyrVectIVectorLayer)layer).getFeatureStore();
92
                else
93
                        return false;
94
                
95
                try {
96
                        FeatureSet features = null;
97
                        features = storeLayer.getFeatureSet();
98
                        FeatureType featureType = features.getDefaultFeatureType();
99
                        FeatureStore outFeatStore = buildOutPutStore(featureType, layer.getShapeType(), Sextante.getText("Difference"), RESULT);
100

    
101
                        GeometryOperation operation = new DifferenceOperation(overlayGeometry);
102
            operation.setTaskStatus(getStatus());
103
                        operation.computesGeometryOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
104
                } catch (DataException e) {
105
                        Sextante.addErrorToLog(e);
106
                        return false;
107
                }
108
                
109
                return true;
110
        }
111

    
112
}