Statistics
| Revision:

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

History | View | Annotate | Download (4.24 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 org.gvsig.fmap.dal.exception.DataException;
24
import org.gvsig.fmap.dal.feature.FeatureSet;
25
import org.gvsig.fmap.dal.feature.FeatureStore;
26
import org.gvsig.fmap.dal.feature.FeatureType;
27
import org.gvsig.sextante.app.algorithm.base.core.GeometryOperation;
28
import org.gvsig.sextante.app.algorithm.base.core.ScalableUnionOperation;
29
import org.gvsig.sextante.app.algorithm.base.panel.AlgorithmOutputPanel;
30
import org.gvsig.sextante.app.extension.core.gvGeoAlgorithm;
31
import org.gvsig.sextante.app.extension.core.gvVectorLayer;
32

    
33
import es.unex.sextante.core.Sextante;
34
import es.unex.sextante.dataObjects.IVectorLayer;
35
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
36
import es.unex.sextante.exceptions.RepeatedParameterNameException;
37
import es.unex.sextante.outputs.OutputVectorLayer;
38

    
39
/**
40
 * Difference algorithm
41
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
42
 */
43
public class DifferenceAlgorithm extends gvGeoAlgorithm {
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
                setExternalParameters((Object)new AlgorithmOutputPanel());
71
        }
72
        
73
        /*
74
         * (non-Javadoc)
75
         * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
76
         */
77
        public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
78
                org.gvsig.fmap.geom.Geometry overlayGeometry = null;
79
                IVectorLayer dif = m_Parameters.getParameterValueAsVectorLayer(DIF);
80
                IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
81
                boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
82
                
83
                try {
84
                        overlayGeometry = ScalableUnionOperation.joinLayerGeometries(dif);
85
                } catch (Exception e) {
86
                        Sextante.addErrorToLog(e);
87
                        return false;
88
                }
89
                
90
                FeatureStore storeLayer = null;
91
                if(layer instanceof gvVectorLayer)
92
                        storeLayer = ((gvVectorLayer)layer).getFeatureStore();
93
                else
94
                        return false;
95
                
96
                try {
97
                        FeatureSet features = null;
98
                        features = storeLayer.getFeatureSet();
99
                        FeatureType featureType = features.getDefaultFeatureType();
100
                        FeatureStore outFeatStore = buildOutPutStore(featureType, layer.getShapeType(), Sextante.getText("Difference"), RESULT);
101

    
102
                        GeometryOperation operation = new DifferenceOperation(overlayGeometry);
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
}