gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.multifile.io / src / main / java / org / gvsig / raster / tools / multifile / io / MultiFileProvider.java @ 1047
History | View | Annotate | Download (28.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.tools.multifile.io; |
23 |
|
24 |
import java.awt.geom.AffineTransform; |
25 |
import java.awt.geom.Point2D; |
26 |
import java.awt.geom.Rectangle2D; |
27 |
import java.io.File; |
28 |
import java.io.IOException; |
29 |
import java.util.ArrayList; |
30 |
|
31 |
import org.gvsig.fmap.dal.DALFileLocator; |
32 |
import org.gvsig.fmap.dal.DALLocator; |
33 |
import org.gvsig.fmap.dal.DataStore; |
34 |
import org.gvsig.fmap.dal.DataStoreParameters; |
35 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
36 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
37 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
38 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
39 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
40 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
41 |
import org.gvsig.fmap.dal.coverage.exception.FileNotSupportedException; |
42 |
import org.gvsig.fmap.dal.coverage.exception.HistogramException; |
43 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
44 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
45 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
46 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
47 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
48 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
49 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
50 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
51 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
52 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
53 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
54 |
import org.gvsig.fmap.dal.coverage.util.ProviderServices; |
55 |
import org.gvsig.fmap.dal.exception.CloseException; |
56 |
import org.gvsig.fmap.dal.exception.InitializeException; |
57 |
import org.gvsig.fmap.dal.exception.OpenException; |
58 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
59 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
60 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
61 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
62 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
63 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
64 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
65 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
66 |
import org.gvsig.metadata.MetadataLocator; |
67 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
68 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
69 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
70 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
71 |
import org.gvsig.raster.impl.provider.RasterProvider; |
72 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
73 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
74 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
75 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
76 |
import org.gvsig.raster.impl.store.properties.MultiProviderHistogramComputer; |
77 |
import org.gvsig.raster.impl.store.properties.MultiProviderStatistics; |
78 |
import org.gvsig.tools.ToolsLocator; |
79 |
import org.gvsig.tools.locator.LocatorException; |
80 |
/**
|
81 |
* A data provider for a multiband image readed from different files
|
82 |
*
|
83 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
84 |
*/
|
85 |
public class MultiFileProvider extends DefaultRasterProvider { |
86 |
public static String NAME = "Multifile Raster"; |
87 |
public static String DESCRIPTION = "Multifile Raster Support"; |
88 |
public final String METADATA_DEFINITION_NAME = NAME; |
89 |
private Extent viewRequest = null; |
90 |
private TileServer tileServer = null; |
91 |
private boolean open = false; |
92 |
|
93 |
private DataStoreTransparency fileTransparency = null; |
94 |
//private static final Logger logger = LoggerFactory.getLogger(MultifileProvider.class);
|
95 |
protected static String[] formatList = null; |
96 |
private ArrayList<RasterProvider> providerList = null; |
97 |
|
98 |
public static void register() { |
99 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
100 |
registerFormats(); |
101 |
|
102 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
103 |
dataman.registerStoreProvider(NAME, |
104 |
MultiFileProvider.class, MultiFileDataParametersImpl.class); |
105 |
} |
106 |
|
107 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
108 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
109 |
NAME, DESCRIPTION, |
110 |
MultiFileServerExplorer.class); |
111 |
|
112 |
if (!dataman.getExplorerProviders().contains(NAME)) {
|
113 |
dataman.registerExplorerProvider(NAME, MultiFileServerExplorer.class, MultiFileServerExplorerParameters.class); |
114 |
} |
115 |
|
116 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
117 |
} |
118 |
|
119 |
private static void registerFormats() { |
120 |
formatList = new String[] { |
121 |
"mff"};
|
122 |
for (int i = 0; i < formatList.length; i++) |
123 |
RasterLocator.getManager().addFormat(formatList[i], MultiFileProvider.class); |
124 |
} |
125 |
|
126 |
public MultiFileProvider() {
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* Opens the dataset.
|
131 |
* @param proj Projection
|
132 |
* @param fName File name
|
133 |
* @throws NotSupportedExtensionException
|
134 |
*/
|
135 |
public MultiFileProvider(String params) throws NotSupportedExtensionException, OpenException { |
136 |
super(params);
|
137 |
if(params instanceof String) { |
138 |
MultiFileDataParameters p = new MultiFileDataParametersImpl();
|
139 |
p.setURI((String)params);
|
140 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
141 |
.createDynObject( |
142 |
MetadataLocator.getMetadataManager().getDefinition( |
143 |
DataStore.METADATA_DEFINITION_NAME))); |
144 |
init(p, null);
|
145 |
} |
146 |
} |
147 |
|
148 |
public MultiFileProvider(MultiFileDataParametersImpl params,
|
149 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException {
|
150 |
super(params, storeServices, ToolsLocator.getDynObjectManager()
|
151 |
.createDynObject( |
152 |
MetadataLocator.getMetadataManager().getDefinition( |
153 |
DataStore.METADATA_DEFINITION_NAME))); |
154 |
init(params, storeServices); |
155 |
} |
156 |
|
157 |
/**
|
158 |
* Build file references
|
159 |
* @param proj Projection
|
160 |
* @param param Load parameters
|
161 |
* @throws NotSupportedExtensionException
|
162 |
*/
|
163 |
public void init(MultiFileDataParameters params, |
164 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException {
|
165 |
|
166 |
openFromMff(); |
167 |
|
168 |
uri = getParameters().getURI(); |
169 |
providerList = getParameters().getProviders(); |
170 |
setParam(storeServices, params); |
171 |
|
172 |
super.init();
|
173 |
|
174 |
try {
|
175 |
loadFromRmf(getRmfBlocksManager()); |
176 |
} catch (ParsingException e) {
|
177 |
//No lee desde rmf
|
178 |
} |
179 |
|
180 |
open = true;
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* Open from a .mff file.
|
185 |
* This method loads all providers and adds these to the parameters
|
186 |
* @throws OpenException
|
187 |
*/
|
188 |
private void openFromMff() throws OpenException { |
189 |
if(getParameters().getURI() != null && new File(getParameters().getURI()).exists()) { |
190 |
try {
|
191 |
if(getParameters().getProviders() != null) |
192 |
getParameters().getProviders().clear(); |
193 |
MultiFileFormat multiFileFormat = new MultiFileFormat();
|
194 |
multiFileFormat = MultiFileFormatSerializer.read(multiFileFormat, getParameters().getURI()); |
195 |
for (int i = 0; i < multiFileFormat.getNumberOfFiles(); i++) { |
196 |
try {
|
197 |
File file = new File(multiFileFormat.getPathToFile(i)); |
198 |
if(file.exists()) {
|
199 |
RasterProvider prov = loadProvider(multiFileFormat.getPathToFile(i), storeServices); |
200 |
getParameters().addProvider(prov); |
201 |
} |
202 |
} catch (ProviderNotRegisteredException e) {
|
203 |
throw new OpenException("A provider can't be loaded", e); |
204 |
} catch (InitializeException e) {
|
205 |
throw new OpenException("A provider can't be initialized", e); |
206 |
} |
207 |
} |
208 |
} catch (IOException e1) { |
209 |
throw new OpenException("File .mff can't be read", e1); |
210 |
} catch (ParsingException e1) {
|
211 |
throw new OpenException("File .mff can't be parsed", e1); |
212 |
} |
213 |
} |
214 |
} |
215 |
|
216 |
/**
|
217 |
* Loads the specific provider
|
218 |
* @param file
|
219 |
* @return
|
220 |
* @throws NotSupportedExtensionException
|
221 |
* @throws FileNotSupportedException
|
222 |
*/
|
223 |
private RasterProvider loadProvider(String file, DataStoreProviderServices storeServices) throws ProviderNotRegisteredException, InitializeException { |
224 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
225 |
DataStoreProvider prov = null;
|
226 |
|
227 |
if(file != null) { |
228 |
//We have to locate a provider's name which manages the selected file
|
229 |
//A FilesystemServerExplorer will give a getProviderNames service
|
230 |
FilesystemServerExplorerParameters paramsExplorer = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
231 |
FilesystemServerExplorer serverExplorer = null;
|
232 |
try {
|
233 |
paramsExplorer.setRoot(File.separator);
|
234 |
serverExplorer = (FilesystemServerExplorer)dataManager.openServerExplorer(FilesystemServerExplorer.NAME, paramsExplorer); |
235 |
} catch (ValidateDataParametersException e) {
|
236 |
throw new InitializeException(e); |
237 |
} |
238 |
File f = new File(file); |
239 |
//Gets the list of provider's name to manage the file
|
240 |
ArrayList<String> provName = serverExplorer.getProviderNameList(f); |
241 |
if(provName.size() > 0) { |
242 |
for (int i = 0; i < provName.size(); i++) { |
243 |
//Gets the first provider what is not a TileProvider
|
244 |
if(provName.get(i).compareTo("Tile Store") != 0) { |
245 |
DataStoreParameters newparams = dataManager.createStoreParameters(provName.get(i)); |
246 |
((FilesystemStoreParameters)newparams).setFile(f); |
247 |
prov = dataManager.createProvider(storeServices, newparams); |
248 |
} |
249 |
} |
250 |
} |
251 |
} |
252 |
|
253 |
if(prov != null && prov instanceof RasterProvider) { |
254 |
if(((RasterProvider)prov).isRotated())
|
255 |
throw new InitializeException("Rotation not supported tiling files", new Throwable()); |
256 |
|
257 |
return (RasterProvider)prov;
|
258 |
} |
259 |
|
260 |
return null; |
261 |
} |
262 |
|
263 |
/**
|
264 |
* Checks if the new file is compatible with the old one
|
265 |
* @param file
|
266 |
* @return
|
267 |
* @throws LocatorException
|
268 |
* @throws NotSupportedExtensionException
|
269 |
* @throws RasterDriverException
|
270 |
* @throws CloseException
|
271 |
*/
|
272 |
private boolean checkNewProvider(RasterProvider p) { |
273 |
Rectangle2D extentOrigin = getExtent().toRectangle2D();
|
274 |
|
275 |
Extent extentNewFile = p.getExtent(); |
276 |
|
277 |
// Comprobamos que el extent y tama?o del fichero a?adido sea igual al
|
278 |
// fichero original. Si no es as? no abrimos la capa y mostramos un aviso
|
279 |
|
280 |
double widthNewFile = (extentNewFile.getMax().getX() - extentNewFile.getMin().getX());
|
281 |
double heightNewFile = (extentNewFile.getMax().getY() - extentNewFile.getMin().getY());
|
282 |
|
283 |
if ((widthNewFile - extentOrigin.getWidth()) > 1.0 || (widthNewFile - extentOrigin.getWidth()) < -1.0 || (heightNewFile - extentOrigin.getHeight()) > 1.0 |
284 |
|| (heightNewFile - extentOrigin.getHeight()) < -1.0) {
|
285 |
return false; |
286 |
} |
287 |
|
288 |
if ((extentNewFile.getMax().getX() - extentNewFile.getMin().getX()) != extentOrigin.getWidth()
|
289 |
|| (extentNewFile.getMax().getY() - extentNewFile.getMin().getY()) != extentOrigin.getHeight()) { |
290 |
return false; |
291 |
} |
292 |
|
293 |
return true; |
294 |
} |
295 |
|
296 |
public MultiFileDataParameters getParameters() {
|
297 |
try {
|
298 |
return (MultiFileDataParameters)parameters;
|
299 |
} catch (ClassCastException e) { |
300 |
return null; |
301 |
} |
302 |
} |
303 |
|
304 |
/*
|
305 |
* (non-Javadoc)
|
306 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#load()
|
307 |
*/
|
308 |
public RasterProvider load() {
|
309 |
return this; |
310 |
} |
311 |
|
312 |
/*
|
313 |
* (non-Javadoc)
|
314 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBandCount()
|
315 |
*/
|
316 |
public int getBandCount() { |
317 |
providerList = getParameters().getProviders(); |
318 |
int bandCount = 0; |
319 |
for (int i = 0; i < providerList.size(); i++) { |
320 |
bandCount += providerList.get(i).getBandCount(); |
321 |
} |
322 |
return bandCount;
|
323 |
} |
324 |
|
325 |
/*
|
326 |
* (non-Javadoc)
|
327 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getDataType()
|
328 |
*/
|
329 |
public int[] getDataType() { |
330 |
providerList = getParameters().getProviders(); |
331 |
int[] datatypes = new int[getBandCount()]; |
332 |
int k = 0; |
333 |
for (int i = 0; i < providerList.size(); i++) { |
334 |
int[] dtByProv = providerList.get(i).getDataType(); |
335 |
for (int j = 0; j < dtByProv.length; j++) { |
336 |
datatypes[k] = dtByProv[j]; |
337 |
k++; |
338 |
} |
339 |
} |
340 |
return datatypes;
|
341 |
} |
342 |
|
343 |
/*
|
344 |
* (non-Javadoc)
|
345 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getURIByProvider()
|
346 |
*/
|
347 |
public String[] getURIByProvider() { |
348 |
providerList = getParameters().getProviders(); |
349 |
String[] uris = new String[providerList.size()]; |
350 |
for (int i = 0; i < uris.length; i++) { |
351 |
uris[i] = providerList.get(i).getURIOfFirstProvider(); |
352 |
} |
353 |
return uris;
|
354 |
} |
355 |
|
356 |
/*
|
357 |
* (non-Javadoc)
|
358 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getBandPositionByProvider(int)
|
359 |
*/
|
360 |
public int getBandPositionByProvider(int band) { |
361 |
return getSubBandByBandNumber(band)[1]; |
362 |
} |
363 |
|
364 |
/*
|
365 |
* (non-Javadoc)
|
366 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getURIOfFirstProvider()
|
367 |
*/
|
368 |
public String getURIOfFirstProvider() { |
369 |
providerList = getParameters().getProviders(); |
370 |
return providerList.get(0).getURIOfFirstProvider(); |
371 |
} |
372 |
|
373 |
|
374 |
/*
|
375 |
* (non-Javadoc)
|
376 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getExtent()
|
377 |
*/
|
378 |
public Extent getExtent() {
|
379 |
providerList = getParameters().getProviders(); |
380 |
if(providerList != null && providerList.size() > 0) |
381 |
return providerList.get(0).getExtent(); |
382 |
return null; |
383 |
} |
384 |
|
385 |
/*
|
386 |
* (non-Javadoc)
|
387 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getAffineTransform()
|
388 |
*/
|
389 |
public AffineTransform getAffineTransform() { |
390 |
providerList = getParameters().getProviders(); |
391 |
return providerList.get(0).getAffineTransform(); |
392 |
} |
393 |
|
394 |
/*
|
395 |
* (non-Javadoc)
|
396 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#setAffineTransform(java.awt.geom.AffineTransform)
|
397 |
*/
|
398 |
public void setAffineTransform(AffineTransform t) { |
399 |
providerList = getParameters().getProviders(); |
400 |
for (int i = 0; i < providerList.size(); i++) { |
401 |
providerList.get(i).setAffineTransform(t); |
402 |
} |
403 |
} |
404 |
|
405 |
/*
|
406 |
* (non-Javadoc)
|
407 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getInternalProviderCount()
|
408 |
*/
|
409 |
public int getInternalProviderCount() { |
410 |
return providerList.size();
|
411 |
} |
412 |
|
413 |
/*
|
414 |
* (non-Javadoc)
|
415 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getInternalProvider(int)
|
416 |
*/
|
417 |
public RasterProvider getInternalProvider(int i) { |
418 |
return providerList.get(i);
|
419 |
} |
420 |
|
421 |
/*
|
422 |
* (non-Javadoc)
|
423 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getBandCountByProvider()
|
424 |
*/
|
425 |
public int[] getBandCountByProvider() { |
426 |
providerList = getParameters().getProviders(); |
427 |
int[] bc = new int[providerList.size()]; |
428 |
for (int i = 0; i < bc.length; i++) { |
429 |
bc[i] = providerList.get(i).getBandCount(); |
430 |
} |
431 |
return bc;
|
432 |
} |
433 |
|
434 |
/*
|
435 |
* (non-Javadoc)
|
436 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getFileSizeByProvider()
|
437 |
*/
|
438 |
public long[] getFileSizeByProvider() { |
439 |
providerList = getParameters().getProviders(); |
440 |
long[] fs = new long[providerList.size()]; |
441 |
for (int i = 0; i < fs.length; i++) { |
442 |
fs[i] = ((DefaultRasterProvider)providerList.get(i)).getFileSize(); |
443 |
} |
444 |
return fs;
|
445 |
} |
446 |
|
447 |
/*
|
448 |
* (non-Javadoc)
|
449 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#rasterToWorld(java.awt.geom.Point2D)
|
450 |
*/
|
451 |
public Point2D rasterToWorld(Point2D pt) { |
452 |
providerList = getParameters().getProviders(); |
453 |
return providerList.get(0).rasterToWorld(pt); |
454 |
} |
455 |
|
456 |
/*
|
457 |
* (non-Javadoc)
|
458 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#worldToRaster(java.awt.geom.Point2D)
|
459 |
*/
|
460 |
public Point2D worldToRaster(Point2D pt) { |
461 |
providerList = getParameters().getProviders(); |
462 |
return providerList.get(0).worldToRaster(pt); |
463 |
} |
464 |
|
465 |
/*
|
466 |
* (non-Javadoc)
|
467 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isInside(java.awt.geom.Point2D)
|
468 |
*/
|
469 |
public boolean isInside(Point2D p){ |
470 |
providerList = getParameters().getProviders(); |
471 |
return providerList.get(0).isInside(p); |
472 |
} |
473 |
|
474 |
/*
|
475 |
* (non-Javadoc)
|
476 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getCellSize()
|
477 |
*/
|
478 |
public double getCellSize() { |
479 |
providerList = getParameters().getProviders(); |
480 |
return providerList.get(0).getCellSize(); |
481 |
} |
482 |
|
483 |
/*
|
484 |
* (non-Javadoc)
|
485 |
* @see org.gvsig.raster.impl.dataset.RasterProvider#getStatistics()
|
486 |
*/
|
487 |
public Statistics getStatistics() {
|
488 |
if(stats == null || (stats instanceof MultiProviderStatistics && |
489 |
((MultiProviderStatistics)stats).getNumberOfProviders() != providerList.size())) { |
490 |
providerList = getParameters().getProviders(); |
491 |
stats = new MultiProviderStatistics(providerList);
|
492 |
} |
493 |
|
494 |
return stats;
|
495 |
} |
496 |
|
497 |
/*
|
498 |
* (non-Javadoc)
|
499 |
* @see org.gvsig.fmap.dal.coverage.store.props.Histogramable#getHistogramComputer()
|
500 |
*/
|
501 |
public HistogramComputer getHistogramComputer() throws HistogramException, InterruptedException { |
502 |
if(histogram == null || |
503 |
(histogram instanceof MultiProviderHistogramComputer &&
|
504 |
((MultiProviderHistogramComputer)histogram).getNumberOfProviders() != providerList.size())) { |
505 |
histogram = new MultiProviderHistogramComputer(this); |
506 |
} |
507 |
|
508 |
return histogram;
|
509 |
} |
510 |
|
511 |
/**
|
512 |
* A multiband provider doesn't have a color table because this will have
|
513 |
* more than one band.
|
514 |
*/
|
515 |
public ColorTable getColorTable() {
|
516 |
return null; |
517 |
} |
518 |
|
519 |
/*
|
520 |
* (non-Javadoc)
|
521 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isOpen()
|
522 |
*/
|
523 |
public boolean isOpen() { |
524 |
return open;
|
525 |
} |
526 |
|
527 |
/*
|
528 |
* (non-Javadoc)
|
529 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close()
|
530 |
*/
|
531 |
public void close() { |
532 |
} |
533 |
|
534 |
/*
|
535 |
* (non-Javadoc)
|
536 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#translateFileName(java.lang.String)
|
537 |
*/
|
538 |
public String translateFileName(String fileName) { |
539 |
return fileName;
|
540 |
} |
541 |
|
542 |
/**
|
543 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n
|
544 |
* de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v)
|
545 |
* ha de estar en coordenadas del fichero.
|
546 |
*/
|
547 |
public void setView(Extent e) { |
548 |
viewRequest = new ExtentImpl(e);
|
549 |
} |
550 |
|
551 |
/*
|
552 |
* (non-Javadoc)
|
553 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView()
|
554 |
*/
|
555 |
public Extent getView() {
|
556 |
return viewRequest;
|
557 |
} |
558 |
|
559 |
/*
|
560 |
* (non-Javadoc)
|
561 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth()
|
562 |
*/
|
563 |
public double getWidth() { |
564 |
providerList = getParameters().getProviders(); |
565 |
if(providerList != null && providerList.size() > 0) { |
566 |
return providerList.get(0).getWidth(); |
567 |
} |
568 |
return 0; |
569 |
} |
570 |
|
571 |
/*
|
572 |
* (non-Javadoc)
|
573 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight()
|
574 |
*/
|
575 |
public double getHeight() { |
576 |
providerList = getParameters().getProviders(); |
577 |
if(providerList != null && providerList.size() > 0) { |
578 |
return providerList.get(0).getHeight(); |
579 |
} |
580 |
return 0; |
581 |
|
582 |
} |
583 |
|
584 |
/*
|
585 |
* (non-Javadoc)
|
586 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int, double)
|
587 |
*/
|
588 |
public Object readBlock(int pos, int blockHeight, double scale) |
589 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
|
590 |
providerList = getParameters().getProviders(); |
591 |
return null; |
592 |
} |
593 |
|
594 |
/**
|
595 |
* Gets a number of provider and the band of this provider
|
596 |
* @param band
|
597 |
* @return
|
598 |
*/
|
599 |
private int[] getSubBandByBandNumber(int band) { |
600 |
providerList = getParameters().getProviders(); |
601 |
int[] res = new int[2]; |
602 |
int acum = 0; |
603 |
for (int i = 0; i < providerList.size(); i++) { |
604 |
acum += providerList.get(i).getBandCount(); |
605 |
if(acum > band) {
|
606 |
res[0] = i;
|
607 |
int aux = (acum - providerList.get(i).getBandCount());
|
608 |
res[1] = band - aux;
|
609 |
return res;
|
610 |
} |
611 |
} |
612 |
return res;
|
613 |
} |
614 |
|
615 |
/*
|
616 |
* (non-Javadoc)
|
617 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int)
|
618 |
*/
|
619 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
620 |
int[] sub = getSubBandByBandNumber(band); |
621 |
RasterProvider prov = providerList.get(sub[0]);
|
622 |
return prov.getData(x, y, sub[1]); |
623 |
} |
624 |
|
625 |
/*
|
626 |
* (non-Javadoc)
|
627 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener)
|
628 |
*/
|
629 |
public void getWindow(Extent ex, int bufWidth, int bufHeight, |
630 |
BandList bandList, TileListener listener) throws ProcessInterruptedException, RasterDriverException {
|
631 |
} |
632 |
|
633 |
/*
|
634 |
* (non-Javadoc)
|
635 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
636 |
*/
|
637 |
public Buffer getWindow(Extent extent, BandList bandList, Buffer rasterBuf) |
638 |
throws ProcessInterruptedException, RasterDriverException {
|
639 |
providerList = getParameters().getProviders(); |
640 |
for (int i = 0; i < providerList.size(); i++) { |
641 |
rasterBuf = ((DefaultRasterProvider)providerList.get(i)).getWindow(extent, bandList, rasterBuf); |
642 |
} |
643 |
return rasterBuf;
|
644 |
} |
645 |
|
646 |
|
647 |
|
648 |
/*
|
649 |
* (non-Javadoc)
|
650 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
|
651 |
*/
|
652 |
public Buffer getWindow(double ulx, double uly, double w, double h, |
653 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException { |
654 |
providerList = getParameters().getProviders(); |
655 |
for (int i = 0; i < providerList.size(); i++) { |
656 |
rasterBuf = ((DefaultRasterProvider)providerList.get(i)).getWindow(ulx, uly, w, h, bandList, rasterBuf, adjustToExtent); |
657 |
} |
658 |
return rasterBuf;
|
659 |
} |
660 |
|
661 |
/*
|
662 |
* (non-Javadoc)
|
663 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
|
664 |
*/
|
665 |
public Buffer getWindow(Extent extent, |
666 |
int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException { |
667 |
providerList = getParameters().getProviders(); |
668 |
for (int i = 0; i < providerList.size(); i++) { |
669 |
rasterBuf = ((DefaultRasterProvider)providerList.get(i)).getWindow(extent, bufWidth, bufHeight, bandList, rasterBuf, adjustToExtent); |
670 |
} |
671 |
return rasterBuf;
|
672 |
} |
673 |
|
674 |
/*
|
675 |
* (non-Javadoc)
|
676 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
677 |
*/
|
678 |
public Buffer getWindow(int x, int y, int w, int h, |
679 |
BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
680 |
providerList = getParameters().getProviders(); |
681 |
for (int i = 0; i < providerList.size(); i++) { |
682 |
rasterBuf = ((DefaultRasterProvider)providerList.get(i)).getWindow(x, y, w, h, bandList, rasterBuf); |
683 |
} |
684 |
return rasterBuf;
|
685 |
} |
686 |
|
687 |
/*
|
688 |
* (non-Javadoc)
|
689 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize()
|
690 |
*/
|
691 |
public int getBlockSize() { |
692 |
return 0; |
693 |
} |
694 |
|
695 |
/*
|
696 |
* (non-Javadoc)
|
697 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getColorInterpretation()
|
698 |
*/
|
699 |
public ColorInterpretation getColorInterpretation() {
|
700 |
if(super.getColorInterpretation() == null) { |
701 |
String[] cis = new String[getBandCount()]; |
702 |
for (int i = 0; i < cis.length; i++) { |
703 |
if(i == 0) |
704 |
cis[i] = ColorInterpretation.GRAY_BAND; |
705 |
else
|
706 |
cis[i] = ColorInterpretation.UNDEF_BAND; |
707 |
} |
708 |
setColorInterpretation(new DataStoreColorInterpretation(cis));
|
709 |
} |
710 |
return super.getColorInterpretation(); |
711 |
} |
712 |
|
713 |
/*
|
714 |
* (non-Javadoc)
|
715 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency()
|
716 |
*/
|
717 |
public DataStoreTransparency getTransparency() {
|
718 |
if(fileTransparency == null) |
719 |
fileTransparency = new DataStoreTransparency();
|
720 |
return fileTransparency;
|
721 |
} |
722 |
|
723 |
/**
|
724 |
* Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
|
725 |
* el valor de esta variable cada vez que dibuja.
|
726 |
* @return true si se ha supersampleado y false si no se ha hecho.
|
727 |
*/
|
728 |
public boolean isSupersampling() { |
729 |
return false; |
730 |
} |
731 |
|
732 |
/*
|
733 |
* (non-Javadoc)
|
734 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewCount(int)
|
735 |
*/
|
736 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
737 |
if(band >= getBandCount())
|
738 |
throw new BandAccessException("Wrong band"); |
739 |
return 0; |
740 |
} |
741 |
|
742 |
/*
|
743 |
* (non-Javadoc)
|
744 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewWidth(int, int)
|
745 |
*/
|
746 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
747 |
if (band >= getBandCount())
|
748 |
throw new BandAccessException("Wrong band"); |
749 |
return 0; |
750 |
} |
751 |
|
752 |
/*
|
753 |
* (non-Javadoc)
|
754 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewHeight(int, int)
|
755 |
*/
|
756 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
757 |
if (band >= getBandCount())
|
758 |
throw new BandAccessException("Wrong band"); |
759 |
return 0; |
760 |
} |
761 |
|
762 |
/*
|
763 |
* (non-Javadoc)
|
764 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isMultiFile()
|
765 |
*/
|
766 |
public boolean isMultiFile() { |
767 |
return true; |
768 |
} |
769 |
|
770 |
/*
|
771 |
* (non-Javadoc)
|
772 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isOverviewsSupported()
|
773 |
*/
|
774 |
public boolean isOverviewsSupported() { |
775 |
return true; |
776 |
} |
777 |
|
778 |
/*
|
779 |
* (non-Javadoc)
|
780 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isReproyectable()
|
781 |
*/
|
782 |
public boolean isReproyectable() { |
783 |
return true; |
784 |
} |
785 |
|
786 |
/*
|
787 |
* (non-Javadoc)
|
788 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getName()
|
789 |
*/
|
790 |
public String getName() { |
791 |
return NAME;
|
792 |
} |
793 |
|
794 |
/*
|
795 |
* (non-Javadoc)
|
796 |
* @see org.gvsig.raster.impl.provider.RasterProvider#setStatus(org.gvsig.raster.impl.provider.RasterProvider)
|
797 |
*/
|
798 |
public void setStatus(RasterProvider provider) { |
799 |
if(provider instanceof MultiFileProvider) { |
800 |
//Not implemented yet
|
801 |
} |
802 |
} |
803 |
|
804 |
/*
|
805 |
* (non-Javadoc)
|
806 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isTimeSupported()
|
807 |
*/
|
808 |
public boolean isTimeSupported() { |
809 |
return true; |
810 |
} |
811 |
|
812 |
/*
|
813 |
* (non-Javadoc)
|
814 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getURIByBand(int)
|
815 |
*/
|
816 |
public String getURIByBand(int band) { |
817 |
int[] sub = getSubBandByBandNumber(band); |
818 |
RasterProvider prov = providerList.get(sub[0]);
|
819 |
return prov.getURIOfFirstProvider();
|
820 |
} |
821 |
|
822 |
/*
|
823 |
* (non-Javadoc)
|
824 |
* @see org.gvsig.raster.impl.provider.RasterProvider#addFile(java.lang.String)
|
825 |
*/
|
826 |
public void addFile(String file) throws InvalidSourceException { |
827 |
/*try {
|
828 |
RasterProvider provider = loadProvider(file, storeServices);
|
829 |
if(checkNewProvider(provider)) {
|
830 |
getParameters().addProvider(provider);
|
831 |
} else {
|
832 |
provider.close();
|
833 |
}
|
834 |
} catch (ProviderNotRegisteredException e) {
|
835 |
throw new InvalidSourceException("Provider not registered", e);
|
836 |
} catch (InitializeException e) {
|
837 |
throw new InvalidSourceException("Initialize exception", e);
|
838 |
}*/
|
839 |
ProviderServices provServ = RasterLocator.getManager().getProviderServices(); |
840 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
841 |
|
842 |
ArrayList<RasterDataParameters> storeParametersList = provServ.createParametersList(file);
|
843 |
for (int j = 0; j < storeParametersList.size(); j++) { |
844 |
RasterProvider newFileProv; |
845 |
try {
|
846 |
newFileProv = (RasterProvider)dataManager.createProvider(storeServices, storeParametersList.get(j)); |
847 |
if(!newFileProv.isTiled() && checkNewProvider(newFileProv)) {
|
848 |
getParameters().addProvider(newFileProv); |
849 |
} |
850 |
} catch (InitializeException e) {
|
851 |
throw new InvalidSourceException("", e); |
852 |
} catch (ProviderNotRegisteredException e) {
|
853 |
throw new InvalidSourceException("", e); |
854 |
} |
855 |
} |
856 |
} |
857 |
|
858 |
/*
|
859 |
* (non-Javadoc)
|
860 |
* @see org.gvsig.raster.impl.provider.RasterProvider#removeFile(java.lang.String)
|
861 |
*/
|
862 |
public void removeFile(String file) { |
863 |
getParameters().removeProvider(file); |
864 |
} |
865 |
|
866 |
/*
|
867 |
* (non-Javadoc)
|
868 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getTileServer()
|
869 |
*/
|
870 |
public TileServer getTileServer() {
|
871 |
if(tileServer == null) |
872 |
tileServer = new FileTileServer(this); |
873 |
return tileServer;
|
874 |
} |
875 |
} |