root / trunk / extensions / extRasterTools-SE / src / org / gvsig / fmap / layers / RasterSEFileAdapter.java @ 10940
History | View | Annotate | Download (5.12 KB)
1 | 10740 | nacho | /*
|
---|---|---|---|
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 org.gvsig.fmap.layers; |
||
45 | |||
46 | import java.awt.geom.Rectangle2D; |
||
47 | import java.io.File; |
||
48 | import java.io.IOException; |
||
49 | |||
50 | import org.gvsig.fmap.drivers.raster.RasterSEDriver; |
||
51 | |||
52 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
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 RasterSEFileAdapter extends RasterSEAdapter { |
||
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 RasterSEFileAdapter(File file) { |
||
72 | this.file = file;
|
||
73 | } |
||
74 | |||
75 | /**
|
||
76 | * Devuelve el Driver Raster.
|
||
77 | *
|
||
78 | * @return RasterDriver.
|
||
79 | */
|
||
80 | private RasterSEDriver getFileDriver() {
|
||
81 | return (RasterSEDriver) 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 | *
|
||
89 | * @throws DriverIOException
|
||
90 | */
|
||
91 | public void start() throws DriverIOException { |
||
92 | try {
|
||
93 | getFileDriver().open(file); |
||
94 | |||
95 | if (!driverInitialized) {
|
||
96 | getFileDriver().initialize(); |
||
97 | driverInitialized = true;
|
||
98 | } |
||
99 | } catch (IOException e) { |
||
100 | throw new DriverIOException(e); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | /**
|
||
105 | * decrementa el contador de n?mero de aperturas y cuando llega a cero pide
|
||
106 | * al driver que cierre el fichero
|
||
107 | *
|
||
108 | * @throws DriverIOException
|
||
109 | */
|
||
110 | public void stop() throws DriverIOException { |
||
111 | try {
|
||
112 | driverInitialized = false;
|
||
113 | getFileDriver().close(); |
||
114 | } catch (IOException e) { |
||
115 | throw new DriverIOException(e); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | /**
|
||
120 | * Devuelve el n?mero de bandas de raster.
|
||
121 | *
|
||
122 | * @return N?mero de bandas.
|
||
123 | */
|
||
124 | public int getNumBands() { |
||
125 | return getFileDriver().getNumBands();
|
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | * Devuelve la extensi?n total de la capa.
|
||
130 | *
|
||
131 | * @return Extensi?n total.
|
||
132 | */
|
||
133 | public Rectangle2D getFullExtent() { |
||
134 | return getFileDriver().getFullExtent();
|
||
135 | } |
||
136 | |||
137 | /**
|
||
138 | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
|
||
139 | */
|
||
140 | public int getRasterDataType() { |
||
141 | return getFileDriver().getRasterDataType();
|
||
142 | } |
||
143 | |||
144 | /**
|
||
145 | * Obtiene una muestra del pixel que se pasa como par?metro en la banda que
|
||
146 | * se pasa como par?metro
|
||
147 | *
|
||
148 | * @param x Coordenada X
|
||
149 | * @param y Coordenada Y
|
||
150 | * @param band N?mero de banda.
|
||
151 | *
|
||
152 | * @return Objeto.
|
||
153 | */
|
||
154 | public Object getData(int x, int y, int band) { |
||
155 | return getFileDriver().getData(x, y, band);
|
||
156 | } |
||
157 | |||
158 | /**
|
||
159 | * Obtiene una muestra del pixel que se pasa como par?metro en la banda que
|
||
160 | * se pasa como par?metro
|
||
161 | *
|
||
162 | * @param x Coordenada X.
|
||
163 | * @param y Coordenada Y.
|
||
164 | * @param band N?mero de banda.
|
||
165 | *
|
||
166 | * @return Entero que representa el valor seleccionado.
|
||
167 | */
|
||
168 | public int getDataAsInt(int x, int y, int band) { |
||
169 | return getFileDriver().getDataAsInt(x, y, band);
|
||
170 | } |
||
171 | |||
172 | /**
|
||
173 | * Obtiene una muestra del pixel que se pasa como par?metro en la banda que
|
||
174 | * se pasa como par?metro
|
||
175 | *
|
||
176 | * @param x Coordenada X.
|
||
177 | * @param y Coordenada Y.
|
||
178 | * @param band N?mero de banda.
|
||
179 | *
|
||
180 | * @return byte.
|
||
181 | */
|
||
182 | public byte getDataAsByte(int x, int y, int band) { |
||
183 | return getFileDriver().getDataAsByte(x, y, band);
|
||
184 | } |
||
185 | |||
186 | /**
|
||
187 | * Obtiene una muestra del pixel que se pasa como par?metro en la banda que
|
||
188 | * se pasa como par?metro
|
||
189 | *
|
||
190 | * @param x Coordenada X.
|
||
191 | * @param y Coordenada Y.
|
||
192 | * @param band N?mero de banda.
|
||
193 | *
|
||
194 | * @return float.
|
||
195 | */
|
||
196 | public float getDataAsFloat(int x, int y, int band) { |
||
197 | return getFileDriver().getDataAsFloat(x, y, band);
|
||
198 | } |
||
199 | |||
200 | /**
|
||
201 | * Obtiene una muestra el pixel que se pasa como par?metro en la banda que
|
||
202 | * se pasa como par?metro
|
||
203 | *
|
||
204 | * @param x Coordenada X.
|
||
205 | * @param y Coordenada Y.
|
||
206 | * @param band N?mero de banda.
|
||
207 | *
|
||
208 | * @return double.
|
||
209 | */
|
||
210 | public double getDataAsDouble(int x, int y, int band) { |
||
211 | return getFileDriver().getDataAsDouble(x, y, band);
|
||
212 | } |
||
213 | |||
214 | /**
|
||
215 | * Devuelve el fichero.
|
||
216 | *
|
||
217 | * @return Fichero.
|
||
218 | */
|
||
219 | public File getFile() { |
||
220 | return file;
|
||
221 | } |
||
222 | |||
223 | } |