Statistics
| Revision:

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

History | View | Annotate | Download (4 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 4419 2006-03-14 19:35:13Z azabala $
47
* $Log$
48
* Revision 1.5  2006-03-14 19:34:18  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.4  2006/03/14 18:32:46  fjp
52
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
53
*
54
* Revision 1.3  2006/03/07 21:01:33  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.2  2006/03/06 19:48:39  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.1  2006/02/17 16:04:28  azabala
61
* *** empty log message ***
62
*
63
*
64
*/
65
package com.iver.gvsig.geoprocessing.impl;
66

    
67
import java.io.File;
68
import java.util.Map;
69

    
70
import org.cresques.cts.IProjection;
71

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

    
105
        public abstract void checkPreconditions() throws GeoprocessException;
106

    
107
        public abstract void process() throws GeoprocessException;
108
        
109
        public abstract void cancel();
110
                
111
        /**
112
         * Creates a new Layer with:
113
         * a) the same projection than input layer.
114
         * b) an adapter created to work with writer's persistent store
115
         * 
116
         * @return FLyrVect with geoprocess result
117
         */
118
        public FLyrVect getResult() throws GeoprocessException {
119
                FLyrVect solution = null;
120
                String fileName = ((ShpWriter)writer).getShpPath();
121
                File file = new File(fileName);
122
                IProjection proj = firstLayer.getProjection();
123
                try {
124
                        IndexedShpDriver driver = new IndexedShpDriver();
125
                        driver.open(file);
126
                        driver.initialize();
127
                        solution = (FLyrVect) LayerFactory.createLayer(fileName,
128
                                                                        driver,
129
                                                                        file,
130
                                                                        proj);
131
                        return solution; 
132
                } catch (Exception e) {
133
                        throw new GeoprocessException("Problemas al cargar la capa resultado");
134
                }         
135
        }
136

    
137
        public void setResultLayerProperties(IWriter writer,
138
                        ISchemaManager schemaManager) {
139
                this.writer = writer;
140
                this.schemaManager = schemaManager;
141
        }
142
        
143
        public abstract ILayerDefinition createLayerDefinition();
144
}
145