Revision 4181 org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalProvider.java
GdalProvider.java | ||
---|---|---|
27 | 27 |
import java.io.FileNotFoundException; |
28 | 28 |
import java.io.FileReader; |
29 | 29 |
import java.io.IOException; |
30 |
import java.net.URI; |
|
31 |
import java.net.URISyntaxException; |
|
30 | 32 |
|
31 | 33 |
import org.gvsig.fmap.dal.DALFileLocator; |
32 | 34 |
import org.gvsig.fmap.dal.DALLocator; |
... | ... | |
37 | 39 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
38 | 40 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
39 | 41 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
42 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
|
40 | 43 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
41 | 44 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
42 | 45 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
43 | 46 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
44 | 47 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
48 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
45 | 49 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
46 | 50 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
47 | 51 |
import org.gvsig.jgdal.GdalException; |
... | ... | |
60 | 64 |
import org.gvsig.tools.dynobject.DynObject; |
61 | 65 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
62 | 66 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
67 |
|
|
68 |
import org.apache.commons.io.FilenameUtils; |
|
63 | 69 |
import org.slf4j.Logger; |
64 | 70 |
import org.slf4j.LoggerFactory; |
65 | 71 |
/** |
... | ... | |
72 | 78 |
public static String DESCRIPTION = "Gdal Raster file"; |
73 | 79 |
public static final String METADATA_DEFINITION_NAME = "GdalStore"; |
74 | 80 |
private static final Logger logger = LoggerFactory.getLogger(GdalProvider.class); |
75 |
|
|
81 |
|
|
76 | 82 |
public static final String FORMAT_GTiff = "GTiff"; |
77 | 83 |
public static final String FORMAT_VRT = "VRT"; |
78 | 84 |
public static final String FORMAT_NITF = "NITF"; |
... | ... | |
106 | 112 |
protected GdalNative file = null; |
107 | 113 |
private Extent viewRequest = null; |
108 | 114 |
protected static String[] formatList = null; |
109 |
|
|
115 |
|
|
110 | 116 |
public static void register() { |
111 | 117 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
112 | 118 |
registerFormats(); |
113 |
|
|
119 |
|
|
114 | 120 |
ExtensionPoint point = extensionPoints.get("DefaultRasterProvider"); |
115 | 121 |
point.append("reader", GdalProvider.NAME, GdalProvider.class); |
116 |
|
|
122 |
|
|
117 | 123 |
RasterLocator.getManager().getProviderServices().registerFileProvidersTiled(GdalProvider.class); |
118 |
|
|
124 |
|
|
119 | 125 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
120 | 126 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
121 | 127 |
dataman.registerStoreProvider(NAME, |
122 | 128 |
GdalProvider.class, GdalDataParameters.class); |
123 | 129 |
} |
124 |
|
|
130 |
|
|
125 | 131 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
126 | 132 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
127 | 133 |
NAME, DESCRIPTION, |
128 | 134 |
GdalFilesystemServerExplorer.class); |
129 |
|
|
135 |
|
|
130 | 136 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
131 | 137 |
} |
132 |
|
|
138 |
|
|
133 | 139 |
private static void registerFormats() { |
134 | 140 |
formatList = new String[] { |
135 |
"bmp",
|
|
141 |
"bmp", |
|
136 | 142 |
"gif", |
137 | 143 |
"tif", |
138 | 144 |
"tiff", |
... | ... | |
164 | 170 |
"grd", |
165 | 171 |
"txt"/*, |
166 | 172 |
"jp2"*/}; |
167 |
for (int i = 0; i < formatList.length; i++)
|
|
173 |
for (int i = 0; i < formatList.length; i++) |
|
168 | 174 |
RasterLocator.getManager().getProviderServices().addFormat(formatList[i], GdalProvider.class); |
169 | 175 |
} |
170 |
|
|
176 |
|
|
171 | 177 |
public String[] getFormatList() { |
172 | 178 |
return formatList; |
173 | 179 |
} |
174 |
|
|
180 |
|
|
175 | 181 |
/** |
176 | 182 |
* Returns true if the extension is supported and false if doesn't |
177 | 183 |
* @param ext |
... | ... | |
186 | 192 |
} |
187 | 193 |
return false; |
188 | 194 |
} |
189 |
|
|
195 |
|
|
190 | 196 |
/** |
191 | 197 |
* Mandatory constructor to instantiate an empty provider |
192 | 198 |
*/ |
193 | 199 |
public GdalProvider() { |
194 | 200 |
} |
195 |
|
|
201 |
|
|
196 | 202 |
/** |
197 | 203 |
* Constructor. Abre el dataset. |
198 | 204 |
* @param proj Proyecci?n |
199 | 205 |
* @param fName Nombre del fichero |
200 | 206 |
* @throws NotSupportedExtensionException |
207 |
* @throws OpenException |
|
208 |
* @deprecated use {@link #GdalProvider(URI)}, this constructor will be removed in gvSIG 2.5 |
|
201 | 209 |
*/ |
202 |
public GdalProvider(String params) throws NotSupportedExtensionException { |
|
210 |
public GdalProvider(String params) throws NotSupportedExtensionException, OpenException {
|
|
203 | 211 |
super(params); |
212 |
logger.info("Deprecated use of GdalProvider constructor"); |
|
204 | 213 |
if(params instanceof String) { |
205 | 214 |
GdalDataParameters p = new GdalDataParameters(); |
206 |
p.setURI((String)params); |
|
215 |
URI uriParam; |
|
216 |
try { |
|
217 |
uriParam = new URI((String)params); |
|
218 |
} catch (URISyntaxException e) { |
|
219 |
throw new OpenException("Can't create uri from "+(String)params, e); |
|
220 |
} |
|
221 |
p.setURI(uriParam); |
|
207 | 222 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
208 | 223 |
.createDynObject( |
209 | 224 |
MetadataLocator.getMetadataManager().getDefinition( |
... | ... | |
211 | 226 |
init(p, null); |
212 | 227 |
} |
213 | 228 |
} |
214 |
|
|
215 |
public GdalProvider (GdalDataParameters params, |
|
229 |
|
|
230 |
/** |
|
231 |
* Constructor. Abre el dataset. |
|
232 |
* @param proj Proyecci?n |
|
233 |
* @param fName Nombre del fichero |
|
234 |
* @throws NotSupportedExtensionException |
|
235 |
*/ |
|
236 |
public GdalProvider(URI uri) throws NotSupportedExtensionException { |
|
237 |
super(uri); |
|
238 |
GdalDataParameters p = new GdalDataParameters(); |
|
239 |
p.setURI(uri); |
|
240 |
super.init( |
|
241 |
p, |
|
242 |
null, |
|
243 |
ToolsLocator.getDynObjectManager().createDynObject( |
|
244 |
MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME))); |
|
245 |
init(p, null); |
|
246 |
} |
|
247 |
|
|
248 |
public GdalProvider (GdalDataParameters params, |
|
216 | 249 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
217 | 250 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
218 | 251 |
.createDynObject( |
... | ... | |
220 | 253 |
DataStore.METADATA_DEFINITION_NAME))); |
221 | 254 |
init(params, storeServices); |
222 | 255 |
} |
223 |
|
|
256 |
|
|
224 | 257 |
public GdalProvider(AbstractRasterDataParameters params, |
225 | 258 |
DataStoreProviderServices storeServices, DynObject metadata) { |
226 | 259 |
super(params, storeServices, metadata); |
227 | 260 |
} |
228 |
|
|
261 |
|
|
229 | 262 |
/** |
230 | 263 |
* Creates file references and loads structures with the information and metadata |
231 | 264 |
* @param params load parameters |
... | ... | |
235 | 268 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException { |
236 | 269 |
try { |
237 | 270 |
setParam(storeServices, params); |
238 |
validRmf(params.getURI()); |
|
239 |
setFName(translateFileName(params.getURI())); |
|
271 |
validRmf(params.getURI().getPath());
|
|
272 |
setFName(translateFileName(params.getURI().getPath()));
|
|
240 | 273 |
// GdalNative aux = new GdalNative(translateFileName(params.getURI())); |
241 | 274 |
// long ptro = aux.getPtro(); |
242 | 275 |
// aux.delete(); |
243 |
file = new GdalNative(translateFileName(params.getURI())); |
|
276 |
file = new GdalNative(translateFileName(params.getURI().getPath()));
|
|
244 | 277 |
setColorInterpretation(file.colorInterpr); |
245 | 278 |
setColorTable(file.palette); |
246 | 279 |
noData = file.getNoDataValue(); |
... | ... | |
314 | 347 |
public RasterProvider load() { |
315 | 348 |
return this; |
316 | 349 |
} |
317 |
|
|
350 |
|
|
318 | 351 |
public boolean isOpen() { |
319 | 352 |
if(file != null && file.isOpen()) |
320 | 353 |
return true; |
321 | 354 |
return false; |
322 | 355 |
} |
323 | 356 |
|
324 |
public String translateFileName(String fileName) { |
|
325 |
if(fileName.endsWith("hdr")) |
|
326 |
return fileName.substring(0, fileName.lastIndexOf(".")); |
|
327 |
return fileName; |
|
357 |
public URI translateURI(URI uri) { |
|
358 |
if ("hdr".equalsIgnoreCase(FilenameUtils.getExtension(uri.getPath()))) { |
|
359 |
File file = new File(FilenameUtils.removeExtension(uri.getPath())); |
|
360 |
return file.toURI(); |
|
361 |
} |
|
362 |
return uri; |
|
328 | 363 |
} |
329 | 364 |
|
330 | 365 |
/** |
... | ... | |
395 | 430 |
} |
396 | 431 |
|
397 | 432 |
@Override |
398 |
public void loadBuffer(SpiRasterQuery q)
|
|
433 |
public void loadBuffer(SpiRasterQuery q) |
|
399 | 434 |
throws ProcessInterruptedException, RasterDriverException { |
400 | 435 |
setView(q.getAdjustedRequestBoundingBox()); |
401 |
|
|
436 |
|
|
402 | 437 |
try { |
403 |
file.readWindow(q.getBufferForProviders(),
|
|
404 |
q.getBandList(),
|
|
405 |
q.getAdjustedRequestBoundingBox(),
|
|
438 |
file.readWindow(q.getBufferForProviders(), |
|
439 |
q.getBandList(), |
|
440 |
q.getAdjustedRequestBoundingBox(), |
|
406 | 441 |
q.getAdjustedRequestPxWindow(), |
407 | 442 |
q.getTaskStatus()); |
408 | 443 |
} catch (GdalException e) { |
409 | 444 |
throw new RasterDriverException("Error reading data", e); |
410 | 445 |
} |
411 |
|
|
446 |
|
|
412 | 447 |
} |
413 |
|
|
448 |
|
|
414 | 449 |
public int getBlockSize(){ |
415 | 450 |
if(file != null) |
416 | 451 |
return file.getBlockSize(); |
... | ... | |
498 | 533 |
public boolean isReproyectable() { |
499 | 534 |
return true; |
500 | 535 |
} |
501 |
|
|
536 |
|
|
502 | 537 |
public boolean needEnhanced() { |
503 |
return (getDataType()[0] != Buffer.TYPE_BYTE);
|
|
538 |
return (getDataType()[0] != Buffer.TYPE_BYTE); |
|
504 | 539 |
//Desconozco pq raz?n estaba esta condici?n. Quiz?s haya que volver a a?adirla |
505 | 540 |
//Eliminada 30/5/2013 |
506 | 541 |
//|| (getBandCount() == 1 && getDataType()[0] == Buffer.TYPE_BYTE)); |
... | ... | |
509 | 544 |
public String getProviderName() { |
510 | 545 |
return NAME; |
511 | 546 |
} |
512 |
|
|
547 |
|
|
513 | 548 |
public void setStatus(RasterProvider provider) { |
514 | 549 |
if(provider instanceof GdalProvider) { |
515 | 550 |
//Not implemented yet |
516 | 551 |
} |
517 | 552 |
} |
518 |
|
|
553 |
|
|
519 | 554 |
public TileServer getTileServer() { |
520 | 555 |
if(tileServer == null) { |
521 | 556 |
DefaultRasterStore store = new DefaultRasterStore(); |
... | ... | |
525 | 560 |
} |
526 | 561 |
return tileServer; |
527 | 562 |
} |
528 |
|
|
563 |
|
|
529 | 564 |
public void close() { |
530 | 565 |
if(file != null){ |
531 | 566 |
file.dispose(); |
... | ... | |
535 | 570 |
} catch (Throwable e) { |
536 | 571 |
} |
537 | 572 |
} |
538 |
|
|
573 |
|
|
539 | 574 |
protected void finalize() throws Throwable { |
540 | 575 |
file = null; |
541 | 576 |
viewRequest = null; |
... | ... | |
547 | 582 |
} |
548 | 583 |
super.finalize(); |
549 | 584 |
} |
585 |
|
|
586 |
public void addFile(File file) throws InvalidSourceException { |
|
587 |
// Do nothing |
|
588 |
} |
|
589 |
|
|
590 |
public void removeFile(File file) { |
|
591 |
// Do nothing |
|
592 |
} |
|
550 | 593 |
} |
Also available in: Unified diff