gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.io / org.gvsig.raster.io.base / src / main / java / org / gvsig / fmap / dal / coverage / dataset / io / GdalDriver.java @ 162
History | View | Annotate | Download (22.6 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.fmap.dal.coverage.dataset.io; |
23 |
|
24 |
import java.awt.geom.AffineTransform; |
25 |
import java.awt.geom.Point2D; |
26 |
import java.awt.geom.Rectangle2D; |
27 |
import java.io.BufferedReader; |
28 |
import java.io.File; |
29 |
import java.io.FileNotFoundException; |
30 |
import java.io.FileReader; |
31 |
import java.io.IOException; |
32 |
|
33 |
import org.gvsig.fmap.dal.DALFileLocator; |
34 |
import org.gvsig.fmap.dal.DALLocator; |
35 |
import org.gvsig.fmap.dal.DataStore; |
36 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
37 |
import org.gvsig.fmap.dal.coverage.dataset.io.param.GdalStoreParameters; |
38 |
import org.gvsig.fmap.dal.coverage.dataset.io.server.GdalFilesystemServerProvider; |
39 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
40 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
41 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
42 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
43 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
44 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
45 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
46 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
47 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
48 |
import org.gvsig.fmap.dal.raster.impl.DefaultCoverageStore; |
49 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
50 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
51 |
import org.gvsig.metadata.MetadataLocator; |
52 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
53 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
54 |
import org.gvsig.raster.impl.provider.RasterProvider; |
55 |
import org.gvsig.raster.impl.store.AbstractRasterStoreParameters; |
56 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
57 |
import org.gvsig.raster.impl.store.properties.DataStoreMetadata; |
58 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
59 |
import org.gvsig.tools.ToolsLocator; |
60 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
61 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
62 |
|
63 |
import es.gva.cit.jgdal.GdalException; |
64 |
/**
|
65 |
* Clase que representa al driver de acceso a datos de gdal.
|
66 |
*
|
67 |
* @author Luis W. Sevilla
|
68 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
69 |
*/
|
70 |
public class GdalDriver extends DefaultRasterProvider { |
71 |
public static String NAME = "Gdal Store"; |
72 |
public static String DESCRIPTION = "Gdal Raster file"; |
73 |
public static final String METADATA_DEFINITION_NAME = "GdalStore"; |
74 |
|
75 |
public static final String FORMAT_GTiff = "GTiff"; |
76 |
public static final String FORMAT_VRT = "VRT"; |
77 |
public static final String FORMAT_NITF = "NITF"; |
78 |
public static final String FORMAT_HFA = "HFA"; |
79 |
public static final String FORMAT_ELAS = "ELAS"; |
80 |
public static final String FORMAT_MEM = "MEM"; |
81 |
public static final String FORMAT_BMP = "BMP"; |
82 |
public static final String FORMAT_PCIDSK = "PCIDSK"; |
83 |
public static final String FORMAT_ILWIS = "ILWIS"; |
84 |
public static final String FORMAT_HDF4 = "HDF4Image"; |
85 |
public static final String FORMAT_PNM = "PNM"; |
86 |
public static final String FORMAT_ENVI = "ENVI"; |
87 |
public static final String FORMAT_EHDR = "EHdr"; |
88 |
public static final String FORMAT_PAUX = "PAux"; |
89 |
public static final String FORMAT_MFF = "MFF"; |
90 |
public static final String FORMAT_MFF2 = "MFF2"; |
91 |
public static final String FORMAT_BT = "BT"; |
92 |
public static final String FORMAT_IDA = "IDA"; |
93 |
public static final String FORMAT_RMF = "RMF"; |
94 |
public static final String FORMAT_RST = "RST"; |
95 |
public static final String FORMAT_LEVELLER = "Leveller"; |
96 |
public static final String FORMAT_TERRAGEN = "Terragen"; |
97 |
public static final String FORMAT_ERS = "ERS"; |
98 |
public static final String FORMAT_INGR = "INGR"; |
99 |
public static final String FORMAT_GSAG = "GSAG"; |
100 |
public static final String FORMAT_GSBG = "GSBG"; |
101 |
public static final String FORMAT_ADRG = "ADRG"; |
102 |
public static final int BAND_HEIGHT = 64; |
103 |
protected GdalNative file = null; |
104 |
|
105 |
private Extent viewRequest = null; |
106 |
|
107 |
public static void register() { |
108 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
109 |
ExtensionPoint point = extensionPoints.get("RasterReader");
|
110 |
|
111 |
point.append("bmp", "", GdalDriver.class); |
112 |
point.append("gif", "", GdalDriver.class); |
113 |
point.append("tif", "", GdalDriver.class); |
114 |
point.append("tiff", "", GdalDriver.class); |
115 |
point.append("jpg", "", GdalDriver.class); |
116 |
point.append("jpeg", "", GdalDriver.class); |
117 |
point.append("png", "", GdalDriver.class); |
118 |
point.append("vrt", "", GdalDriver.class); |
119 |
point.append("dat", "", GdalDriver.class); // Envi |
120 |
point.append("lan", "", GdalDriver.class); // Erdas |
121 |
point.append("gis", "", GdalDriver.class); // Erdas |
122 |
point.append("img", "", GdalDriver.class); // Erdas |
123 |
point.append("pix", "", GdalDriver.class); // PCI Geomatics |
124 |
point.append("aux", "", GdalDriver.class); // PCI Geomatics |
125 |
point.append("adf", "", GdalDriver.class); // ESRI Grids |
126 |
point.append("mpr", "", GdalDriver.class); // Ilwis |
127 |
point.append("mpl", "", GdalDriver.class); // Ilwis |
128 |
point.append("map", "", GdalDriver.class); // PC Raster |
129 |
point.append("asc", "", GdalDriver.class); |
130 |
point.append("pgm", "", GdalDriver.class); //Ficheros PNM en escala de grises |
131 |
point.append("ppm", "", GdalDriver.class); //Ficheros PNM en RGB |
132 |
point.append("rst", "", GdalDriver.class); //IDRISIS |
133 |
point.append("rmf", "", GdalDriver.class); //Raster Matrix Format |
134 |
point.append("nos", "", GdalDriver.class); |
135 |
point.append("kap", "", GdalDriver.class); |
136 |
point.append("hdr", "", GdalDriver.class); |
137 |
point.append("raw", "", GdalDriver.class); |
138 |
point.append("ers", "", GdalDriver.class); |
139 |
|
140 |
point = extensionPoints.get("DefaultDriver");
|
141 |
point.append("reader", "", GdalDriver.class); |
142 |
|
143 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
144 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
145 |
dataman.registerStoreProvider(NAME, |
146 |
GdalDriver.class, GdalStoreParameters.class); |
147 |
} |
148 |
|
149 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
150 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
151 |
NAME, DESCRIPTION, |
152 |
GdalFilesystemServerProvider.class); |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Constructor. Abre el dataset.
|
157 |
* @param proj Proyecci?n
|
158 |
* @param fName Nombre del fichero
|
159 |
* @throws NotSupportedExtensionException
|
160 |
*/
|
161 |
public GdalDriver(String params) throws NotSupportedExtensionException { |
162 |
super(params);
|
163 |
if(params instanceof String) { |
164 |
GdalStoreParameters p = new GdalStoreParameters();
|
165 |
p.setFileName((String)params);
|
166 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
167 |
.createDynObject( |
168 |
MetadataLocator.getMetadataManager().getDefinition( |
169 |
DataStore.METADATA_DEFINITION_NAME))); |
170 |
init(p, null);
|
171 |
} |
172 |
} |
173 |
|
174 |
public GdalDriver (GdalStoreParameters params,
|
175 |
DefaultCoverageStore storeServices) throws NotSupportedExtensionException {
|
176 |
super(params, storeServices, ToolsLocator.getDynObjectManager()
|
177 |
.createDynObject( |
178 |
MetadataLocator.getMetadataManager().getDefinition( |
179 |
DataStore.METADATA_DEFINITION_NAME))); |
180 |
init(params, storeServices); |
181 |
} |
182 |
|
183 |
/**
|
184 |
* Crea las referencias al fichero y carga
|
185 |
* las estructuras con la informaci?n y los metadatos.
|
186 |
* @param proj Proyecci?n
|
187 |
* @param param Parametros de carga
|
188 |
* @throws NotSupportedExtensionException
|
189 |
*/
|
190 |
public void init (AbstractRasterStoreParameters params, |
191 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
|
192 |
try {
|
193 |
if(params.getFile().exists()) {
|
194 |
setParam(params); |
195 |
validRmf(params.getFileName()); |
196 |
file = new GdalNative(translateFileName(params.getFileName()));
|
197 |
setColorTable(file.palette); |
198 |
noData = file.getNoDataValue(); |
199 |
wktProjection = file.getProjectionRef(); |
200 |
noDataEnabled = file.existsNoDataValue(); |
201 |
ownTransformation = file.getOwnTransformation(); |
202 |
externalTransformation = (AffineTransform)ownTransformation.clone();
|
203 |
load(); |
204 |
} else
|
205 |
setParam(params); |
206 |
//TODO: FUNCIONALIDAD: Formatos gestionados por gdal que no tienen extensi?n. Estos tendr?n un objeto IRegistrableRasterFormat Por ej: Grass
|
207 |
bandCount = file.getRasterCount(); |
208 |
} catch (GdalException e) {
|
209 |
e.printStackTrace(); |
210 |
throw new NotSupportedExtensionException("Extension not supported"); |
211 |
} catch(Exception e) { |
212 |
System.out.println("Error en GdalOpen"); |
213 |
e.printStackTrace(); |
214 |
file = null;
|
215 |
} |
216 |
|
217 |
//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
|
218 |
int[] dt = new int[file.getDataType().length]; |
219 |
for (int i = 0; i < dt.length; i++) |
220 |
dt[i] = rasterUtil.getRasterBufTypeFromGdalType(file.getDataType()[i]); |
221 |
setDataType(dt); |
222 |
|
223 |
super.init();
|
224 |
|
225 |
try {
|
226 |
loadFromRmf(getRmfBlocksManager()); |
227 |
} catch (ParsingException e) {
|
228 |
//No lee desde rmf
|
229 |
} |
230 |
} |
231 |
|
232 |
/**
|
233 |
* Comprueba si el fichero abierto es un RasterMetaFile o una imagen
|
234 |
* raster.
|
235 |
* @throws GdalException
|
236 |
*/
|
237 |
private void validRmf(String file) throws GdalException { |
238 |
if(file.endsWith(".rmf")) { |
239 |
File f = new File(file); |
240 |
FileReader fr;
|
241 |
try {
|
242 |
fr = new FileReader(f); |
243 |
BufferedReader br = new BufferedReader(fr); |
244 |
char[] buffer = new char[5]; |
245 |
br.read(buffer); |
246 |
StringBuffer st = new StringBuffer(new String(buffer)); |
247 |
if(st.toString().equals("<?xml")) |
248 |
throw new GdalException("RasterMetaFile"); |
249 |
} catch (FileNotFoundException e) { |
250 |
throw new GdalException("File Not Found"); |
251 |
} catch (IOException e) { |
252 |
throw new GdalException(""); |
253 |
} |
254 |
} |
255 |
} |
256 |
/**
|
257 |
* Obtenemos o calculamos el extent de la imagen.
|
258 |
*/
|
259 |
public RasterProvider load() {
|
260 |
return this; |
261 |
} |
262 |
|
263 |
/*
|
264 |
* (non-Javadoc)
|
265 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isOpen()
|
266 |
*/
|
267 |
public boolean isOpen() { |
268 |
if(file != null && file.isOpen()) |
269 |
return true; |
270 |
return false; |
271 |
} |
272 |
|
273 |
/**
|
274 |
* Cierra el fichero de imagen
|
275 |
*/
|
276 |
public void close() { |
277 |
try {
|
278 |
if(file != null){ |
279 |
file.close(); |
280 |
file = null;
|
281 |
} |
282 |
viewRequest = null;
|
283 |
} catch (GdalException e) {
|
284 |
e.printStackTrace(); |
285 |
} |
286 |
} |
287 |
|
288 |
/*
|
289 |
* (non-Javadoc)
|
290 |
* @see org.gvsig.raster.dataset.RasterDataset#translateFileName(java.lang.String)
|
291 |
*/
|
292 |
public String translateFileName(String fileName) { |
293 |
if(fileName.endsWith("hdr")) |
294 |
return fileName.substring(0, fileName.lastIndexOf(".")); |
295 |
return fileName;
|
296 |
} |
297 |
|
298 |
/**
|
299 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n
|
300 |
* de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v)
|
301 |
* ha de estar en coordenadas del fichero.
|
302 |
*/
|
303 |
public void setView(Extent e) { |
304 |
viewRequest = e; |
305 |
} |
306 |
|
307 |
/**
|
308 |
* Obtiene extent de la vista actual
|
309 |
*/
|
310 |
public Extent getView() {
|
311 |
return viewRequest;
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* Obtiene la anchura del fichero
|
316 |
*/
|
317 |
public double getWidth() { |
318 |
return file.width;
|
319 |
} |
320 |
|
321 |
/**
|
322 |
* Obtiene la altura del fichero
|
323 |
*/
|
324 |
public double getHeight() { |
325 |
return file.height;
|
326 |
} |
327 |
|
328 |
/*
|
329 |
* (non-Javadoc)
|
330 |
* @see org.gvsig.fmap.driver.GeoRasterFile#readCompletetLine(int, int)
|
331 |
*/
|
332 |
public Object readCompleteLine(int line, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
333 |
if(line > this.getHeight() || band > this.getBandCount()) |
334 |
throw new InvalidSetViewException("Request out of grid"); |
335 |
|
336 |
try{
|
337 |
return file.readCompleteLine(line, band);
|
338 |
}catch(GdalException e){
|
339 |
throw new RasterDriverException("Error reading data from Gdal library"); |
340 |
} |
341 |
} |
342 |
|
343 |
/*
|
344 |
* (non-Javadoc)
|
345 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int)
|
346 |
*/
|
347 |
public Object readBlock(int pos, int blockHeight) |
348 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
|
349 |
if(pos < 0) |
350 |
throw new InvalidSetViewException("Request out of grid"); |
351 |
|
352 |
if((pos + blockHeight) > getHeight())
|
353 |
blockHeight = Math.abs(((int)getHeight()) - pos); |
354 |
try{
|
355 |
return file.readBlock(pos, blockHeight);
|
356 |
}catch(GdalException e){
|
357 |
throw new RasterDriverException("Error reading data from Gdal library"); |
358 |
} |
359 |
} |
360 |
|
361 |
/* (non-Javadoc)
|
362 |
* @see org.cresques.io.GeoRasterFile#getData(int, int, int)
|
363 |
*/
|
364 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
365 |
if(file != null){ |
366 |
if(x < 0 || y < 0 || x >= file.width || y >= file.height) |
367 |
throw new InvalidSetViewException("Request out of grid"); |
368 |
Object[] data = file.getData(x, y); |
369 |
return data[band];
|
370 |
} |
371 |
throw new FileNotOpenException("GdalNative not exist"); |
372 |
} |
373 |
|
374 |
/*
|
375 |
* (non-Javadoc)
|
376 |
* @see org.gvsig.raster.dataset.RasterDataset#getWindowRaster(double, double, double, double, org.gvsig.raster.dataset.BandList, org.gvsig.raster.dataset.IBuffer)
|
377 |
*/
|
378 |
public Buffer getWindowRaster(double ulx, double uly, double lrx, double lry, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
379 |
Extent selectedExtent = new ExtentImpl(ulx, uly, lrx, lry);
|
380 |
setView(selectedExtent); |
381 |
|
382 |
try {
|
383 |
file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight(), true);
|
384 |
} catch (GdalException e) {
|
385 |
throw new RasterDriverException("Error reading data"); |
386 |
} |
387 |
|
388 |
return rasterBuf;
|
389 |
} |
390 |
|
391 |
/*
|
392 |
* (non-Javadoc)
|
393 |
* @see org.gvsig.fmap.driver.GeoRasterFile#getWindowRaster(double, double, double, double, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer)
|
394 |
*/
|
395 |
public Buffer getWindowRaster(double ulx, double uly, double w, double h, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException { |
396 |
//El incremento o decremento de las X e Y depende de los signos de rotaci?n y escala en la matriz de transformaci?n. Por esto
|
397 |
//tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o y - h
|
398 |
Extent ext = getExtent(); |
399 |
Point2D pInit = rasterToWorld(new Point2D.Double(0, 0)); |
400 |
Point2D pEnd = rasterToWorld(new Point2D.Double(getWidth(), getHeight())); |
401 |
double wRaster = Math.abs(pEnd.getX() - pInit.getX()); |
402 |
double hRaster = Math.abs(pEnd.getY() - pInit.getY()); |
403 |
double lrx = (((ext.getULX() - wRaster) > ext.maxX()) || ((ext.getULX() - wRaster) < ext.minX())) ? (ulx + w) : (ulx - w);
|
404 |
double lry = (((ext.getULY() - hRaster) > ext.maxY()) || ((ext.getULY() - hRaster) < ext.minY())) ? (uly + h) : (uly - h);
|
405 |
|
406 |
Extent selectedExtent = new ExtentImpl(ulx, uly, lrx, lry);
|
407 |
setView(selectedExtent); |
408 |
|
409 |
try {
|
410 |
file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight(), adjustToExtent); |
411 |
} catch (GdalException e) {
|
412 |
throw new RasterDriverException("Error reading data"); |
413 |
} |
414 |
|
415 |
return rasterBuf;
|
416 |
} |
417 |
|
418 |
/*
|
419 |
* (non-Javadoc)
|
420 |
* @see org.gvsig.fmap.driver.GeoRasterFile#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer)
|
421 |
*/
|
422 |
public Buffer getWindowRaster(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException { |
423 |
Extent selectedExtent = new ExtentImpl(minX, minY, maxX, maxY);
|
424 |
setView(selectedExtent); |
425 |
|
426 |
double width = 0; |
427 |
double height = 0; |
428 |
|
429 |
Point2D ul = new Point2D.Double(viewRequest.getULX(), viewRequest.getULY()); |
430 |
Point2D lr = new Point2D.Double(viewRequest.getLRX(), viewRequest.getLRY()); |
431 |
ul = worldToRaster(ul); |
432 |
lr = worldToRaster(lr); |
433 |
|
434 |
if(ul.getX() > lr.getX())
|
435 |
ul.setLocation(ul.getX() - 1, ul.getY());
|
436 |
else
|
437 |
lr.setLocation(lr.getX() - 1, lr.getY());
|
438 |
|
439 |
if(ul.getY() > lr.getY())
|
440 |
ul.setLocation(ul.getX(), ul.getY() - 1);
|
441 |
else
|
442 |
lr.setLocation(lr.getX(), lr.getY() - 1);
|
443 |
|
444 |
adjustPoints(ul, lr); |
445 |
|
446 |
width = Math.abs(((int)lr.getX()) - ((int)ul.getX())) + 1; |
447 |
height = Math.abs(((int)lr.getY()) - ((int)ul.getY())) + 1; |
448 |
|
449 |
try {
|
450 |
file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), width, height, bufWidth, bufHeight, adjustToExtent); |
451 |
} catch (GdalException e) {
|
452 |
throw new RasterDriverException("Error reading data"); |
453 |
} |
454 |
|
455 |
return rasterBuf;
|
456 |
} |
457 |
|
458 |
|
459 |
private void adjustPoints(Point2D ul, Point2D lr) { |
460 |
double a = (ul.getX() - (int)ul.getX()); |
461 |
double b = (ul.getY() - (int)ul.getY()); |
462 |
ul.setLocation( (a > 0.95 || a < 0.05) ? Math.round(ul.getX()) : ul.getX(), |
463 |
(b > 0.95 || b < 0.05) ? Math.round(ul.getY()) : ul.getY()); |
464 |
lr.setLocation( (a > 0.95 || a < 0.05) ? Math.round(lr.getX()) : lr.getX(), |
465 |
(b > 0.95 || b < 0.05) ? Math.round(lr.getY()) : lr.getY()); |
466 |
} |
467 |
|
468 |
/*
|
469 |
* (non-Javadoc)
|
470 |
* @see org.gvsig.fmap.driver.GeoRasterFile#getWindowRaster(int, int, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer)
|
471 |
*/
|
472 |
public Buffer getWindowRaster(int x, int y, int w, int h, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
473 |
try {
|
474 |
setView( |
475 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
|
476 |
getWidth(), |
477 |
getHeight(), |
478 |
new Rectangle2D.Double(x, y, w, h))) |
479 |
); |
480 |
file.readWindow(rasterBuf, bandList, x, y, w, h); |
481 |
} catch (GdalException e) {
|
482 |
throw new RasterDriverException("Error reading data"); |
483 |
} |
484 |
return rasterBuf;
|
485 |
} |
486 |
|
487 |
/*
|
488 |
* (non-Javadoc)
|
489 |
* @see org.gvsig.fmap.driver.GeoRasterFile#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer)
|
490 |
*/
|
491 |
public Buffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
492 |
try {
|
493 |
setView( |
494 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
|
495 |
getWidth(), |
496 |
getHeight(), |
497 |
new Rectangle2D.Double(x, y, w, h))) |
498 |
); |
499 |
file.readWindow(rasterBuf, bandList, x, y, w, h, bufWidth, bufHeight); |
500 |
} catch (GdalException e) {
|
501 |
throw new RasterDriverException("Error reading data"); |
502 |
} |
503 |
return rasterBuf;
|
504 |
} |
505 |
|
506 |
/**
|
507 |
* Devuelve el tama?o de bloque
|
508 |
* @return Tama?o de bloque
|
509 |
*/
|
510 |
public int getBlockSize(){ |
511 |
if(file != null) |
512 |
return file.getBlockSize();
|
513 |
else
|
514 |
return 0; |
515 |
} |
516 |
|
517 |
/**
|
518 |
* Obtiene el objeto que contiene los metadatos
|
519 |
*/
|
520 |
public DataStoreMetadata getMetadata() {
|
521 |
if(file != null) |
522 |
return file.metadata;
|
523 |
else
|
524 |
return null; |
525 |
} |
526 |
|
527 |
/**
|
528 |
* Obtiene el objeto que contiene que contiene la interpretaci?n de
|
529 |
* color por banda
|
530 |
* @return
|
531 |
*/
|
532 |
public DataStoreColorInterpretation getColorInterpretation(){
|
533 |
if(file != null) |
534 |
return file.colorInterpr;
|
535 |
return null; |
536 |
} |
537 |
|
538 |
/**
|
539 |
* Asigna el objeto que contiene que contiene la interpretaci?n de
|
540 |
* color por banda
|
541 |
* @param DataStoreColorInterpretation
|
542 |
*/
|
543 |
public void setColorInterpretation(DataStoreColorInterpretation colorInterpretation){ |
544 |
if(file != null) |
545 |
file.colorInterpr = colorInterpretation; |
546 |
} |
547 |
|
548 |
/**
|
549 |
* Obtiene el objeto que contiene el estado de la transparencia
|
550 |
*/
|
551 |
public DataStoreTransparency getTransparency() {
|
552 |
return file.fileTransparency;
|
553 |
} |
554 |
|
555 |
/**
|
556 |
* Obtiene el flag que dice si la imagen est? o no georreferenciada
|
557 |
* @return true si est? georreferenciada y false si no lo est?.
|
558 |
*/
|
559 |
public boolean isGeoreferenced() { |
560 |
if(file != null) |
561 |
return file.georeferenced;
|
562 |
else
|
563 |
return false; |
564 |
} |
565 |
|
566 |
/**
|
567 |
* Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
|
568 |
* el valor de esta variable cada vez que dibuja.
|
569 |
* @return true si se ha supersampleado y false si no se ha hecho.
|
570 |
*/
|
571 |
public boolean isSupersampling() { |
572 |
if(file != null) |
573 |
return file.isSupersampling;
|
574 |
else
|
575 |
return false; |
576 |
} |
577 |
|
578 |
public GdalNative getNative(){
|
579 |
return file;
|
580 |
} |
581 |
|
582 |
/*
|
583 |
* (non-Javadoc)
|
584 |
* @see org.gvsig.raster.dataset.RasterDataset#setAffineTransform(java.awt.geom.AffineTransform)
|
585 |
*/
|
586 |
public void setAffineTransform(AffineTransform t){ |
587 |
super.setAffineTransform(t);
|
588 |
file.setExternalTransform(t); |
589 |
} |
590 |
|
591 |
/*
|
592 |
* (non-Javadoc)
|
593 |
* @see org.gvsig.raster.dataset.RasterDataset#getOverviewCount(int)
|
594 |
*/
|
595 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
596 |
if(band >= getBandCount())
|
597 |
throw new BandAccessException("Wrong band"); |
598 |
try {
|
599 |
return file.getRasterBand(band + 1).getOverviewCount(); |
600 |
} catch (GdalException e) {
|
601 |
throw new RasterDriverException(""); |
602 |
} |
603 |
} |
604 |
|
605 |
/*
|
606 |
* (non-Javadoc)
|
607 |
* @see org.gvsig.raster.dataset.RasterDataset#getOverviewWidth(int, int)
|
608 |
*/
|
609 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
610 |
if (band >= getBandCount())
|
611 |
throw new BandAccessException("Wrong band"); |
612 |
try {
|
613 |
if (overview >= file.getRasterBand(band + 1).getOverviewCount()) |
614 |
throw new BandAccessException("Wrong overview count"); |
615 |
return file.getRasterBand(band + 1).getOverview(overview).getRasterBandXSize(); |
616 |
} catch (GdalException e) {
|
617 |
throw new RasterDriverException(""); |
618 |
} |
619 |
} |
620 |
|
621 |
/*
|
622 |
* (non-Javadoc)
|
623 |
* @see org.gvsig.raster.dataset.RasterDataset#getOverviewWidth(int, int)
|
624 |
*/
|
625 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
626 |
if (band >= getBandCount())
|
627 |
throw new BandAccessException("Wrong band"); |
628 |
try {
|
629 |
if (overview >= file.getRasterBand(band + 1).getOverviewCount()) |
630 |
throw new BandAccessException("Wrong overview count"); |
631 |
return file.getRasterBand(band + 1).getOverview(overview).getRasterBandYSize(); |
632 |
} catch (GdalException e) {
|
633 |
throw new RasterDriverException(""); |
634 |
} |
635 |
} |
636 |
|
637 |
/*
|
638 |
* (non-Javadoc)
|
639 |
* @see org.gvsig.raster.dataset.RasterDataset#overviewsSupport()
|
640 |
*/
|
641 |
public boolean overviewsSupport() { |
642 |
return true; |
643 |
} |
644 |
|
645 |
/*
|
646 |
* (non-Javadoc)
|
647 |
* @see org.gvsig.raster.dataset.RasterDataset#isReproyectable()
|
648 |
*/
|
649 |
public boolean isReproyectable() { |
650 |
return true; |
651 |
} |
652 |
|
653 |
/*
|
654 |
* (non-Javadoc)
|
655 |
* @see org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider#getName()
|
656 |
*/
|
657 |
public String getName() { |
658 |
return NAME;
|
659 |
} |
660 |
} |