root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / dissolve / DissolveGeoprocessController.java @ 5412
History | View | Annotate | Download (6.2 KB)
1 |
/*
|
---|---|
2 |
* Created on 11-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: DissolveGeoprocessController.java 5412 2006-05-24 21:15:07Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1 2006-05-24 21:11:14 azabala
|
49 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
50 |
*
|
51 |
* Revision 1.2 2006/05/08 15:35:32 azabala
|
52 |
* *** empty log message ***
|
53 |
*
|
54 |
* Revision 1.1 2006/04/11 17:55:51 azabala
|
55 |
* primera version en cvs
|
56 |
*
|
57 |
*
|
58 |
*/
|
59 |
package com.iver.cit.gvsig.geoprocess.dissolve; |
60 |
|
61 |
import java.io.File; |
62 |
import java.util.HashMap; |
63 |
import java.util.Map; |
64 |
|
65 |
import com.iver.andami.PluginServices; |
66 |
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
67 |
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
68 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
70 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
71 |
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController; |
72 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
73 |
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
74 |
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask; |
75 |
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
76 |
import com.iver.cit.gvsig.geoprocess.dissolve.fmap.DissolveGeoprocess; |
77 |
import com.iver.cit.gvsig.geoprocess.dissolve.gui.GeoProcessingDissolvePanel; |
78 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
79 |
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
80 |
|
81 |
public class DissolveGeoprocessController extends AbstractGeoprocessController { |
82 |
private GeoProcessingDissolvePanel geoProcessingDissolvePanel;
|
83 |
private DissolveGeoprocess dissolve;
|
84 |
|
85 |
public void setView(IGeoprocessPanel viewPanel) { |
86 |
this.geoProcessingDissolvePanel =
|
87 |
(GeoProcessingDissolvePanel) viewPanel; |
88 |
} |
89 |
|
90 |
public IGeoprocess getGeoprocess() {
|
91 |
return dissolve;
|
92 |
} |
93 |
|
94 |
public boolean launchGeoprocess() { |
95 |
FLyrVect inputLayer = geoProcessingDissolvePanel.getInputLayer(); |
96 |
FLayers layers = geoProcessingDissolvePanel.getFLayers(); |
97 |
File outputFile = geoProcessingDissolvePanel.getOutputFile();
|
98 |
if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
99 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
100 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
101 |
geoProcessingDissolvePanel.error(errorDescription, error); |
102 |
return false; |
103 |
} |
104 |
String dissolveField = geoProcessingDissolvePanel
|
105 |
.getDissolveFieldName(); |
106 |
boolean onlySelection = geoProcessingDissolvePanel
|
107 |
.isDissolveOnlySelected(); |
108 |
boolean onlyAdjacents = geoProcessingDissolvePanel.onlyAdjacentSelected();
|
109 |
DissolveGeoprocess dissolve = new DissolveGeoprocess(inputLayer,
|
110 |
dissolveField); |
111 |
|
112 |
// Antes de crear el esquema vemos la seleccion del usuario
|
113 |
Map fields_functions = geoProcessingDissolvePanel.getFieldFunctionMap();
|
114 |
dissolve.setFieldsFunctions(fields_functions); |
115 |
|
116 |
HashMap params = new HashMap(); |
117 |
params.put("layer_selection", new Boolean(onlySelection)); |
118 |
params.put("only_adjacents", new Boolean(onlyAdjacents)); |
119 |
try {
|
120 |
dissolve.setParameters(params); |
121 |
} catch (GeoprocessException e1) {
|
122 |
String error = PluginServices.getText(this, "Error_escritura_resultados"); |
123 |
String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
124 |
geoProcessingDissolvePanel.error(errorDescription, error); |
125 |
return false; |
126 |
} |
127 |
|
128 |
SHPLayerDefinition definition = (SHPLayerDefinition) dissolve |
129 |
.createLayerDefinition(); |
130 |
definition.setFile(outputFile); |
131 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
132 |
|
133 |
ShpWriter writer = null;
|
134 |
try {
|
135 |
schemaManager.createOrAlterSchema(definition); |
136 |
writer = new ShpWriter();
|
137 |
writer.setFile(outputFile); |
138 |
writer.initialize(definition); |
139 |
} catch (Exception e) { |
140 |
String error = PluginServices.getText(this, "Error_escritura_resultados"); |
141 |
String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
142 |
geoProcessingDissolvePanel.error(errorDescription, error); |
143 |
return false; |
144 |
} |
145 |
dissolve.setResultLayerProperties(writer, schemaManager); |
146 |
|
147 |
try {
|
148 |
|
149 |
dissolve.checkPreconditions(); |
150 |
IMonitorableTask task1 = dissolve.createTask(); |
151 |
AddResultLayerTask task2 = new AddResultLayerTask(dissolve);
|
152 |
task2.setLayers(layers); |
153 |
MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
154 |
task2); |
155 |
if(inputLayer.getISpatialIndex() == null){ |
156 |
final IMonitorableTask sptIdxTask =
|
157 |
geoProcessingDissolvePanel.askForSpatialIndexCreation(inputLayer); |
158 |
if(sptIdxTask != null){ |
159 |
PluginServices.backgroundExecution( |
160 |
new Runnable(){ |
161 |
public void run() { |
162 |
PluginServices. |
163 |
cancelableBackgroundExecution(sptIdxTask); |
164 |
}} |
165 |
); |
166 |
} |
167 |
}//if
|
168 |
if (globalTask.preprocess())
|
169 |
PluginServices.cancelableBackgroundExecution(globalTask); |
170 |
} catch (GeoprocessException e) {
|
171 |
String error = PluginServices.getText(this, "Error_ejecucion"); |
172 |
String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
173 |
geoProcessingDissolvePanel.error(errorDescription, error); |
174 |
return false; |
175 |
} |
176 |
return true; |
177 |
} |
178 |
|
179 |
} |
180 |
|