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