Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / gvsig / geoprocessing / impl / AbstractGeoprocess.java @ 4993

History | View | Annotate | Download (4.64 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 4991 2006-05-01 19:19:10Z azabala $
47
* $Log$
48
* Revision 1.7  2006-05-01 19:19:10  azabala
49
* la capa resultado tiene como nombre ahora solo el nombre del fichero (no la ruta completa)
50
*
51
* Revision 1.6  2006/03/17 19:52:19  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.5  2006/03/14 19:34:18  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.4  2006/03/14 18:32:46  fjp
58
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
59
*
60
* Revision 1.3  2006/03/07 21:01:33  azabala
61
* *** empty log message ***
62
*
63
* Revision 1.2  2006/03/06 19:48:39  azabala
64
* *** empty log message ***
65
*
66
* Revision 1.1  2006/02/17 16:04:28  azabala
67
* *** empty log message ***
68
*
69
*
70
*/
71
package com.iver.gvsig.geoprocessing.impl;
72

    
73
import java.io.File;
74
import java.util.Map;
75

    
76
import org.cresques.cts.IProjection;
77

    
78
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
79
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver;
80
import com.iver.cit.gvsig.fmap.edition.EditionException;
81
import com.iver.cit.gvsig.fmap.edition.ISchemaManager;
82
import com.iver.cit.gvsig.fmap.edition.IWriter;
83
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter;
84
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
85
import com.iver.cit.gvsig.fmap.layers.ISpatialDB;
86
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
87
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
88
import com.iver.gvsig.geoprocessing.model.GeoprocessException;
89
import com.iver.gvsig.geoprocessing.model.IGeoprocess;
90
/**
91
 * Base class with all commong logic to geoprocesses
92
 * @author azabala
93
 *
94
 */
95
public abstract class AbstractGeoprocess implements IGeoprocess {
96
        /**
97
         * Writes result features in a persistent
98
         * data format.
99
         */
100
        protected IWriter writer;
101
        /**
102
         * Creates schema of result data format.
103
         */
104
        protected ISchemaManager schemaManager;
105
        /**
106
         * All geoprocesses at least work with one
107
         * vectorial layer
108
         */
109
        protected FLyrVect firstLayer;
110
                
111
        public abstract void setParameters(Map params) throws GeoprocessException;
112

    
113
        public abstract void checkPreconditions() throws GeoprocessException;
114

    
115
        public abstract void process() throws GeoprocessException;
116
        
117
        public  void cancel(){
118
                try {
119
                        schemaManager.drop();
120
                } catch (EditionException e) {
121
                        // TODO Auto-generated catch block
122
                        e.printStackTrace();
123
                }
124
        }
125
                
126
        /**
127
         * Creates a new Layer with:
128
         * a) the same projection than input layer.
129
         * b) an adapter created to work with writer's persistent store
130
         * 
131
         * @return FLyrVect with geoprocess result
132
         */
133
        public FLyrVect getResult() throws GeoprocessException {
134
                FLyrVect solution = null;
135
                String fileName = ((ShpWriter)writer).getShpPath();
136
                String layerName = null;
137
                int fileNameStart = fileName.lastIndexOf(File.separator) + 1;
138
                if(fileNameStart == -1)
139
                        fileNameStart = 0;
140
                layerName = fileName.substring(fileNameStart, fileName.length() -1);                
141
                
142
                File file = new File(fileName);
143
                IProjection proj = firstLayer.getProjection();
144
                try {
145
                        IndexedShpDriver driver = new IndexedShpDriver();
146
                        driver.open(file);
147
                        driver.initialize();
148
                        solution = (FLyrVect) LayerFactory.createLayer(layerName,
149
                                                                        driver,
150
                                                                        file,
151
                                                                        proj);
152
                        return solution; 
153
                } catch (Exception e) {
154
                        throw new GeoprocessException("Problemas al cargar la capa resultado");
155
                }         
156
        }
157

    
158
        public void setResultLayerProperties(IWriter writer,
159
                        ISchemaManager schemaManager) {
160
                this.writer = writer;
161
                this.schemaManager = schemaManager;
162
        }
163
        
164
        public abstract ILayerDefinition createLayerDefinition();
165
        
166
}
167