Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoprocessingExtensions / src / com / iver / cit / gvsig / geoprocess / impl / reproject / ReprojectGeoprocessController.java @ 8253

History | View | Annotate | Download (5.96 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 8253 2006-10-23 15:16:12Z jmvivo $
47
* $Log$
48
* Revision 1.4  2006-10-23 15:16:12  jmvivo
49
* implementados el getWidth y el getHeight
50
*
51
* Revision 1.3  2006/08/11 17:20:32  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.2  2006/07/04 16:43:18  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.1  2006/07/03 20:28:29  azabala
58
* *** empty log message ***
59
*
60
*
61
*/
62
package com.iver.cit.gvsig.geoprocess.impl.reproject;
63

    
64
import java.io.File;
65
import java.io.FileNotFoundException;
66
import java.util.HashMap;
67

    
68
import org.cresques.cts.IProjection;
69

    
70
import com.iver.andami.PluginServices;
71
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
72
import com.iver.cit.gvsig.fmap.edition.IWriter;
73
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
74
import com.iver.cit.gvsig.fmap.layers.FLayers;
75
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
76
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController;
77
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
78
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
79
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
80
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel;
81
import com.iver.cit.gvsig.geoprocess.impl.reproject.fmap.ReprojectGeoprocess;
82
import com.iver.cit.gvsig.geoprocess.impl.reproject.gui.GeoprocessingReprojectPanel;
83
import com.iver.cit.gvsig.geoprocess.impl.xyshift.fmap.XYShiftGeoprocess;
84
import com.iver.utiles.swing.threads.IMonitorableTask;
85
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
86

    
87
public class ReprojectGeoprocessController extends AbstractGeoprocessController {
88

    
89
        private GeoprocessingReprojectPanel panel;
90
        private ReprojectGeoprocess reproject;
91
        
92
        public void setView(IGeoprocessPanel viewPanel) {
93
                this.panel = (GeoprocessingReprojectPanel) viewPanel;
94
        }
95

    
96
        public IGeoprocess getGeoprocess() {
97
                return new ReprojectGeoprocess();
98
        }
99

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

    
176
        public int getWidth() {
177
                return 750;
178
        }
179

    
180
        public int getHeight() {
181
                return 220;
182
        }
183

    
184
}
185