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

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

    
23
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue;
24
import es.unex.sextante.core.Sextante;
25
import es.unex.sextante.dataObjects.IVectorLayer;
26
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
27
import es.unex.sextante.exceptions.RepeatedParameterNameException;
28
import es.unex.sextante.outputs.OutputVectorLayer;
29

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

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

    
44
        public static final String  RESULT    = "RESULT";
45
        public static final String  LAYER     = "LAYER";
46
        public static final String  CHECK     = "CHECK";
47
        public static final String  X         = "X";
48
        public static final String  Y         = "Y";
49

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

    
112
}