Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / RasterFileAdapter.java @ 10627

History | View | Annotate | Download (5.2 KB)

1
/*
2
 * Created on 20-dic-2004
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
package com.iver.cit.gvsig.fmap.layers;
45

    
46
import java.awt.geom.Rectangle2D;
47
import java.io.File;
48
import java.io.IOException;
49

    
50
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
51
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
52
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
53

    
54

    
55
/**
56
 * Adapta un driver de fichero vectorial a la interfaz vectorial, manteniendo
57
 * adem?s el estado necesario por una capa vectorial de fichero (el nombre del
58
 * fichero)
59
 */
60
public class RasterFileAdapter extends RasterAdapter {
61
        private boolean driverInitialized = false;
62
        private File file;
63

    
64
        //private FileWriterDriver writeDriver;
65

    
66
        /**
67
         * Crea un nuevo VectorialFileAdapter.
68
         *
69
         * @param file Fichero.
70
         */
71
        public RasterFileAdapter(File file) {
72
                this.file = file;
73
        }
74

    
75
        /**
76
         * Devuelve el Driver Raster.
77
         *
78
         * @return RasterDriver.
79
         */
80
        private RasterDriver getFileDriver() {
81
                return (RasterDriver) getDriver();
82
        }
83

    
84
        /**
85
         * incrementa el contador de las veces que se ha abierto el fichero.
86
         * Solamente cuando el contador est? a cero pide al driver que abra el
87
         * fichero
88
         * @throws LoadLayerException TODO
89
         */
90
        public void start() throws LoadLayerException {
91
                try {
92
                        getFileDriver().open(file);
93

    
94
                        if (!driverInitialized) {
95
                                getFileDriver().initialize();
96
                                driverInitialized = true;
97
                        }
98
                } catch (IOException e) {
99
                        throw new LoadLayerException(file.getName(),e);
100
                }
101
        }
102

    
103
        /**
104
         * decrementa el contador de n?mero de aperturas y cuando llega a cero pide
105
         * al driver que cierre el fichero
106
         *
107
         * @throws DriverIOException
108
         */
109
        public void stop() throws DriverIOException {
110
                try {
111
                        driverInitialized = false;
112
                        getFileDriver().close();
113
                } catch (IOException e) {
114
                        throw new DriverIOException(e);
115
                }
116
        }
117

    
118
        /**
119
         * Devuelve el n?mero de bandas de raster.
120
         *
121
         * @return N?mero de bandas.
122
         */
123
        public int getNumBands() {
124
                return getFileDriver().getNumBands();
125
        }
126

    
127
        /**
128
         * Devuelve la extensi?n total de la capa.
129
         *
130
         * @return Extensi?n total.
131
         */
132
        public Rectangle2D getFullExtent() {
133
                return getFileDriver().getFullExtent();
134
        }
135

    
136
        /**
137
         * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
138
         */
139
        public int getRasterDataType() {
140
                return getFileDriver().getRasterDataType();
141
        }
142

    
143
        /**
144
         * Obtiene una muestra del pixel que se pasa como par?metro en la banda que
145
         * se pasa como par?metro
146
         *
147
         * @param x Coordenada X
148
         * @param y Coordenada Y
149
         * @param band N?mero de banda.
150
         *
151
         * @return Objeto.
152
         */
153
        public Object getData(int x, int y, int band) {
154
                return getFileDriver().getData(x, y, band);
155
        }
156

    
157
        /**
158
         * Obtiene una muestra del pixel que se pasa como par?metro en la banda que
159
         * se pasa como par?metro
160
         *
161
         * @param x Coordenada X.
162
         * @param y Coordenada Y.
163
         * @param band N?mero de banda.
164
         *
165
         * @return Entero que representa el valor seleccionado.
166
         */
167
        public int getDataAsInt(int x, int y, int band) {
168
                return getFileDriver().getDataAsInt(x, y, band);
169
        }
170

    
171
        /**
172
         * Obtiene una muestra del pixel que se pasa como par?metro en la banda que
173
         * se pasa como par?metro
174
         *
175
         * @param x Coordenada X.
176
         * @param y Coordenada Y.
177
         * @param band N?mero de banda.
178
         *
179
         * @return byte.
180
         */
181
        public byte getDataAsByte(int x, int y, int band) {
182
                return getFileDriver().getDataAsByte(x, y, band);
183
        }
184

    
185
        /**
186
         * Obtiene una muestra del pixel que se pasa como par?metro en la banda que
187
         * se pasa como par?metro
188
         *
189
         * @param x Coordenada X.
190
         * @param y Coordenada Y.
191
         * @param band N?mero de banda.
192
         *
193
         * @return float.
194
         */
195
        public float getDataAsFloat(int x, int y, int band) {
196
                return getFileDriver().getDataAsFloat(x, y, band);
197
        }
198

    
199
        /**
200
         * Obtiene una muestra el pixel que se pasa como par?metro en la banda que
201
         * se pasa como par?metro
202
         *
203
         * @param x Coordenada X.
204
         * @param y Coordenada Y.
205
         * @param band N?mero de banda.
206
         *
207
         * @return double.
208
         */
209
        public double getDataAsDouble(int x, int y, int band) {
210
                return getFileDriver().getDataAsDouble(x, y, band);
211
        }
212

    
213
        /**
214
         * Devuelve el fichero.
215
         *
216
         * @return Fichero.
217
         */
218
        public File getFile() {
219
                return file;
220
        }
221

    
222
}