Statistics
| Revision:

gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.algorithm / org.gvsig.sextante.app.algorithm.reproject / src / main / java / org / gvsig / sextante / app / algorithm / reproject / ReprojectAlgorithm.java @ 172

History | View | Annotate | Download (4.02 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2010 Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.sextante.app.algorithm.reproject;
20

    
21
import es.unex.sextante.core.Sextante;
22
import es.unex.sextante.dataObjects.IVectorLayer;
23
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
24
import es.unex.sextante.exceptions.RepeatedParameterNameException;
25
import es.unex.sextante.outputs.OutputVectorLayer;
26

    
27
import org.cresques.cts.IProjection;
28

    
29
import org.gvsig.fmap.crs.CRSFactory;
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.core.gvGeoAlgorithm;
35
import org.gvsig.geoprocess.core.gvVectorLayer;
36

    
37
/**
38
 * Reproject algorithm
39
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
40
 */
41
public class ReprojectAlgorithm extends gvGeoAlgorithm {
42
        public static final String        RESULT            = "RESULT";
43
        public static final String        LAYER             = "LAYER";
44
        public static final String        SELECTED_GEOM     = "SELECTED_GEOM";
45
        public static final String        DST_PROJECTION    = "DST_PROJECTION";
46
        
47
        /*
48
         * (non-Javadoc)
49
         * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
50
         */
51
        public void defineCharacteristics() {
52
                setName(Sextante.getText("Reproject"));
53
                setGroup(Sextante.getText("gvSIG_Algorithms"));
54
        // setGeneratesUserDefinedRasterOutput(false);
55
                
56
                try {
57
                        m_Parameters.addInputVectorLayer(LAYER, 
58
                                                                                                Sextante.getText("Input_layer"), 
59
                                                                                                IVectorLayer.SHAPE_TYPE_WRONG, 
60
                                                                                                true);
61
                        m_Parameters.addBoolean(SELECTED_GEOM, 
62
                                                                        Sextante.getText("Selected_geometries"), 
63
                                                                        false);
64
                        m_Parameters.addString(DST_PROJECTION, Sextante.getText("Projection"));
65
                        addOutputVectorLayer(RESULT,
66
                                                                Sextante.getText("Reproject"),
67
                                                                OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
68
                } catch (RepeatedParameterNameException e) {
69
                        Sextante.addErrorToLog(e);
70
                }
71
        }
72
        
73
        /*
74
         * (non-Javadoc)
75
         * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
76
         */
77
        public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
78
                IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
79
                boolean selectedGeom = m_Parameters.getParameterValueAsBoolean(SELECTED_GEOM);
80
                String dstProj = m_Parameters.getParameterValueAsString(DST_PROJECTION);
81
                
82
                FeatureStore storeLayer = null;
83
                if(layer instanceof gvVectorLayer)
84
                        storeLayer = ((gvVectorLayer)layer).getFeatureStore();
85
                else
86
                        return false;
87
                
88
                try {
89
                        FeatureSet features = null;
90
                        features = storeLayer.getFeatureSet();
91
                        FeatureType featureType = features.getDefaultFeatureType();
92
                        FeatureStore outFeatStore = buildOutPutStore(featureType, layer.getShapeType(), Sextante.getText("Reproject"), RESULT);
93
                        IProjection projOutput = CRSFactory.getCRS(dstProj);
94
                        ReprojectOperation operation = new ReprojectOperation(((IProjection)layer.getCRS()), projOutput);
95
                        operation.setProgressModel(this);
96
                        operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true);
97
                } catch (DataException e) {
98
                        Sextante.addErrorToLog(e);
99
                        return false;
100
                }
101
                return true;
102
        }
103
}