root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / fmap / AbstractGeoprocess.java @ 5412
History | View | Annotate | Download (4.78 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 5412 2006-05-24 21:15:07Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.1 2006-05-24 21:12:16 azabala
|
49 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
50 |
*
|
51 |
* Revision 1.7 2006/05/01 19:19:10 azabala
|
52 |
* la capa resultado tiene como nombre ahora solo el nombre del fichero (no la ruta completa)
|
53 |
*
|
54 |
* Revision 1.6 2006/03/17 19:52:19 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.5 2006/03/14 19:34:18 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.4 2006/03/14 18:32:46 fjp
|
61 |
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
|
62 |
*
|
63 |
* Revision 1.3 2006/03/07 21:01:33 azabala
|
64 |
* *** empty log message ***
|
65 |
*
|
66 |
* Revision 1.2 2006/03/06 19:48:39 azabala
|
67 |
* *** empty log message ***
|
68 |
*
|
69 |
* Revision 1.1 2006/02/17 16:04:28 azabala
|
70 |
* *** empty log message ***
|
71 |
*
|
72 |
*
|
73 |
*/
|
74 |
package com.iver.cit.gvsig.geoprocess.core.fmap; |
75 |
|
76 |
import java.io.File; |
77 |
import java.util.Map; |
78 |
|
79 |
import org.cresques.cts.IProjection; |
80 |
|
81 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
82 |
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
83 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
84 |
import com.iver.cit.gvsig.fmap.edition.ISchemaManager; |
85 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
86 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
87 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
88 |
import com.iver.cit.gvsig.fmap.layers.ISpatialDB; |
89 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
90 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
91 |
/**
|
92 |
* Base class with all commong logic to geoprocesses
|
93 |
* @author azabala
|
94 |
*
|
95 |
*/
|
96 |
public abstract class AbstractGeoprocess implements IGeoprocess { |
97 |
/**
|
98 |
* Writes result features in a persistent
|
99 |
* data format.
|
100 |
*/
|
101 |
protected IWriter writer;
|
102 |
/**
|
103 |
* Creates schema of result data format.
|
104 |
*/
|
105 |
protected ISchemaManager schemaManager;
|
106 |
/**
|
107 |
* All geoprocesses at least work with one
|
108 |
* vectorial layer
|
109 |
*/
|
110 |
protected FLyrVect firstLayer;
|
111 |
|
112 |
public abstract void setParameters(Map params) throws GeoprocessException; |
113 |
|
114 |
public abstract void checkPreconditions() throws GeoprocessException; |
115 |
|
116 |
public abstract void process() throws GeoprocessException; |
117 |
|
118 |
public void cancel(){ |
119 |
try {
|
120 |
schemaManager.drop(); |
121 |
} catch (EditionException e) {
|
122 |
// TODO Auto-generated catch block
|
123 |
e.printStackTrace(); |
124 |
} |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Creates a new Layer with:
|
129 |
* a) the same projection than input layer.
|
130 |
* b) an adapter created to work with writer's persistent store
|
131 |
*
|
132 |
* @return FLyrVect with geoprocess result
|
133 |
*/
|
134 |
public FLyrVect getResult() throws GeoprocessException { |
135 |
FLyrVect solution = null;
|
136 |
String fileName = ((ShpWriter)writer).getShpPath();
|
137 |
String layerName = null; |
138 |
int fileNameStart = fileName.lastIndexOf(File.separator) + 1; |
139 |
if(fileNameStart == -1) |
140 |
fileNameStart = 0;
|
141 |
layerName = fileName.substring(fileNameStart, fileName.length() /*-1*/);
|
142 |
|
143 |
File file = new File(fileName); |
144 |
IProjection proj = firstLayer.getProjection(); |
145 |
try {
|
146 |
IndexedShpDriver driver = new IndexedShpDriver();
|
147 |
driver.open(file); |
148 |
driver.initialize(); |
149 |
solution = (FLyrVect) LayerFactory.createLayer(layerName, |
150 |
driver, |
151 |
file, |
152 |
proj); |
153 |
|
154 |
//FIXME Si la capa resultado esta vacia lanzar una excepcion
|
155 |
//de Geoprocesamiento
|
156 |
return solution;
|
157 |
} catch (Exception e) { |
158 |
throw new GeoprocessException("Problemas al cargar la capa resultado", e); |
159 |
} |
160 |
} |
161 |
|
162 |
public void setResultLayerProperties(IWriter writer, |
163 |
ISchemaManager schemaManager) { |
164 |
this.writer = writer;
|
165 |
this.schemaManager = schemaManager;
|
166 |
} |
167 |
|
168 |
public abstract ILayerDefinition createLayerDefinition(); |
169 |
|
170 |
} |
171 |
|