svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / RasterFileAdapter.java @ 10926
History | View | Annotate | Download (5.2 KB)
1 | 567 | luisw | /*
|
---|---|---|---|
2 | * Created on 20-dic-2004
|
||
3 | */
|
||
4 | 1100 | fjp | /* 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 | 567 | luisw | 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 | 10627 | caballero | import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
51 | 2850 | nacho | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
52 | import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
||
53 | 567 | luisw | |
54 | 2850 | nacho | |
55 | 567 | luisw | /**
|
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 | 1034 | vcaballero | |
64 | 567 | luisw | //private FileWriterDriver writeDriver;
|
65 | |||
66 | /**
|
||
67 | * Crea un nuevo VectorialFileAdapter.
|
||
68 | *
|
||
69 | 1034 | vcaballero | * @param file Fichero.
|
70 | 567 | luisw | */
|
71 | public RasterFileAdapter(File file) { |
||
72 | this.file = file;
|
||
73 | } |
||
74 | 1034 | vcaballero | |
75 | 567 | luisw | /**
|
76 | 1034 | vcaballero | * Devuelve el Driver Raster.
|
77 | 567 | luisw | *
|
78 | 1034 | vcaballero | * @return RasterDriver.
|
79 | 567 | luisw | */
|
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 | 10627 | caballero | * @throws LoadLayerException TODO
|
89 | 567 | luisw | */
|
90 | 10627 | caballero | public void start() throws LoadLayerException { |
91 | 567 | luisw | try {
|
92 | getFileDriver().open(file); |
||
93 | |||
94 | if (!driverInitialized) {
|
||
95 | getFileDriver().initialize(); |
||
96 | driverInitialized = true;
|
||
97 | } |
||
98 | } catch (IOException e) { |
||
99 | 10627 | caballero | throw new LoadLayerException(file.getName(),e); |
100 | 567 | luisw | } |
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 | 4376 | nacho | driverInitialized = false;
|
112 | 567 | luisw | getFileDriver().close(); |
113 | } catch (IOException e) { |
||
114 | throw new DriverIOException(e); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | 1034 | vcaballero | /**
|
119 | * Devuelve el n?mero de bandas de raster.
|
||
120 | *
|
||
121 | * @return N?mero de bandas.
|
||
122 | */
|
||
123 | 567 | luisw | public int getNumBands() { |
124 | return getFileDriver().getNumBands();
|
||
125 | } |
||
126 | |||
127 | 1034 | vcaballero | /**
|
128 | * Devuelve la extensi?n total de la capa.
|
||
129 | *
|
||
130 | * @return Extensi?n total.
|
||
131 | */
|
||
132 | 567 | luisw | 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 | 1034 | vcaballero | /**
|
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 | 567 | luisw | public Object getData(int x, int y, int band) { |
154 | return getFileDriver().getData(x, y, band);
|
||
155 | } |
||
156 | |||
157 | 1034 | vcaballero | /**
|
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 | 567 | luisw | public int getDataAsInt(int x, int y, int band) { |
168 | return getFileDriver().getDataAsInt(x, y, band);
|
||
169 | } |
||
170 | |||
171 | 1034 | vcaballero | /**
|
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 | 567 | luisw | public byte getDataAsByte(int x, int y, int band) { |
182 | return getFileDriver().getDataAsByte(x, y, band);
|
||
183 | } |
||
184 | |||
185 | 1034 | vcaballero | /**
|
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 | 567 | luisw | public float getDataAsFloat(int x, int y, int band) { |
196 | return getFileDriver().getDataAsFloat(x, y, band);
|
||
197 | } |
||
198 | |||
199 | 1034 | vcaballero | /**
|
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 | 567 | luisw | public double getDataAsDouble(int x, int y, int band) { |
210 | return getFileDriver().getDataAsDouble(x, y, band);
|
||
211 | } |
||
212 | 1034 | vcaballero | |
213 | 567 | luisw | /**
|
214 | 1034 | vcaballero | * Devuelve el fichero.
|
215 | 567 | luisw | *
|
216 | 1034 | vcaballero | * @return Fichero.
|
217 | 567 | luisw | */
|
218 | public File getFile() { |
||
219 | return file;
|
||
220 | } |
||
221 | 10627 | caballero | |
222 | 567 | luisw | } |