root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / convexhull / ConvexHullGeoprocessController.java @ 5412
History | View | Annotate | Download (5.12 KB)
1 | 5412 | azabala | /*
|
---|---|---|---|
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$
|
||
47 | * $Log$
|
||
48 | * Revision 1.1 2006-05-24 21:13:52 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:23 azabala
|
||
52 | * refactoring of ITask api
|
||
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.convexhull; |
||
60 | |||
61 | import java.io.File; |
||
62 | import java.util.HashMap; |
||
63 | |||
64 | import com.iver.andami.PluginServices; |
||
65 | import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition; |
||
66 | import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager; |
||
67 | import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
||
68 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
69 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
70 | import com.iver.cit.gvsig.geoprocess.convexhull.fmap.ConvexHullGeoprocess; |
||
71 | import com.iver.cit.gvsig.geoprocess.convexhull.gui.GeoProcessingConvexHullPanel; |
||
72 | import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController; |
||
73 | import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
||
74 | import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
||
75 | import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask; |
||
76 | import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel; |
||
77 | import com.iver.utiles.swing.threads.IMonitorableTask; |
||
78 | import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst; |
||
79 | |||
80 | public class ConvexHullGeoprocessController extends |
||
81 | AbstractGeoprocessController { |
||
82 | |||
83 | |||
84 | private GeoProcessingConvexHullPanel geoProcessingConvexHullPanel;
|
||
85 | private ConvexHullGeoprocess convexHull;
|
||
86 | public void setView(IGeoprocessPanel viewPanel) { |
||
87 | this.geoProcessingConvexHullPanel =
|
||
88 | (GeoProcessingConvexHullPanel) viewPanel; |
||
89 | } |
||
90 | public IGeoprocess getGeoprocess() {
|
||
91 | return convexHull;
|
||
92 | } |
||
93 | |||
94 | public boolean launchGeoprocess() { |
||
95 | FLyrVect inputLayer = geoProcessingConvexHullPanel.getInputLayer(); |
||
96 | FLayers layers = geoProcessingConvexHullPanel.getFLayers(); |
||
97 | File outputFile = geoProcessingConvexHullPanel.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 | geoProcessingConvexHullPanel.error(errorDescription, error); |
||
102 | return false; |
||
103 | } |
||
104 | ConvexHullGeoprocess convexHull = new ConvexHullGeoprocess();
|
||
105 | convexHull.setFirstOperand(inputLayer); |
||
106 | |||
107 | SHPLayerDefinition definition = (SHPLayerDefinition) convexHull |
||
108 | .createLayerDefinition(); |
||
109 | definition.setFile(outputFile); |
||
110 | ShpSchemaManager schemaManager = new ShpSchemaManager();
|
||
111 | ShpWriter writer = null;
|
||
112 | try {
|
||
113 | writer = getShpWriter(definition); |
||
114 | } catch (Exception e1) { |
||
115 | String error = PluginServices.getText(this, "Error_escritura_resultados"); |
||
116 | String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados"); |
||
117 | geoProcessingConvexHullPanel.error(errorDescription, error); |
||
118 | return false; |
||
119 | } |
||
120 | convexHull.setResultLayerProperties(writer, schemaManager); |
||
121 | HashMap params = new HashMap(); |
||
122 | boolean onlySelected = geoProcessingConvexHullPanel
|
||
123 | .isConvexHullOnlySelected(); |
||
124 | params.put("layer_selection", new Boolean(onlySelected)); |
||
125 | try {
|
||
126 | convexHull.setParameters(params); |
||
127 | convexHull.checkPreconditions(); |
||
128 | IMonitorableTask task1 = convexHull.createTask(); |
||
129 | if(task1 == null){ |
||
130 | return false; |
||
131 | |||
132 | } |
||
133 | AddResultLayerTask task2 = new AddResultLayerTask(convexHull);
|
||
134 | task2.setLayers(layers); |
||
135 | MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
|
||
136 | task2); |
||
137 | if (globalTask.preprocess())
|
||
138 | PluginServices.cancelableBackgroundExecution(globalTask); |
||
139 | |||
140 | } catch (GeoprocessException e) {
|
||
141 | String error = PluginServices.getText(this, "Error_ejecucion"); |
||
142 | String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso"); |
||
143 | geoProcessingConvexHullPanel.error(errorDescription, error); |
||
144 | return false; |
||
145 | } |
||
146 | return true; |
||
147 | } |
||
148 | |||
149 | } |