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