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