gvsig-raster / org.gvsig.raster.gdal / trunk / org.gvsig.raster.gdal / org.gvsig.raster.gdal.io / src / main / java / org / gvsig / raster / gdal / io / GdalProvider.java @ 4346
History | View | Annotate | Download (20.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.raster.gdal.io; |
23 |
|
24 |
import java.awt.geom.AffineTransform; |
25 |
import java.io.BufferedReader; |
26 |
import java.io.File; |
27 |
import java.io.FileNotFoundException; |
28 |
import java.io.FileReader; |
29 |
import java.io.IOException; |
30 |
import java.net.URI; |
31 |
import java.net.URISyntaxException; |
32 |
|
33 |
import org.apache.commons.io.FilenameUtils; |
34 |
import org.slf4j.Logger; |
35 |
import org.slf4j.LoggerFactory; |
36 |
|
37 |
import org.gvsig.fmap.dal.DALFileLocator; |
38 |
import org.gvsig.fmap.dal.DALLocator; |
39 |
import org.gvsig.fmap.dal.DataStore; |
40 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
41 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
42 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
43 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
44 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
45 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
46 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
47 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
48 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
49 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
50 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
51 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
52 |
import org.gvsig.fmap.dal.exception.OpenException; |
53 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
54 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
55 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
56 |
import org.gvsig.jgdal.GdalException; |
57 |
import org.gvsig.metadata.MetadataLocator; |
58 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
59 |
import org.gvsig.raster.impl.buffer.SpiRasterQuery; |
60 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
61 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider; |
62 |
import org.gvsig.raster.impl.provider.RasterProvider; |
63 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
64 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
65 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
66 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
67 |
import org.gvsig.raster.impl.store.properties.DataStoreMetadata; |
68 |
import org.gvsig.tools.ToolsLocator; |
69 |
import org.gvsig.tools.dynobject.DynObject; |
70 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
71 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
72 |
/**
|
73 |
* This class represents the data access for gdal formats.
|
74 |
*
|
75 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
76 |
*/
|
77 |
public class GdalProvider extends AbstractRasterProvider { |
78 |
public static String NAME = "Gdal Store"; |
79 |
public static String DESCRIPTION = "Gdal Raster file"; |
80 |
public static final String METADATA_DEFINITION_NAME = "GdalStore"; |
81 |
private static final Logger logger = LoggerFactory.getLogger(GdalProvider.class); |
82 |
|
83 |
public static final String FORMAT_GTiff = "GTiff"; |
84 |
public static final String FORMAT_VRT = "VRT"; |
85 |
public static final String FORMAT_NITF = "NITF"; |
86 |
public static final String FORMAT_HFA = "HFA"; |
87 |
public static final String FORMAT_ELAS = "ELAS"; |
88 |
public static final String FORMAT_MEM = "MEM"; |
89 |
public static final String FORMAT_BMP = "BMP"; |
90 |
public static final String FORMAT_PCIDSK = "PCIDSK"; |
91 |
public static final String FORMAT_ILWIS = "ILWIS"; |
92 |
public static final String FORMAT_HDF4 = "HDF4Image"; |
93 |
public static final String FORMAT_PNM = "PNM"; |
94 |
public static final String FORMAT_ENVI = "ENVI"; |
95 |
public static final String FORMAT_EHDR = "EHdr"; |
96 |
public static final String FORMAT_PAUX = "PAux"; |
97 |
public static final String FORMAT_MFF = "MFF"; |
98 |
public static final String FORMAT_MFF2 = "MFF2"; |
99 |
public static final String FORMAT_BT = "BT"; |
100 |
public static final String FORMAT_IDA = "IDA"; |
101 |
public static final String FORMAT_RMF = "RMF"; |
102 |
public static final String FORMAT_RST = "RST"; |
103 |
public static final String FORMAT_LEVELLER = "Leveller"; |
104 |
public static final String FORMAT_TERRAGEN = "Terragen"; |
105 |
public static final String FORMAT_ERS = "ERS"; |
106 |
public static final String FORMAT_INGR = "INGR"; |
107 |
public static final String FORMAT_GSAG = "GSAG"; |
108 |
public static final String FORMAT_GSBG = "GSBG"; |
109 |
public static final String FORMAT_ADRG = "ADRG"; |
110 |
public static final String FORMAT_JP2 = "JPEG2000"; |
111 |
public static final String FORMAT_GRD = "GRD"; |
112 |
public static final int BAND_HEIGHT = 64; |
113 |
protected GdalDataSource file = null; |
114 |
private Extent viewRequest = null; |
115 |
protected static String[][] formatList = null; |
116 |
|
117 |
public static void register() { |
118 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
119 |
registerFormats(); |
120 |
|
121 |
ExtensionPoint point = extensionPoints.get("DefaultRasterProvider");
|
122 |
point.append("reader", GdalProvider.NAME, GdalProvider.class);
|
123 |
|
124 |
RasterLocator.getManager().getProviderServices().registerFileProvidersTiled(GdalProvider.class); |
125 |
|
126 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
127 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
128 |
dataman.registerStoreProvider(NAME, |
129 |
GdalProvider.class, GdalDataParameters.class); |
130 |
} |
131 |
|
132 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
133 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
134 |
NAME, DESCRIPTION, |
135 |
GdalFilesystemServerExplorer.class); |
136 |
|
137 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
138 |
} |
139 |
|
140 |
private static void registerFormats() { |
141 |
formatList = new String[][] { |
142 |
new String[] {"bmp","image/bmp" }, |
143 |
new String[] {"gif","image/gif" }, |
144 |
new String[] {"tif","image/tiff" }, |
145 |
new String[] {"tiff","image/tiff" }, |
146 |
new String[] {"jpg","image/jpeg" }, |
147 |
new String[] {"jpeg","image/jpeg" }, |
148 |
new String[] {"png","image/png" }, |
149 |
new String[] {"vrt","image/vrt" }, |
150 |
new String[] {"dat","image/dat" }, // Envi |
151 |
new String[] {"lan","image/lan" }, // Erdas |
152 |
new String[] {"gis","image/gis" }, // Erdas |
153 |
new String[] {"img","image/img" }, // Erdas |
154 |
new String[] {"pix", "image/pix" },// PCI Geomatics |
155 |
new String[] {"aux","image/aux" }, // PCI Geomatics |
156 |
new String[] {"adf","image/adf" }, // ESRI Grids |
157 |
new String[] {"mpr","image/mpr" }, // Ilwis |
158 |
new String[] {"mpl","image/mpl" }, // Ilwis |
159 |
new String[] {"map", "image/map" },// PC Raster |
160 |
new String[] {"asc","image/asc" }, |
161 |
new String[] {"pgm", "image/pgn" },//Ficheros PNM en escala de grises |
162 |
new String[] {"ppm", "image/ppm" },//Ficheros PNM en RGB |
163 |
new String[] {"rst", "image/rst" },//IDRISIS |
164 |
new String[] {"rmf", "image/rmf" },//Raster Matrix Format |
165 |
new String[] {"nos","image/nos" }, |
166 |
new String[] {"kap","image/kap" }, |
167 |
new String[] {"hdr","image/hdr" }, |
168 |
new String[] {"raw","image/raw" }, |
169 |
new String[] {"ers","image/ers" }, |
170 |
new String[] {"xml","image/xml" }, |
171 |
new String[] {"grd","image/grd" }, |
172 |
/*
|
173 |
new String[] {"jp2","image/jp2" },
|
174 |
new String[] {"mrsid","image/mrsid" },
|
175 |
new String[] {"ecw","image/ecw" },
|
176 |
*/
|
177 |
new String[] {"txt","image/txt" } |
178 |
}; |
179 |
for (int i = 0; i < formatList.length; i++) |
180 |
RasterLocator.getManager().getProviderServices().addFormat(formatList[i][0], GdalProvider.class);
|
181 |
} |
182 |
|
183 |
public String[] getFormatList() { |
184 |
String[] fl = new String[formatList.length]; |
185 |
for( int i=0; i<fl.length; i++) { |
186 |
fl[i] = formatList[i][0];
|
187 |
} |
188 |
return fl;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* Returns true if the extension is supported and false if doesn't
|
193 |
* @param ext
|
194 |
* @return
|
195 |
*/
|
196 |
public boolean isExtensionSupported(String ext) { |
197 |
if(ext.indexOf(".") != -1) |
198 |
ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length()); |
199 |
for (int i = 0; i < formatList.length; i++) { |
200 |
if(formatList[i][0].compareTo(ext) == 0) |
201 |
return true; |
202 |
} |
203 |
return false; |
204 |
} |
205 |
|
206 |
/**
|
207 |
* Mandatory constructor to instantiate an empty provider
|
208 |
*/
|
209 |
public GdalProvider() {
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* Constructor. Abre el dataset.
|
214 |
* @param params
|
215 |
* @throws NotSupportedExtensionException
|
216 |
* @throws OpenException
|
217 |
* @deprecated use {@link #GdalProvider(URI)}, this constructor will be removed in gvSIG 2.5
|
218 |
*/
|
219 |
public GdalProvider(String params) throws NotSupportedExtensionException, OpenException { |
220 |
super(params);
|
221 |
logger.info("Deprecated use of GdalProvider constructor");
|
222 |
if(params instanceof String) { |
223 |
GdalDataParameters p = new GdalDataParameters();
|
224 |
URI uriParam;
|
225 |
try {
|
226 |
uriParam = new URI((String)params); |
227 |
} catch (URISyntaxException e) { |
228 |
throw new OpenException("Can't create uri from "+(String)params, e); |
229 |
} |
230 |
p.setURI(uriParam); |
231 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
232 |
.createDynObject( |
233 |
MetadataLocator.getMetadataManager().getDefinition( |
234 |
DataStore.METADATA_DEFINITION_NAME))); |
235 |
init(p, null);
|
236 |
} |
237 |
} |
238 |
|
239 |
/**
|
240 |
* Constructor. Abre el dataset.
|
241 |
* @param uri
|
242 |
* @throws NotSupportedExtensionException
|
243 |
*/
|
244 |
public GdalProvider(URI uri) throws NotSupportedExtensionException { |
245 |
super(uri);
|
246 |
GdalDataParameters p = new GdalDataParameters();
|
247 |
p.setURI(uri); |
248 |
super.init(
|
249 |
p, |
250 |
null,
|
251 |
ToolsLocator.getDynObjectManager().createDynObject( |
252 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME))); |
253 |
init(p, null);
|
254 |
} |
255 |
|
256 |
public GdalProvider (GdalDataParameters params,
|
257 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
|
258 |
super(params, storeServices, ToolsLocator.getDynObjectManager()
|
259 |
.createDynObject( |
260 |
MetadataLocator.getMetadataManager().getDefinition( |
261 |
DataStore.METADATA_DEFINITION_NAME))); |
262 |
init(params, storeServices); |
263 |
} |
264 |
|
265 |
public GdalProvider(AbstractRasterDataParameters params,
|
266 |
DataStoreProviderServices storeServices, DynObject metadata) { |
267 |
super(params, storeServices, metadata);
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* Creates file references and loads structures with the information and metadata
|
272 |
* @param params load parameters
|
273 |
* @param storeServices
|
274 |
* @throws NotSupportedExtensionException
|
275 |
*/
|
276 |
public void init (AbstractRasterDataParameters params, |
277 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
|
278 |
try {
|
279 |
setParam(storeServices, params); |
280 |
validRmf(params.getURI().getPath()); |
281 |
setFName(translateFileName(params.getURI().getPath())); |
282 |
// GdalNative aux = new GdalNative(translateFileName(params.getURI()));
|
283 |
// long ptro = aux.getPtro();
|
284 |
// aux.delete();
|
285 |
file = new GdalDataSource(translateFileName(params.getURI().getPath()));
|
286 |
setColorInterpretation(file.colorInterpr); |
287 |
setColorTable(file.palette); |
288 |
noData = file.getNoDataValue(); |
289 |
String wktProjection = file.getProjectionRef();
|
290 |
if(wktProjection != null && wktProjection != "") { |
291 |
try {
|
292 |
if(RasterLocator.getManager().isCRSUtilSupported())
|
293 |
proj = RasterLocator.getManager().getCRSUtils().convertWktToIProjection(wktProjection); |
294 |
} catch (Exception e) { |
295 |
logger.info("Error reading WKT from the raster provider", e);
|
296 |
} |
297 |
} |
298 |
//CrsWkt crs = new CrsWkt(wktProjection);
|
299 |
//IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
300 |
ownTransformation = file.getOwnTransformation(); |
301 |
externalTransformation = (AffineTransform)ownTransformation.clone();
|
302 |
load(); |
303 |
|
304 |
if(file != null) |
305 |
bandCount = file.getRasterCount(); |
306 |
} catch (GdalException e) {
|
307 |
throw new NotSupportedExtensionException("Extension not supported", e); |
308 |
} catch(Exception e) { |
309 |
System.out.println("Error en GdalOpen"); |
310 |
e.printStackTrace(); |
311 |
file = null;
|
312 |
} |
313 |
|
314 |
//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
|
315 |
int[] dt = new int[file.getDataType().length]; |
316 |
for (int i = 0; i < dt.length; i++) |
317 |
dt[i] = GdalDataSource.getRasterBufTypeFromGdalType(file.getDataType()[i]); |
318 |
setDataType(dt); |
319 |
|
320 |
super.init();
|
321 |
|
322 |
try {
|
323 |
loadFromRmf(getRmfBlocksManager()); |
324 |
} catch (ParsingException e) {
|
325 |
//No lee desde rmf
|
326 |
logger.debug("Problems reading from the RMF file", e);
|
327 |
} |
328 |
} |
329 |
|
330 |
public String getMimeType() { |
331 |
try {
|
332 |
File f = ((FilesystemStoreParameters) (this.getDataStoreParameters())).getFile(); |
333 |
String ext = FilenameUtils.getExtension(f.getName());
|
334 |
for (int i = 0; i < formatList.length; i++) { |
335 |
if (ext.equalsIgnoreCase(formatList[i][0])) { |
336 |
return formatList[i][1]; |
337 |
} |
338 |
} |
339 |
} catch (Exception ex) { |
340 |
logger.warn("Can't get mime type for GDAL archive.",ex);
|
341 |
} |
342 |
return "image"; |
343 |
} |
344 |
|
345 |
/**
|
346 |
* Comprueba si el fichero abierto es un RasterMetaFile o una imagen
|
347 |
* raster.
|
348 |
* @throws GdalException
|
349 |
*/
|
350 |
private void validRmf(String file) throws GdalException { |
351 |
if(file.endsWith(".rmf")) { |
352 |
File f = new File(file); |
353 |
try {
|
354 |
FileReader fr = new FileReader(f); |
355 |
BufferedReader br = new BufferedReader(fr); |
356 |
char[] buffer = new char[5]; |
357 |
br.read(buffer); |
358 |
StringBuffer st = new StringBuffer(new String(buffer)); |
359 |
br.close(); |
360 |
fr.close(); |
361 |
if(st.toString().equals("<?xml")) |
362 |
throw new GdalException("RasterMetaFile"); |
363 |
} catch (FileNotFoundException e) { |
364 |
throw new GdalException("File Not Found"); |
365 |
} catch (IOException e) { |
366 |
throw new GdalException(""); |
367 |
} |
368 |
} |
369 |
} |
370 |
|
371 |
public RasterProvider load() {
|
372 |
return this; |
373 |
} |
374 |
|
375 |
public boolean isOpen() { |
376 |
if(file != null && file.isOpen()) |
377 |
return true; |
378 |
return false; |
379 |
} |
380 |
|
381 |
public URI translateURI(URI uri) { |
382 |
if ("hdr".equalsIgnoreCase(FilenameUtils.getExtension(uri.getPath()))) { |
383 |
File file = new File(FilenameUtils.removeExtension(uri.getPath())); |
384 |
return file.toURI();
|
385 |
} |
386 |
return uri;
|
387 |
} |
388 |
|
389 |
/**
|
390 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n
|
391 |
* de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v)
|
392 |
* ha de estar en coordenadas del fichero.
|
393 |
* @param e
|
394 |
*/
|
395 |
public void setView(Extent e) { |
396 |
viewRequest = new ExtentImpl(e);
|
397 |
} |
398 |
|
399 |
public Extent getView() {
|
400 |
return viewRequest;
|
401 |
} |
402 |
|
403 |
public double getWidth() { |
404 |
return file.width;
|
405 |
} |
406 |
|
407 |
public double getHeight() { |
408 |
return file.height;
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* Read a line from the file
|
413 |
* @param line
|
414 |
* @param band
|
415 |
* @return
|
416 |
* @throws InvalidSetViewException
|
417 |
* @throws FileNotOpenException
|
418 |
* @throws RasterDriverException
|
419 |
* @Deprecated This operation is deprecated because is not useful and in the future
|
420 |
* it will not be maintained. The abstract operation has dissapear
|
421 |
*/
|
422 |
public Object readCompleteLine(int line, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
423 |
if(line > this.getHeight() || band > this.getBandCount()) |
424 |
throw new InvalidSetViewException("Request out of grid"); |
425 |
|
426 |
try{
|
427 |
return file.readCompleteLine(line, band);
|
428 |
}catch(GdalException e){
|
429 |
throw new RasterDriverException("Error reading data from Gdal library"); |
430 |
} |
431 |
} |
432 |
|
433 |
public Object readBlock(int pos, int blockHeight, double scale) |
434 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
|
435 |
if(pos < 0) |
436 |
throw new InvalidSetViewException("Request out of grid"); |
437 |
|
438 |
if((pos + blockHeight) > getHeight())
|
439 |
blockHeight = Math.abs(((int)getHeight()) - pos); |
440 |
try{
|
441 |
return file.readBlock(pos, blockHeight, scale);
|
442 |
}catch(GdalException e){
|
443 |
throw new RasterDriverException("Error reading data from Gdal library"); |
444 |
} |
445 |
} |
446 |
|
447 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
448 |
if(file != null){ |
449 |
if(x < 0 || y < 0 || x >= file.width || y >= file.height) |
450 |
throw new InvalidSetViewException("Request out of grid"); |
451 |
Object[] data = file.getData(x, y); |
452 |
return data[band];
|
453 |
} |
454 |
throw new FileNotOpenException("GdalNative not exist"); |
455 |
} |
456 |
|
457 |
@Override
|
458 |
public void loadBuffer(SpiRasterQuery q) |
459 |
throws ProcessInterruptedException, RasterDriverException {
|
460 |
setView(q.getAdjustedRequestBoundingBox()); |
461 |
|
462 |
try {
|
463 |
file.readWindow(q.getBufferForProviders(), |
464 |
q.getBandList(), |
465 |
q.getAdjustedRequestBoundingBox(), |
466 |
q.getAdjustedRequestPxWindow(), |
467 |
q.getTaskStatus()); |
468 |
} catch (GdalException e) {
|
469 |
throw new RasterDriverException("Error reading data", e); |
470 |
} |
471 |
|
472 |
} |
473 |
|
474 |
public int getBlockSize(){ |
475 |
if(file != null) |
476 |
return file.getBlockSize();
|
477 |
else
|
478 |
return 0; |
479 |
} |
480 |
|
481 |
public DataStoreMetadata getMetadata() {
|
482 |
if(file != null) |
483 |
return file.metadata;
|
484 |
else
|
485 |
return null; |
486 |
} |
487 |
|
488 |
public Transparency getTransparency() { |
489 |
return file.fileTransparency;
|
490 |
} |
491 |
|
492 |
public boolean isGeoreferenced() { |
493 |
if(file != null) |
494 |
return file.georeferenced;
|
495 |
else
|
496 |
return false; |
497 |
} |
498 |
|
499 |
/**
|
500 |
* Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
|
501 |
* el valor de esta variable cada vez que dibuja.
|
502 |
* @return true si se ha supersampleado y false si no se ha hecho.
|
503 |
*/
|
504 |
public boolean isSupersampling() { |
505 |
if(file != null) |
506 |
return file.isSupersampling;
|
507 |
else
|
508 |
return false; |
509 |
} |
510 |
|
511 |
protected GdalDataSource getNative(){
|
512 |
return file;
|
513 |
} |
514 |
|
515 |
public void setAffineTransform(AffineTransform t){ |
516 |
super.setAffineTransform(t);
|
517 |
file.setExternalTransform(t); |
518 |
} |
519 |
|
520 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
521 |
if(band >= getBandCount())
|
522 |
throw new BandAccessException("Wrong band"); |
523 |
try {
|
524 |
return file.getRasterBand(band + 1).getOverviewCount(); |
525 |
} catch (GdalException e) {
|
526 |
throw new RasterDriverException(""); |
527 |
} |
528 |
} |
529 |
|
530 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
531 |
if (band >= getBandCount())
|
532 |
throw new BandAccessException("Wrong band"); |
533 |
try {
|
534 |
if (overview >= file.getRasterBand(band + 1).getOverviewCount()) |
535 |
throw new BandAccessException("Wrong overview count"); |
536 |
return file.getRasterBand(band + 1).getOverview(overview).getRasterBandXSize(); |
537 |
} catch (GdalException e) {
|
538 |
throw new RasterDriverException(""); |
539 |
} |
540 |
} |
541 |
|
542 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
543 |
if (band >= getBandCount())
|
544 |
throw new BandAccessException("Wrong band"); |
545 |
try {
|
546 |
if (overview >= file.getRasterBand(band + 1).getOverviewCount()) |
547 |
throw new BandAccessException("Wrong overview count"); |
548 |
return file.getRasterBand(band + 1).getOverview(overview).getRasterBandYSize(); |
549 |
} catch (GdalException e) {
|
550 |
throw new RasterDriverException(""); |
551 |
} |
552 |
} |
553 |
|
554 |
public boolean isOverviewsSupported() { |
555 |
return true; |
556 |
} |
557 |
|
558 |
public boolean isReproyectable() { |
559 |
return true; |
560 |
} |
561 |
|
562 |
public boolean needEnhanced() { |
563 |
return (getDataType()[0] != Buffer.TYPE_BYTE); |
564 |
//Desconozco pq raz?n estaba esta condici?n. Quiz?s haya que volver a a?adirla
|
565 |
//Eliminada 30/5/2013
|
566 |
//|| (getBandCount() == 1 && getDataType()[0] == Buffer.TYPE_BYTE));
|
567 |
} |
568 |
|
569 |
public String getProviderName() { |
570 |
return NAME;
|
571 |
} |
572 |
|
573 |
public void setStatus(RasterProvider provider) { |
574 |
if(provider instanceof GdalProvider) { |
575 |
//Not implemented yet
|
576 |
} |
577 |
} |
578 |
|
579 |
public TileServer getTileServer() {
|
580 |
if(tileServer == null) { |
581 |
DefaultRasterStore store = new DefaultRasterStore();
|
582 |
store.setProvider(this);
|
583 |
tileServer = new FileTileServer(store);
|
584 |
// tileServer.setFileSuffix("rmf");
|
585 |
} |
586 |
return tileServer;
|
587 |
} |
588 |
|
589 |
public void close() { |
590 |
if(file != null){ |
591 |
file.dispose(); |
592 |
} |
593 |
try {
|
594 |
finalize(); |
595 |
} catch (Throwable e) { |
596 |
} |
597 |
} |
598 |
|
599 |
protected void finalize() throws Throwable { |
600 |
file = null;
|
601 |
viewRequest = null;
|
602 |
if(formatList != null) { |
603 |
for (int i = 0; i < formatList.length; i++) { |
604 |
formatList[i] = null;
|
605 |
} |
606 |
formatList = null;
|
607 |
} |
608 |
super.finalize();
|
609 |
} |
610 |
|
611 |
public void addFile(File file) throws InvalidSourceException { |
612 |
// Do nothing
|
613 |
} |
614 |
|
615 |
public void removeFile(File file) { |
616 |
// Do nothing
|
617 |
} |
618 |
} |