svn-gvsig-desktop / tags / v1_0_2_Build_906 / extensions / extGeoprocessingExtensions / src / com / iver / cit / gvsig / geoprocess / impl / reproject / ReprojectGeoprocessController.java @ 10972
History | View | Annotate | Download (6.27 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 10972 2007-03-29 11:33:05Z $
|
47 |
* $Log$
|
48 |
* Revision 1.3.2.2 2006-11-29 12:51:36 jmvivo
|
49 |
* Se ha a?adido mas informaci?n al mensaje de error para los GeoprocessException: e.getMessage()
|
50 |
*
|
51 |
* Revision 1.3.2.1 2006/11/15 00:08:17 jjdelcerro
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.4 2006/10/23 15:16:12 jmvivo
|
55 |
* implementados el getWidth y el getHeight
|
56 |
*
|
57 |
* Revision 1.3 2006/08/11 17:20:32 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.2 2006/07/04 16:43:18 azabala
|
61 |
* *** empty log message ***
|
62 |
*
|
63 |
* Revision 1.1 2006/07/03 20:28:29 azabala
|
64 |
* *** empty log message ***
|
65 |
*
|
66 |
*
|
67 |
*/
|
68 |
package com.iver.cit.gvsig.geoprocess.impl.reproject; |
69 |
|
70 |
import java.io.File; |
71 |
import java.io.FileNotFoundException; |
72 |
import java.util.HashMap; |
73 |
|
74 |
import org.cresques.cts.IProjection; |
75 |
|
76 |
import com.iver.andami.PluginServices; |
77 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
78 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
79 |
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
80 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
81 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
82 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController; |
83 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
84 |
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
85 |
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask; |
86 |
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
87 |
import com.iver.cit.gvsig.geoprocess.impl.reproject.fmap.ReprojectGeoprocess; |
88 |
import com.iver.cit.gvsig.geoprocess.impl.reproject.gui.GeoprocessingReprojectPanel; |
89 |
import com.iver.cit.gvsig.geoprocess.impl.xyshift.fmap.XYShiftGeoprocess; |
90 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
91 |
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
92 |
|
93 |
public class ReprojectGeoprocessController extends AbstractGeoprocessController { |
94 |
|
95 |
private GeoprocessingReprojectPanel panel;
|
96 |
private ReprojectGeoprocess reproject;
|
97 |
|
98 |
public void setView(IGeoprocessPanel viewPanel) { |
99 |
this.panel = (GeoprocessingReprojectPanel) viewPanel;
|
100 |
} |
101 |
|
102 |
public IGeoprocess getGeoprocess() {
|
103 |
return new ReprojectGeoprocess(); |
104 |
} |
105 |
|
106 |
public boolean launchGeoprocess() { |
107 |
FLyrVect inputLayer = panel.getInputLayer(); |
108 |
FLayers layers = panel.getFLayers(); |
109 |
File outputFile = null; |
110 |
try {
|
111 |
outputFile = panel.getOutputFile(); |
112 |
} catch (FileNotFoundException e3) { |
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 == null || (outputFile.getAbsolutePath().length() == 0)) { |
119 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
120 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
121 |
panel.error(errorDescription, error); |
122 |
return false; |
123 |
} |
124 |
if (outputFile.exists()) {
|
125 |
if (!panel.askForOverwriteOutputFile(outputFile)) {
|
126 |
return false; |
127 |
} |
128 |
} |
129 |
reproject = (ReprojectGeoprocess) getGeoprocess(); |
130 |
reproject.setFirstLayer(inputLayer); |
131 |
SHPLayerDefinition definition = |
132 |
(SHPLayerDefinition) reproject.createLayerDefinition(); |
133 |
definition.setFile(outputFile); |
134 |
ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
135 |
IWriter writer = null;
|
136 |
try {
|
137 |
writer = getShpWriter(definition); |
138 |
} catch (Exception e1) { |
139 |
String error = PluginServices.getText(this, "Error_escritura_resultados"); |
140 |
String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
141 |
panel.error(errorDescription, error); |
142 |
return false; |
143 |
} |
144 |
reproject.setResultLayerProperties(writer, schemaManager); |
145 |
HashMap params = new HashMap(); |
146 |
boolean onlySelected = panel.isFirstOnlySelected();
|
147 |
params.put("firstlayerselection", new Boolean(onlySelected)); |
148 |
IProjection projection = panel.getTargetProjection(); |
149 |
IProjection previousProj = inputLayer.getProjection(); |
150 |
if(previousProj.equals(projection)){
|
151 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
152 |
String errorDesc = PluginServices.getText(this, "Error_proyecciones_iguales"); |
153 |
panel.error(errorDesc, error); |
154 |
return false; |
155 |
} |
156 |
params.put("targetProjection", projection);
|
157 |
|
158 |
try {
|
159 |
reproject.setParameters(params); |
160 |
reproject.checkPreconditions(); |
161 |
IMonitorableTask task1 = reproject.createTask(); |
162 |
if(task1 == null){ |
163 |
return false; |
164 |
|
165 |
} |
166 |
AddResultLayerTask task2 = new AddResultLayerTask(reproject);
|
167 |
task2.setLayers(layers); |
168 |
MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
169 |
task2); |
170 |
if (globalTask.preprocess())
|
171 |
PluginServices.cancelableBackgroundExecution(globalTask); |
172 |
|
173 |
} catch (GeoprocessException e) {
|
174 |
String error = PluginServices.getText(this, "Error_ejecucion"); |
175 |
String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
176 |
errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>"; |
177 |
panel.error(errorDescription, error); |
178 |
return false; |
179 |
} |
180 |
return true; |
181 |
} |
182 |
|
183 |
public int getWidth() { |
184 |
return 750; |
185 |
} |
186 |
|
187 |
public int getHeight() { |
188 |
return 220; |
189 |
} |
190 |
|
191 |
} |
192 |
|