root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / spatialjoin / SpatialJoinGeoprocessController.java @ 5412
History | View | Annotate | Download (6.75 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: SpatialJoinGeoprocessController.java 5412 2006-05-24 21:15:07Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1 2006-05-24 21:09:47 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.spatialjoin; |
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.gui.GeoProcessingDissolvePanel; |
77 |
import com.iver.cit.gvsig.geoprocess.spatialjoin.fmap.SpatialJoinGeoprocess; |
78 |
import com.iver.cit.gvsig.geoprocess.spatialjoin.gui.GeoProcessingSpatialjoinPanel; |
79 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
80 |
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
81 |
|
82 |
public class SpatialJoinGeoprocessController extends |
83 |
AbstractGeoprocessController { |
84 |
|
85 |
private GeoProcessingSpatialjoinPanel geoProcessingSpatialjoinPanel;
|
86 |
private SpatialJoinGeoprocess spatialJoin;
|
87 |
|
88 |
public void setView(IGeoprocessPanel viewPanel) { |
89 |
this.geoProcessingSpatialjoinPanel =
|
90 |
(GeoProcessingSpatialjoinPanel) viewPanel; |
91 |
} |
92 |
public IGeoprocess getGeoprocess() {
|
93 |
return spatialJoin;
|
94 |
} |
95 |
|
96 |
public boolean launchGeoprocess() { |
97 |
// this open a modal dialog and sets sumarize functions
|
98 |
Map sumarizeFunctions = null; |
99 |
if (!geoProcessingSpatialjoinPanel.isNearestSelected()){
|
100 |
boolean isOk = geoProcessingSpatialjoinPanel.openSumarizeFunction();
|
101 |
if(! isOk){
|
102 |
//Ok button wasnt pushed. Dialog was closed directly
|
103 |
return false; |
104 |
} |
105 |
sumarizeFunctions = geoProcessingSpatialjoinPanel |
106 |
.getSumarizeFunctions(); |
107 |
if(sumarizeFunctions == null || sumarizeFunctions.size() == 0){ |
108 |
geoProcessingSpatialjoinPanel.error(PluginServices.getText(this, "Error_spjoinmn_sin_funcion"), |
109 |
PluginServices.getText(this, "Error_entrada_datos")); |
110 |
} |
111 |
} |
112 |
FLyrVect inputLayer = geoProcessingSpatialjoinPanel.getFirstLayer(); |
113 |
FLyrVect secondLayer = geoProcessingSpatialjoinPanel.getSecondLayer(); |
114 |
FLayers layers = geoProcessingSpatialjoinPanel.getFLayers(); |
115 |
File outputFile = geoProcessingSpatialjoinPanel.getOutputFile();
|
116 |
if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) { |
117 |
String error = PluginServices.getText(this, "Error_entrada_datos"); |
118 |
String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado"); |
119 |
geoProcessingSpatialjoinPanel.error(errorDescription, error); |
120 |
return false; |
121 |
} |
122 |
boolean onlyFirstSelection = geoProcessingSpatialjoinPanel
|
123 |
.onlyFirstLayerSelected(); |
124 |
boolean onlySecondSelection = geoProcessingSpatialjoinPanel
|
125 |
.onlySecondLayerSelected(); |
126 |
boolean nearest = geoProcessingSpatialjoinPanel.isNearestSelected();
|
127 |
SpatialJoinGeoprocess join = new SpatialJoinGeoprocess(inputLayer);
|
128 |
join.setSecondOperand(secondLayer); |
129 |
join.setFields_sumFunctions(sumarizeFunctions); |
130 |
HashMap params = new HashMap(); |
131 |
Boolean first = new Boolean(onlyFirstSelection); |
132 |
params.put("firstlayerselection", first);
|
133 |
|
134 |
Boolean second = new Boolean(onlySecondSelection); |
135 |
params.put("secondlayerselection", second);
|
136 |
|
137 |
Boolean nearSel = new Boolean(nearest); |
138 |
params.put("nearest", nearSel);
|
139 |
try {
|
140 |
ShpSchemaManager schemaManager = new ShpSchemaManager();
|
141 |
ShpWriter writer = new ShpWriter();
|
142 |
join.setResultLayerProperties(writer, schemaManager); |
143 |
join.setParameters(params); |
144 |
SHPLayerDefinition definition = |
145 |
(SHPLayerDefinition) join.createLayerDefinition(); |
146 |
definition.setFile(outputFile); |
147 |
writer.setFile(definition.getFile()); |
148 |
writer.initialize(definition); |
149 |
writer = getShpWriter(definition); |
150 |
join.checkPreconditions(); |
151 |
IMonitorableTask task1 = join.createTask(); |
152 |
if(task1 == null){ |
153 |
//mensaje de error
|
154 |
return false; |
155 |
} |
156 |
AddResultLayerTask task2 = new AddResultLayerTask(join);
|
157 |
task2.setLayers(layers); |
158 |
MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
159 |
task2); |
160 |
if(secondLayer.getISpatialIndex() == null){ |
161 |
final IMonitorableTask sptIdxTask =
|
162 |
geoProcessingSpatialjoinPanel.askForSpatialIndexCreation(secondLayer); |
163 |
PluginServices.backgroundExecution( |
164 |
new Runnable(){ |
165 |
public void run() { |
166 |
PluginServices. |
167 |
cancelableBackgroundExecution(sptIdxTask); |
168 |
}} |
169 |
); |
170 |
}//if
|
171 |
if (globalTask.preprocess())
|
172 |
PluginServices.cancelableBackgroundExecution(globalTask); |
173 |
} catch (GeoprocessException e) {
|
174 |
String error = PluginServices.getText(this, "Error_ejecucion"); |
175 |
String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
176 |
geoProcessingSpatialjoinPanel.error(errorDescription, error); |
177 |
return false; |
178 |
|
179 |
} catch (Exception e) { |
180 |
String error = PluginServices.getText(this, "Error_escritura_resultados"); |
181 |
String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
182 |
geoProcessingSpatialjoinPanel.error(errorDescription, error); |
183 |
return false; |
184 |
} |
185 |
return true; |
186 |
} |
187 |
|
188 |
} |
189 |
|