root / tags / v1_0_2_Build_892 / extensions / extGeoprocessingExtensions / src / com / iver / cit / gvsig / geoprocess / impl / xyshift / XYShiftGeoprocessController.java @ 10278
History | View | Annotate | Download (6.19 KB)
1 |
/*
|
---|---|
2 |
* Created on 28-jun-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: XYShiftGeoprocessController.java 10278 2007-02-12 15:50:11Z $
|
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:17:55 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.2 2006/06/29 17:58:31 azabala
|
61 |
* *** empty log message ***
|
62 |
*
|
63 |
* Revision 1.1 2006/06/28 18:17:21 azabala
|
64 |
* first version in cvs
|
65 |
*
|
66 |
*
|
67 |
*/
|
68 |
package com.iver.cit.gvsig.geoprocess.impl.xyshift; |
69 |
|
70 |
import java.io.File; |
71 |
import java.io.FileNotFoundException; |
72 |
import java.util.HashMap; |
73 |
|
74 |
import com.iver.andami.PluginServices; |
75 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
76 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
77 |
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
78 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
79 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
80 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController; |
81 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
82 |
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
83 |
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask; |
84 |
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
85 |
import com.iver.cit.gvsig.geoprocess.impl.xyshift.fmap.XYShiftGeoprocess; |
86 |
import com.iver.cit.gvsig.geoprocess.impl.xyshift.gui.GeoprocessingXYShiftPanel; |
87 |
import com.iver.cit.gvsig.geoprocess.impl.xyshift.gui.GeoprocessingXYShiftPanel2; |
88 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
89 |
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
90 |
|
91 |
public class XYShiftGeoprocessController extends AbstractGeoprocessController { |
92 |
|
93 |
private GeoprocessingXYShiftPanel2 panel;
|
94 |
private XYShiftGeoprocess xyShift;
|
95 |
|
96 |
|
97 |
public void setView(IGeoprocessPanel viewPanel) { |
98 |
this.panel = (GeoprocessingXYShiftPanel2) viewPanel;
|
99 |
} |
100 |
|
101 |
public IGeoprocess getGeoprocess() {
|
102 |
return xyShift;
|
103 |
} |
104 |
|
105 |
public boolean launchGeoprocess() { |
106 |
FLyrVect inputLayer = panel.getInputLayer(); |
107 |
FLayers layers = panel.getFLayers(); |
108 |
File outputFile = null; |
109 |
try {
|
110 |
outputFile = panel.getOutputFile(); |
111 |
} catch (FileNotFoundException e3) { |
112 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
113 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
114 |
panel.error(errorDescription, error); |
115 |
return false; |
116 |
} |
117 |
if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
118 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
119 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
120 |
panel.error(errorDescription, error); |
121 |
return false; |
122 |
} |
123 |
if (outputFile.exists()) {
|
124 |
if (!panel.askForOverwriteOutputFile(outputFile)) {
|
125 |
return false; |
126 |
} |
127 |
} |
128 |
xyShift = new XYShiftGeoprocess(inputLayer);
|
129 |
SHPLayerDefinition definition = |
130 |
(SHPLayerDefinition) xyShift.createLayerDefinition(); |
131 |
definition.setFile(outputFile); |
132 |
ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
|
133 |
IWriter writer = null;
|
134 |
try {
|
135 |
writer = getShpWriter(definition); |
136 |
} catch (Exception e1) { |
137 |
String error = PluginServices.getText(this, "Error_escritura_resultados"); |
138 |
String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
139 |
panel.error(errorDescription, error); |
140 |
return false; |
141 |
} |
142 |
xyShift.setResultLayerProperties(writer, schemaManager); |
143 |
HashMap params = new HashMap(); |
144 |
boolean onlySelected = panel.isFirstOnlySelected();
|
145 |
params.put("firstlayerselection", new Boolean(onlySelected)); |
146 |
try {
|
147 |
double xShift = panel.getXOffset();
|
148 |
params.put("xshift", new Double(xShift)); |
149 |
double yShift = panel.getYOffset();
|
150 |
params.put("yshift", new Double(yShift)); |
151 |
} catch (GeoprocessException e1) {
|
152 |
String error = PluginServices.getText(this, "Error_escritura_resultados"); |
153 |
String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
154 |
panel.error(errorDescription, error); |
155 |
return false; |
156 |
} |
157 |
|
158 |
try {
|
159 |
xyShift.setParameters(params); |
160 |
xyShift.checkPreconditions(); |
161 |
IMonitorableTask task1 = xyShift.createTask(); |
162 |
if(task1 == null){ |
163 |
return false; |
164 |
|
165 |
} |
166 |
AddResultLayerTask task2 = new AddResultLayerTask(xyShift);
|
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 |
public int getWidth() { |
183 |
return 750; |
184 |
} |
185 |
|
186 |
public int getHeight() { |
187 |
return 240; |
188 |
} |
189 |
} |
190 |
|