root / trunk / extensions / extTopology / src / com / iver / cit / gvsig / geoprocess / impl / referencing / ReferencingGeoprocessController.java @ 23163
History | View | Annotate | Download (6.04 KB)
1 |
/*
|
---|---|
2 |
* Created on 10-abr-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:
|
47 |
* $Log:
|
48 |
*/
|
49 |
package com.iver.cit.gvsig.geoprocess.impl.referencing; |
50 |
|
51 |
import java.io.File; |
52 |
import java.io.FileNotFoundException; |
53 |
import java.util.HashMap; |
54 |
|
55 |
import org.opengis.referencing.operation.MathTransform; |
56 |
|
57 |
import com.iver.andami.PluginServices; |
58 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
59 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
60 |
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
62 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
63 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController; |
64 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
65 |
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
66 |
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask; |
67 |
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessUserEntries; |
68 |
import com.iver.cit.gvsig.geoprocess.impl.referencing.fmap.ReferencingGeoprocess; |
69 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
70 |
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
71 |
|
72 |
public class ReferencingGeoprocessController extends AbstractGeoprocessController { |
73 |
|
74 |
private IReferencingGeoprocessUserEntries userEntries;
|
75 |
private ReferencingGeoprocess geoprocess;
|
76 |
|
77 |
public void setView(IGeoprocessUserEntries viewPanel) { |
78 |
this.userEntries = (IReferencingGeoprocessUserEntries) viewPanel;
|
79 |
} |
80 |
|
81 |
public IGeoprocess getGeoprocess() {
|
82 |
return geoprocess;
|
83 |
} |
84 |
|
85 |
public boolean launchGeoprocess() { |
86 |
/*MOVER A CLASE ABSTRACTA*/
|
87 |
final FLyrVect inputLayer = userEntries.getInputLayer();
|
88 |
FLayers layers = userEntries.getFLayers(); |
89 |
File outputFile = null; |
90 |
try {
|
91 |
outputFile = userEntries.getOutputFile(); |
92 |
} catch (FileNotFoundException e3) { |
93 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
94 |
String errorDescription = PluginServices.getText(this, |
95 |
"Error_seleccionar_resultado");
|
96 |
userEntries.error(errorDescription, error); |
97 |
return false; |
98 |
} |
99 |
if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
100 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
101 |
String errorDescription = PluginServices.getText(this, |
102 |
"Error_seleccionar_resultado");
|
103 |
userEntries.error(errorDescription, error); |
104 |
return false; |
105 |
} |
106 |
if (outputFile.exists()) {
|
107 |
if (!userEntries.askForOverwriteOutputFile(outputFile)) {
|
108 |
return false; |
109 |
} |
110 |
} |
111 |
/*MOVER A CLASE ABSTRACTA*/
|
112 |
|
113 |
geoprocess = new ReferencingGeoprocess(inputLayer);
|
114 |
|
115 |
/*MOVER A CLASE ABSTRACTA*/
|
116 |
SHPLayerDefinition definition = (SHPLayerDefinition) geoprocess |
117 |
.createLayerDefinition(); |
118 |
definition.setFile(outputFile); |
119 |
ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile
|
120 |
.getAbsolutePath()); |
121 |
IWriter writer = null;
|
122 |
try {
|
123 |
writer = getShpWriter(definition); |
124 |
} catch (Exception e1) { |
125 |
String error = PluginServices.getText(this, |
126 |
"Error_escritura_resultados");
|
127 |
String errorDescription = PluginServices.getText(this, |
128 |
"Error_preparar_escritura_resultados");
|
129 |
userEntries.error(errorDescription, error); |
130 |
return false; |
131 |
} |
132 |
geoprocess.setResultLayerProperties(writer, schemaManager); |
133 |
|
134 |
/*MOVER A CLASE ABSTRACTA*/
|
135 |
|
136 |
HashMap params = new HashMap(); |
137 |
MathTransform mathTransform; |
138 |
try {
|
139 |
mathTransform = userEntries.getMathTransform(); |
140 |
params.put("mathTransform", mathTransform);
|
141 |
} catch (GeoprocessException e1) {
|
142 |
String error = PluginServices.getText(this,"Error_calculo_transformacion"); |
143 |
userEntries.error( PluginServices.getText(this, "Error_calculo_transformacion"), error); |
144 |
return false; |
145 |
} |
146 |
|
147 |
boolean hasAuxiliarLyrs = userEntries.hasAuxiliarLyrs();
|
148 |
params.put("hasAuxiliar", new Boolean(hasAuxiliarLyrs)); |
149 |
if(hasAuxiliarLyrs){
|
150 |
params.put("auxiliarLyrs", userEntries.getAuxiliarLyrs());
|
151 |
} |
152 |
|
153 |
/*
|
154 |
* MOVER A CLASE ABSTRACTA
|
155 |
* */
|
156 |
try {
|
157 |
geoprocess.setParameters(params); |
158 |
geoprocess.checkPreconditions(); |
159 |
IMonitorableTask task1 = geoprocess.createTask(); |
160 |
if (task1 == null) { |
161 |
return false; |
162 |
|
163 |
} |
164 |
AddResultLayerTask task2 = new AddResultLayerTask(geoprocess);
|
165 |
task2.setLayers(layers); |
166 |
MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(
|
167 |
task1, task2); |
168 |
if (globalTask.preprocess())
|
169 |
PluginServices.cancelableBackgroundExecution(globalTask); |
170 |
|
171 |
} catch (GeoprocessException e) {
|
172 |
String error = PluginServices.getText(this, "Error_ejecucion"); |
173 |
String errorDescription = PluginServices.getText(this, |
174 |
"Error_fallo_geoproceso");
|
175 |
userEntries.error(errorDescription, error); |
176 |
return false; |
177 |
} |
178 |
return true; |
179 |
/*
|
180 |
* MOVER A CLASE ABSTRACTA
|
181 |
* */
|
182 |
} |
183 |
|
184 |
public int getWidth() { |
185 |
return 700; |
186 |
} |
187 |
|
188 |
public int getHeight() { |
189 |
return 600; |
190 |
} |
191 |
|
192 |
} |