Statistics
| Revision:

gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.xyshift / src / main / java / org / gvsig / geoprocess / algorithm / xyshift / XYShiftAlgorithm.java @ 245

History | View | Annotate | Download (4.48 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.xyshift;
25

    
26
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue;
27
import es.unex.sextante.core.Sextante;
28
import es.unex.sextante.dataObjects.IVectorLayer;
29
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
30
import es.unex.sextante.exceptions.RepeatedParameterNameException;
31
import es.unex.sextante.outputs.OutputVectorLayer;
32

    
33
import org.gvsig.fmap.dal.exception.DataException;
34
import org.gvsig.fmap.dal.feature.FeatureSet;
35
import org.gvsig.fmap.dal.feature.FeatureStore;
36
import org.gvsig.fmap.dal.feature.FeatureType;
37
import org.gvsig.geoprocess.algorithm.base.core.GeometryOperation;
38
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
39
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
40

    
41
/**
42
 * XYShift algorithm
43
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
44
 */
45
public class XYShiftAlgorithm extends AbstractSextanteGeoProcess {
46

    
47
        public static final String  RESULT    = "RESULT";
48
        public static final String  LAYER     = "LAYER";
49
        public static final String  CHECK     = "CHECK";
50
        public static final String  X         = "X";
51
        public static final String  Y         = "Y";
52

    
53
        /*
54
         * (non-Javadoc)
55
         * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
56
         */
57
        public void defineCharacteristics(){
58
        setName(getTranslation("XYShift"));
59
        setGroup(getTranslation("basic_vect_algorithms"));
60
        // setGeneratesUserDefinedRasterOutput(false);
61
                
62
                try {
63
                        m_Parameters.addInputVectorLayer(LAYER, 
64
                getTranslation("Input_layer"),
65
                                                                                                IVectorLayer.SHAPE_TYPE_WRONG, 
66
                                                                                                true);
67
            m_Parameters.addBoolean(CHECK,
68
                getTranslation("Selected_geometries"), false);
69
            m_Parameters.addNumericalValue(X, getTranslation("X_traslation"),
70
                0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE);
71
            m_Parameters.addNumericalValue(Y, getTranslation("Y_traslation"),
72
                0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE);
73
                } catch (RepeatedParameterNameException e) {
74
                        Sextante.addErrorToLog(e);
75
                }
76
        addOutputVectorLayer(RESULT, getTranslation("XY-Shift"),
77
            OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
78
        }
79
        
80
        /*
81
         * (non-Javadoc)
82
         * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
83
         */
84
        public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
85
                IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
86
                boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
87
                double x = m_Parameters.getParameterValueAsDouble(X);
88
                double y = m_Parameters.getParameterValueAsDouble(Y);
89
                
90
                FeatureStore storeLayer = null;
91
                if(layer instanceof FlyrVectIVectorLayer)
92
                        storeLayer = ((FlyrVectIVectorLayer)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 =
101
                buildOutPutStore(featureType, layer.getShapeType(),
102
                    getTranslation("XYShift"), RESULT);
103
                        
104
                        GeometryOperation operation = new XYShiftOperation(x, y);
105
            operation.setTaskStatus(getStatus());
106
                        operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
107
                } catch (DataException e) {
108
                        Sextante.addErrorToLog(e);
109
                        return false;
110
                }
111
                
112
                return true;
113
        }
114

    
115
}