Statistics
| Revision:

root / trunk / extensions / extGeoprocessingExtensions / src / com / iver / cit / gvsig / geoprocess / impl / reproject / ReprojectGeoprocessController.java @ 6179

History | View | Annotate | Download (5.39 KB)

1
/*
2
 * Created on 03-jul-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
*
46
* $Id: ReprojectGeoprocessController.java 6179 2006-07-04 16:43:18Z azabala $
47
* $Log$
48
* Revision 1.2  2006-07-04 16:43:18  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.1  2006/07/03 20:28:29  azabala
52
* *** empty log message ***
53
*
54
*
55
*/
56
package com.iver.cit.gvsig.geoprocess.impl.reproject;
57

    
58
import java.io.File;
59
import java.util.HashMap;
60

    
61
import org.cresques.cts.IProjection;
62

    
63
import com.iver.andami.PluginServices;
64
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
65
import com.iver.cit.gvsig.fmap.edition.IWriter;
66
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
67
import com.iver.cit.gvsig.fmap.layers.FLayers;
68
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
69
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController;
70
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
71
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
72
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
73
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel;
74
import com.iver.cit.gvsig.geoprocess.impl.reproject.fmap.ReprojectGeoprocess;
75
import com.iver.cit.gvsig.geoprocess.impl.reproject.gui.GeoprocessingReprojectPanel;
76
import com.iver.cit.gvsig.geoprocess.impl.xyshift.fmap.XYShiftGeoprocess;
77
import com.iver.utiles.swing.threads.IMonitorableTask;
78
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
79

    
80
public class ReprojectGeoprocessController extends AbstractGeoprocessController {
81

    
82
        private GeoprocessingReprojectPanel panel;
83
        private ReprojectGeoprocess reproject;
84
        
85
        public void setView(IGeoprocessPanel viewPanel) {
86
                this.panel = (GeoprocessingReprojectPanel) viewPanel;
87
        }
88

    
89
        public IGeoprocess getGeoprocess() {
90
                return new ReprojectGeoprocess();
91
        }
92

    
93
        public boolean launchGeoprocess() {
94
                FLyrVect inputLayer = panel.getInputLayer();
95
                FLayers layers = panel.getFLayers();
96
                File outputFile = panel.getOutputFile();
97
                if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
98
                        String error = PluginServices.getText(this, "Error_entrada_datos");
99
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
100
                        panel.error(errorDescription, error);
101
                        return false;
102
                }
103
                if (outputFile.exists()) {
104
                        if (!panel.askForOverwriteOutputFile(outputFile)) {
105
                                return false;
106
                        }
107
                }
108
                reproject = (ReprojectGeoprocess) getGeoprocess();
109
                reproject.setFirstLayer(inputLayer);
110
                SHPLayerDefinition definition = 
111
                        (SHPLayerDefinition) reproject.createLayerDefinition();
112
                definition.setFile(outputFile);
113
                ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
114
                IWriter writer = null;
115
                try {
116
                        writer = getShpWriter(definition);
117
                } catch (Exception e1) {
118
                        String error = PluginServices.getText(this, "Error_escritura_resultados");
119
                        String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados");
120
                        panel.error(errorDescription, error);
121
                        return false;
122
                } 
123
                reproject.setResultLayerProperties(writer, schemaManager);
124
                HashMap params = new HashMap();
125
                boolean onlySelected = panel.isFirstOnlySelected();
126
                params.put("firstlayerselection", new Boolean(onlySelected));
127
                IProjection projection = panel.getTargetProjection();
128
                IProjection previousProj = inputLayer.getProjection();
129
                if(previousProj.equals(projection)){
130
                        String error = PluginServices.getText(this, "Error_entrada_datos");
131
                        String errorDesc = PluginServices.getText(this, "Error_proyecciones_iguales");
132
                        panel.error(errorDesc, error);
133
                        return false;
134
                }
135
                params.put("targetProjection", projection);
136
                
137
                try {
138
                        reproject.setParameters(params);
139
                        reproject.checkPreconditions();
140
                        IMonitorableTask task1 = reproject.createTask();
141
                        if(task1 == null){
142
                                return false;
143
                                
144
                        }
145
                        AddResultLayerTask task2 = new AddResultLayerTask(reproject);
146
                        task2.setLayers(layers);
147
                        MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
148
                                        task2);
149
                        if (globalTask.preprocess())
150
                                PluginServices.cancelableBackgroundExecution(globalTask);
151
                        
152
                } catch (GeoprocessException e) {
153
                        String error = PluginServices.getText(this, "Error_ejecucion");
154
                        String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso");
155
                        panel.error(errorDescription, error);
156
                        return false;
157
                }
158
                return true;
159
        }
160

    
161
}
162