svn-gvsig-desktop / tags / v1_1_Build_1002 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / fmap / AbstractGeoprocess.java @ 12070
History | View | Annotate | Download (6.84 KB)
1 |
/*
|
---|---|
2 |
* Created on 16-feb-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: AbstractGeoprocess.java 12070 2007-06-07 14:39:32Z $
|
47 |
* $Log$
|
48 |
* Revision 1.7.2.1 2006-11-15 00:08:17 jjdelcerro
|
49 |
* *** empty log message ***
|
50 |
*
|
51 |
* Revision 1.9 2006/10/20 14:28:30 azabala
|
52 |
* changed visibility of createLayerFrom method to protected
|
53 |
*
|
54 |
* Revision 1.8 2006/09/15 10:42:54 caballero
|
55 |
* extensibilidad de documentos
|
56 |
*
|
57 |
* Revision 1.7 2006/08/29 07:56:30 cesar
|
58 |
* Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
59 |
*
|
60 |
* Revision 1.6 2006/08/29 07:21:09 cesar
|
61 |
* Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
|
62 |
*
|
63 |
* Revision 1.5 2006/06/29 07:33:57 fjp
|
64 |
* Cambios ISchemaManager y IFieldManager por terminar
|
65 |
*
|
66 |
* Revision 1.4 2006/06/20 18:19:43 azabala
|
67 |
* refactorizaci?n para que todos los nuevos geoprocesos cuelguen del paquete impl
|
68 |
*
|
69 |
* Revision 1.3 2006/06/12 19:15:38 azabala
|
70 |
* cambios para poder trabajar en geoprocessing con capas MULTI (dxf, jdbc, etc)
|
71 |
*
|
72 |
* Revision 1.2 2006/05/31 09:10:12 fjp
|
73 |
* Ubicaci?n de IWriter
|
74 |
*
|
75 |
* Revision 1.1 2006/05/24 21:12:16 azabala
|
76 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
77 |
*
|
78 |
* Revision 1.7 2006/05/01 19:19:10 azabala
|
79 |
* la capa resultado tiene como nombre ahora solo el nombre del fichero (no la ruta completa)
|
80 |
*
|
81 |
* Revision 1.6 2006/03/17 19:52:19 azabala
|
82 |
* *** empty log message ***
|
83 |
*
|
84 |
* Revision 1.5 2006/03/14 19:34:18 azabala
|
85 |
* *** empty log message ***
|
86 |
*
|
87 |
* Revision 1.4 2006/03/14 18:32:46 fjp
|
88 |
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
|
89 |
*
|
90 |
* Revision 1.3 2006/03/07 21:01:33 azabala
|
91 |
* *** empty log message ***
|
92 |
*
|
93 |
* Revision 1.2 2006/03/06 19:48:39 azabala
|
94 |
* *** empty log message ***
|
95 |
*
|
96 |
* Revision 1.1 2006/02/17 16:04:28 azabala
|
97 |
* *** empty log message ***
|
98 |
*
|
99 |
*
|
100 |
*/
|
101 |
package com.iver.cit.gvsig.geoprocess.core.fmap; |
102 |
|
103 |
import java.io.File; |
104 |
import java.util.Map; |
105 |
|
106 |
import org.cresques.cts.IProjection; |
107 |
|
108 |
import com.iver.andami.PluginServices; |
109 |
import com.iver.cit.gvsig.fmap.MapContext; |
110 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
111 |
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
112 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
113 |
import com.iver.cit.gvsig.fmap.edition.ISchemaManager; |
114 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
115 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.MultiShpWriter; |
116 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
117 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
118 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
119 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
120 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
121 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
122 |
/**
|
123 |
* Base class with all commong logic to geoprocesses
|
124 |
* @author azabala
|
125 |
*
|
126 |
*/
|
127 |
public abstract class AbstractGeoprocess implements IGeoprocess { |
128 |
/**
|
129 |
* Writes result features in a persistent
|
130 |
* data format.
|
131 |
*/
|
132 |
protected IWriter writer;
|
133 |
/**
|
134 |
* Creates schema of result data format.
|
135 |
*/
|
136 |
protected ISchemaManager schemaManager;
|
137 |
/**
|
138 |
* All geoprocesses at least work with one
|
139 |
* vectorial layer
|
140 |
*/
|
141 |
protected FLyrVect firstLayer;
|
142 |
|
143 |
public abstract void setParameters(Map params) throws GeoprocessException; |
144 |
|
145 |
public abstract void checkPreconditions() throws GeoprocessException; |
146 |
|
147 |
public abstract void process() throws GeoprocessException; |
148 |
|
149 |
public void cancel(){ |
150 |
try {
|
151 |
schemaManager.removeSchema("");
|
152 |
} catch (EditionException e) {
|
153 |
// TODO Auto-generated catch block
|
154 |
e.printStackTrace(); |
155 |
} |
156 |
} |
157 |
|
158 |
|
159 |
protected FLayer createLayerFrom(IWriter writer) throws GeoprocessException{ |
160 |
FLyrVect solution = null;
|
161 |
//Para evitar todos estos casts, hay que meter la
|
162 |
//interfaz FileWriter
|
163 |
String fileName = ((ShpWriter)writer).getShpPath();
|
164 |
String layerName = null; |
165 |
int fileNameStart = fileName.lastIndexOf(File.separator) + 1; |
166 |
if(fileNameStart == -1) |
167 |
fileNameStart = 0;
|
168 |
layerName = fileName.substring(fileNameStart, fileName.length() /*-1*/);
|
169 |
File file = new File(fileName); |
170 |
IProjection proj = firstLayer.getProjection(); |
171 |
//TODO La proyeccion se deberia leer del WRITER
|
172 |
try {
|
173 |
IndexedShpDriver driver = new IndexedShpDriver();
|
174 |
driver.open(file); |
175 |
driver.initialize(); |
176 |
solution = (FLyrVect) LayerFactory.createLayer(layerName, |
177 |
driver, |
178 |
file, |
179 |
proj); |
180 |
return solution;
|
181 |
} catch (Exception e) { |
182 |
throw new GeoprocessException("Problemas al cargar la capa resultado", e); |
183 |
} |
184 |
} |
185 |
|
186 |
/**
|
187 |
* Creates a new Layer with:
|
188 |
* a) the same projection than input layer.
|
189 |
* b) an adapter created to work with writer's persistent store
|
190 |
*
|
191 |
* @return FLyrVect with geoprocess result
|
192 |
*/
|
193 |
public FLayer getResult() throws GeoprocessException { |
194 |
if(! (writer instanceof MultiShpWriter)){ |
195 |
return createLayerFrom(writer);
|
196 |
}else{
|
197 |
IWriter[] writers = ((MultiShpWriter)writer).getWriters();
|
198 |
if(writers.length > 1){ |
199 |
MapContext map = ((View)PluginServices.
|
200 |
getMDIManager(). |
201 |
getActiveWindow()). |
202 |
getModel(). |
203 |
getMapContext(); |
204 |
FLayers solution = new FLayers(map, null); |
205 |
String name = ((MultiShpWriter)writer).getFileName();
|
206 |
int fileNameStart = name.lastIndexOf(File.separator) + 1; |
207 |
if(fileNameStart == -1) |
208 |
fileNameStart = 0;
|
209 |
name = name.substring(fileNameStart, name.length()); |
210 |
solution.setName(name); |
211 |
for(int i = 0; i < writers.length; i++){ |
212 |
solution.addLayer(createLayerFrom(writers[i])); |
213 |
} |
214 |
return solution;
|
215 |
}else{
|
216 |
return createLayerFrom(writers[0]); |
217 |
} |
218 |
} |
219 |
} |
220 |
|
221 |
public void setResultLayerProperties(IWriter writer, |
222 |
ISchemaManager schemaManager) { |
223 |
this.writer = writer;
|
224 |
this.schemaManager = schemaManager;
|
225 |
} |
226 |
|
227 |
public abstract ILayerDefinition createLayerDefinition(); |
228 |
|
229 |
} |
230 |
|