Revision 2300
org.gvsig.raster.mosaic/trunk/org.gvsig.raster.mosaic/org.gvsig.raster.mosaic.app/src/main/java/org/gvsig/raster/mosaic/app/MainDialogActions.java | ||
---|---|---|
44 | 44 |
this.addFilesPanel = panel; |
45 | 45 |
} |
46 | 46 |
|
47 |
public void loadLayer() { |
|
48 |
RasterDataStore mainRasterStore = (RasterDataStore)addFilesPanel.getResult(); |
|
49 |
if(mainRasterStore == null) { |
|
50 |
return; |
|
51 |
} |
|
47 |
public void saveLayer() { |
|
48 |
RasterDataStore mainRasterStore = addFilesPanel.getResult(false); |
|
52 | 49 |
|
53 | 50 |
try { |
54 | 51 |
saveMosaicFileLayer(mainRasterStore); |
55 | 52 |
} catch (IOException e) { |
56 | 53 |
RasterSwingLibrary.messageBoxError(Messages.getText("error_saving_mosaic"), addFilesPanel, e); |
57 | 54 |
} |
58 |
|
|
59 |
try { |
|
60 |
loadLayerInView(mainRasterStore); |
|
61 |
} catch (LoadLayerException e) { |
|
62 |
RasterSwingLibrary.messageBoxError(Messages.getText("error_loading_layer"), addFilesPanel, e); |
|
63 |
} |
|
64 | 55 |
} |
65 | 56 |
|
66 | 57 |
/** |
... | ... | |
95 | 86 |
return null; |
96 | 87 |
} |
97 | 88 |
|
89 |
public void loadLayer() { |
|
90 |
RasterDataStore mainRasterStore = addFilesPanel.getResult(true); |
|
91 |
if(mainRasterStore == null) { |
|
92 |
return; |
|
93 |
} |
|
94 |
|
|
95 |
try { |
|
96 |
loadLayerInView(mainRasterStore); |
|
97 |
} catch (LoadLayerException e) { |
|
98 |
RasterSwingLibrary.messageBoxError(Messages.getText("error_loading_layer"), addFilesPanel, e); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
98 | 102 |
private void loadLayerInView(RasterDataStore mainRasterStore) throws LoadLayerException { |
99 | 103 |
MapContextManager mcm = MapContextLocator.getMapContextManager(); |
100 | 104 |
FLyrRaster lyr = (FLyrRaster) mcm.createLayer(file, mainRasterStore); |
... | ... | |
129 | 133 |
store.getBandCount(), |
130 | 134 |
store.getDataType()[0], |
131 | 135 |
store.getCellSize(), |
132 |
store.getNoDataValue().getValue().doubleValue());
|
|
136 |
store.getNoDataValue()); |
|
133 | 137 |
} catch (RasterDriverException e1) { |
134 | 138 |
log.debug("Error loading a RasterDataStore from the list", e1); |
135 | 139 |
} catch (InitializeException e1) { |
... | ... | |
156 | 160 |
store.getBandCount(), |
157 | 161 |
store.getDataType()[0], |
158 | 162 |
store.getCellSize(), |
159 |
store.getNoDataValue().getValue().doubleValue());
|
|
163 |
store.getNoDataValue()); |
|
160 | 164 |
} catch (RasterDriverException e1) { |
161 | 165 |
log.debug("Error loading a RasterDataStore from the list", e1); |
162 | 166 |
} catch (InitializeException e1) { |
org.gvsig.raster.mosaic/trunk/org.gvsig.raster.mosaic/org.gvsig.raster.mosaic.app/src/main/java/org/gvsig/raster/mosaic/app/MosaicSupportExtension.java | ||
---|---|---|
106 | 106 |
} |
107 | 107 |
|
108 | 108 |
public void actionPerformed(ActionEvent e) { |
109 |
//Cargar cuadro de a?adir ficheros |
|
109 | 110 |
if(e.getSource() == layerNamewindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT)) { |
110 | 111 |
String[] suffixList = RasterLocator.getManager().getProviderServices().getReadOnlyFormatList(); |
111 | 112 |
String file = getNewLayerPanel().getFileSelected(); |
... | ... | |
121 | 122 |
PluginServices.getMDIManager().addCentredWindow(addFilesWindow); |
122 | 123 |
} |
123 | 124 |
|
125 |
//Cargar capa |
|
124 | 126 |
if(e.getSource() == addFilesWindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR1)) { |
125 | 127 |
actions.loadLayer(); |
126 | 128 |
} |
127 | 129 |
|
130 |
//Salvar capa a disco |
|
128 | 131 |
if(e.getSource() == addFilesWindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR2)) { |
132 |
actions.saveLayer(); |
|
129 | 133 |
} |
130 | 134 |
} |
131 | 135 |
|
... | ... | |
141 | 145 |
lyrRaster.getDataStore().getBandCount(), |
142 | 146 |
lyrRaster.getDataStore().getDataType()[0], |
143 | 147 |
lyrRaster.getDataStore().getCellSize(), |
144 |
lyrRaster.getNoDataValue().getValue().doubleValue());
|
|
148 |
lyrRaster.getNoDataValue()); |
|
145 | 149 |
} |
146 | 150 |
} |
147 | 151 |
} |
org.gvsig.raster.mosaic/trunk/org.gvsig.raster.mosaic/org.gvsig.raster.mosaic.io/src/main/java/org/gvsig/raster/mosaic/io/MosaicProvider_old.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.mosaic.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.security.MessageDigest; |
|
30 |
import java.security.NoSuchAlgorithmException; |
|
31 |
import java.util.ArrayList; |
|
32 |
import java.util.Date; |
|
33 |
import java.util.HashMap; |
|
34 |
import java.util.List; |
|
35 |
|
|
36 |
import org.cresques.cts.IProjection; |
|
37 |
import org.gvsig.compat.net.ICancellable; |
|
38 |
import org.gvsig.fmap.dal.DALFileLocator; |
|
39 |
import org.gvsig.fmap.dal.DALLocator; |
|
40 |
import org.gvsig.fmap.dal.DataStore; |
|
41 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
42 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
43 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
44 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
45 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
|
46 |
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand; |
|
47 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
48 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
49 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
|
50 |
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException; |
|
51 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
52 |
import org.gvsig.fmap.dal.coverage.exception.FileNotSupportedException; |
|
53 |
import org.gvsig.fmap.dal.coverage.exception.HistogramException; |
|
54 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
55 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
56 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
|
57 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
58 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
59 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
|
60 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
61 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
|
62 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
|
63 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
|
64 |
import org.gvsig.fmap.dal.coverage.store.props.TimeSeries; |
|
65 |
import org.gvsig.fmap.dal.coverage.util.MathUtils; |
|
66 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
|
67 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
68 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
69 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
70 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
71 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
72 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
73 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
74 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
75 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
|
76 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
77 |
import org.gvsig.metadata.MetadataLocator; |
|
78 |
import org.gvsig.raster.cache.tile.Tile; |
|
79 |
import org.gvsig.raster.cache.tile.TileCache; |
|
80 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
|
81 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
|
82 |
import org.gvsig.raster.cache.tile.TileCacheManager; |
|
83 |
import org.gvsig.raster.cache.tile.exception.TileBuildException; |
|
84 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
|
85 |
import org.gvsig.raster.cache.tile.layer.TiledLayer; |
|
86 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
|
87 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
|
88 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
89 |
import org.gvsig.raster.impl.datastruct.BandListImpl; |
|
90 |
import org.gvsig.raster.impl.datastruct.DatasetBandImpl; |
|
91 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
92 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
|
93 |
import org.gvsig.raster.impl.provider.MemoryTileMatrixBuffer; |
|
94 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
95 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
|
96 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
|
97 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
|
98 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
|
99 |
import org.gvsig.raster.impl.store.properties.SimpleProviderHistogramComputer; |
|
100 |
import org.gvsig.raster.impl.store.properties.SimpleProviderStatistics; |
|
101 |
import org.gvsig.raster.mosaic.io.downloader.MosaicTileServer; |
|
102 |
import org.gvsig.timesupport.RelativeInstant; |
|
103 |
import org.gvsig.timesupport.Time; |
|
104 |
import org.gvsig.timesupport.TimeSupportLocator; |
|
105 |
import org.gvsig.tools.ToolsLocator; |
|
106 |
import org.gvsig.tools.task.TaskStatus; |
|
107 |
import org.slf4j.Logger; |
|
108 |
import org.slf4j.LoggerFactory; |
|
109 |
/** |
|
110 |
* Data provider for raster mosaics |
|
111 |
* |
|
112 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
113 |
*/ |
|
114 |
@SuppressWarnings("deprecation") |
|
115 |
public class MosaicProvider_old extends DefaultRasterProvider { |
|
116 |
public static String NAME = "Mosaic Raster"; |
|
117 |
public static String DESCRIPTION = "Mosaic Raster Support"; |
|
118 |
public final String METADATA_DEFINITION_NAME = NAME; |
|
119 |
private static final Logger logger = LoggerFactory.getLogger(MosaicProvider.class); |
|
120 |
private boolean open = false; |
|
121 |
private RasterUtils util = RasterLocator.getManager().getRasterUtils(); |
|
122 |
private MathUtils math = RasterLocator.getManager().getMathUtils(); |
|
123 |
protected static String[] formatList = null; |
|
124 |
//private MosaicRasterFormat mosaicRasterFormat = null; |
|
125 |
private List<RasterProvider> providerList = null; |
|
126 |
private double pixelSize = 0D; |
|
127 |
private Extent extent = null; |
|
128 |
private double width = 0; |
|
129 |
private double height = 0; |
|
130 |
private Extent viewRequest = null; |
|
131 |
private TiledLayer tiledLayer = null; |
|
132 |
//This provider needs a MosaicTileServer by set of layers |
|
133 |
private HashMap<String, MosaicTileServer> |
|
134 |
tileServerMap = new HashMap<String, MosaicTileServer>(); |
|
135 |
private ArrayList<RasterProvider> selectedProviders = new ArrayList<RasterProvider>(); |
|
136 |
|
|
137 |
public static void register() { |
|
138 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
139 |
registerFormats(); |
|
140 |
|
|
141 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
|
142 |
dataman.registerStoreProvider(NAME, |
|
143 |
MosaicProvider.class, MosaicDataParametersImpl.class); |
|
144 |
} |
|
145 |
|
|
146 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
|
147 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
|
148 |
NAME, DESCRIPTION, |
|
149 |
MosaicServerExplorer.class); |
|
150 |
|
|
151 |
if (!dataman.getExplorerProviders().contains(NAME)) { |
|
152 |
dataman.registerExplorerProvider(NAME, MosaicServerExplorer.class, MosaicServerExplorerParameters.class); |
|
153 |
} |
|
154 |
|
|
155 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
|
156 |
} |
|
157 |
|
|
158 |
private static void registerFormats() { |
|
159 |
formatList = new String[] {"mrf"}; |
|
160 |
for (int i = 0; i < formatList.length; i++) |
|
161 |
RasterLocator.getManager().addFormat(formatList[i], MosaicProvider.class); |
|
162 |
} |
|
163 |
|
|
164 |
public String[] getFormatList() { |
|
165 |
return formatList; |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* Returns true if the extension is supported and false if doesn't |
|
170 |
* @param ext |
|
171 |
* @return |
|
172 |
*/ |
|
173 |
public boolean isExtensionSupported(String ext) { |
|
174 |
if(ext.indexOf(".") != -1) |
|
175 |
ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length()); |
|
176 |
for (int i = 0; i < formatList.length; i++) { |
|
177 |
if(formatList[i].compareTo(ext) == 0) |
|
178 |
return true; |
|
179 |
} |
|
180 |
return false; |
|
181 |
} |
|
182 |
|
|
183 |
public MosaicProvider_old() { |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* Opens the dataset. |
|
188 |
* @param proj Projection |
|
189 |
* @param fName File name |
|
190 |
* @throws NotSupportedExtensionException |
|
191 |
*/ |
|
192 |
public MosaicProvider_old(String params) throws NotSupportedExtensionException, OpenException { |
|
193 |
super(params); |
|
194 |
if(params instanceof String) { |
|
195 |
MosaicDataParametersImpl p = new MosaicDataParametersImpl(); |
|
196 |
p.setURI((String)params); |
|
197 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
|
198 |
.createDynObject( |
|
199 |
MetadataLocator.getMetadataManager().getDefinition( |
|
200 |
DataStore.METADATA_DEFINITION_NAME))); |
|
201 |
init(p, null); |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
public MosaicProvider_old (MosaicDataParametersImpl params, |
|
206 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
207 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
|
208 |
.createDynObject( |
|
209 |
MetadataLocator.getMetadataManager().getDefinition( |
|
210 |
DataStore.METADATA_DEFINITION_NAME))); |
|
211 |
init(params, storeServices); |
|
212 |
} |
|
213 |
|
|
214 |
/** |
|
215 |
* Build file references |
|
216 |
* @param proj Projection |
|
217 |
* @param param Load parameters |
|
218 |
* @throws NotSupportedExtensionException |
|
219 |
*/ |
|
220 |
public void init (AbstractRasterDataParameters params, |
|
221 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
222 |
setParam(storeServices, params); |
|
223 |
|
|
224 |
openFromMrf(); |
|
225 |
|
|
226 |
calcMetadataFromParams(); |
|
227 |
|
|
228 |
super.init(); |
|
229 |
|
|
230 |
try { |
|
231 |
loadFromRmf(getRmfBlocksManager()); |
|
232 |
} catch (ParsingException e) { |
|
233 |
//No lee desde rmf |
|
234 |
} |
|
235 |
|
|
236 |
open = true; |
|
237 |
} |
|
238 |
|
|
239 |
/** |
|
240 |
* Calculates metadata using the parameters |
|
241 |
*/ |
|
242 |
private void calcMetadataFromParams() { |
|
243 |
uri = getParameters().getURI(); |
|
244 |
providerList = getParameters().getProviders(); |
|
245 |
pixelSize = getParameters().getPixelSize(); |
|
246 |
setColorInterpretation(providerList.get(0).getColorInterpretation().cloneColorInterpretation()); |
|
247 |
|
|
248 |
//Se le pone banda de transparencia siempre |
|
249 |
if(providerList.get(0).getDataType()[0] == Buffer.TYPE_BYTE) { |
|
250 |
transparency = new DataStoreTransparency(); |
|
251 |
transparency.setTransparencyBand(getBandCount() - 1); |
|
252 |
} else |
|
253 |
transparency = providerList.get(0).getTransparency(); |
|
254 |
|
|
255 |
extent = null; |
|
256 |
for (int i = 0; i < providerList.size(); i++) { |
|
257 |
if(extent == null) |
|
258 |
extent = providerList.get(i).getExtent(); |
|
259 |
else |
|
260 |
extent = extent.encloseBoundinBoxes(providerList.get(i).getExtent()); |
|
261 |
|
|
262 |
//Usa el primer NoData de la primera imagen que tenga un valor asignado |
|
263 |
if(noData == null && providerList.get(i).getNoDataValue().isDefined()) { |
|
264 |
noData = providerList.get(i).getNoDataValue(); |
|
265 |
noData.setFileName(getParameters().getURI()); |
|
266 |
} |
|
267 |
} |
|
268 |
width = extent.width() / pixelSize; |
|
269 |
height = extent.height() / pixelSize; |
|
270 |
|
|
271 |
ownTransformation = new AffineTransform(pixelSize, 0, |
|
272 |
0, -pixelSize, |
|
273 |
extent.getULX(), extent.getULY()); |
|
274 |
externalTransformation = (AffineTransform) ownTransformation.clone(); |
|
275 |
|
|
276 |
((MosaicDataParametersImpl)getParameters()).resetParamsChanged(); |
|
277 |
} |
|
278 |
|
|
279 |
/** |
|
280 |
* Loads the specific provider |
|
281 |
* @param file |
|
282 |
* @return |
|
283 |
* @throws NotSupportedExtensionException |
|
284 |
* @throws FileNotSupportedException |
|
285 |
*/ |
|
286 |
@SuppressWarnings("unchecked") |
|
287 |
private RasterProvider loadProvider(String file, DataStoreProviderServices storeServices) throws ProviderNotRegisteredException, InitializeException { |
|
288 |
DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager(); |
|
289 |
DataStoreProvider prov = null; |
|
290 |
|
|
291 |
if(file != null) { |
|
292 |
//We have to locate a provider's name which manages the selected file |
|
293 |
//A FilesystemServerExplorer will give a getProviderNames service |
|
294 |
FilesystemServerExplorerParameters paramsExplorer = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
|
295 |
FilesystemServerExplorer serverExplorer = null; |
|
296 |
try { |
|
297 |
paramsExplorer.setRoot(File.separator); |
|
298 |
serverExplorer = (FilesystemServerExplorer)dataManager.openServerExplorer(FilesystemServerExplorer.NAME, paramsExplorer); |
|
299 |
} catch (ValidateDataParametersException e) { |
|
300 |
throw new InitializeException(e); |
|
301 |
} |
|
302 |
File f = new File(file); |
|
303 |
//Gets the list of provider's name to manage the file |
|
304 |
List<String> provName = serverExplorer.getProviderNameList(f); |
|
305 |
if(provName.size() > 0) { |
|
306 |
for (int i = 0; i < provName.size(); i++) { |
|
307 |
//Gets the first provider what is not a TileProvider |
|
308 |
if(provName.get(i).compareTo("Tile Store") != 0) { |
|
309 |
DataStoreParameters newparams = dataManager.createStoreParameters(provName.get(i)); |
|
310 |
((FilesystemStoreParameters)newparams).setFile(f); |
|
311 |
prov = dataManager.createProvider(storeServices, newparams); |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
|
|
317 |
if(prov != null && prov instanceof RasterProvider) { |
|
318 |
if(((RasterProvider)prov).isRotated()) |
|
319 |
throw new InitializeException("Rotation not supported tiling files", new Throwable()); |
|
320 |
|
|
321 |
return (RasterProvider)prov; |
|
322 |
} |
|
323 |
|
|
324 |
return null; |
|
325 |
} |
|
326 |
|
|
327 |
/** |
|
328 |
* Open from a .mrf file. |
|
329 |
* This method loads all providers and adds these to the parameters |
|
330 |
* @throws OpenException |
|
331 |
*/ |
|
332 |
private void openFromMrf() throws OpenException { |
|
333 |
if(getParameters().getURI() != null && new File(getParameters().getURI()).exists()) { |
|
334 |
try { |
|
335 |
if(getParameters().getProviders() != null) |
|
336 |
getParameters().getProviders().clear(); |
|
337 |
MosaicRasterFormat multiFileFormat = new MosaicRasterFormat(); |
|
338 |
multiFileFormat = MosaicRasterFormatSerializer.read(multiFileFormat, getParameters().getURI()); |
|
339 |
for (int i = 0; i < multiFileFormat.getNumberOfFiles(); i++) { |
|
340 |
try { |
|
341 |
File file = new File(multiFileFormat.getPathToFile(i)); |
|
342 |
if(file.exists()) { |
|
343 |
RasterProvider prov = loadProvider(multiFileFormat.getPathToFile(i), storeServices); |
|
344 |
if(i == 0) |
|
345 |
getParameters().setPixelSize(prov.getCellSize()); |
|
346 |
getParameters().addProvider(prov); |
|
347 |
} |
|
348 |
} catch (ProviderNotRegisteredException e) { |
|
349 |
throw new OpenException("A provider can't be loaded", e); |
|
350 |
} catch (InitializeException e) { |
|
351 |
throw new OpenException("A provider can't be initialized", e); |
|
352 |
} |
|
353 |
} |
|
354 |
} catch (IOException e1) { |
|
355 |
throw new OpenException("File .mrf can't be read", e1); |
|
356 |
} catch (ParsingException e1) { |
|
357 |
throw new OpenException("File .mrf can't be parsed", e1); |
|
358 |
} |
|
359 |
} |
|
360 |
} |
|
361 |
|
|
362 |
public RasterProvider load() { |
|
363 |
return this; |
|
364 |
} |
|
365 |
|
|
366 |
/** |
|
367 |
* Gets the MosaicDataParameters |
|
368 |
* @return |
|
369 |
*/ |
|
370 |
public MosaicDataParameters getParameters() { |
|
371 |
try { |
|
372 |
return (MosaicDataParameters)parameters; |
|
373 |
} catch (ClassCastException e) { |
|
374 |
return null; |
|
375 |
} |
|
376 |
} |
|
377 |
|
|
378 |
public boolean isOpen() { |
|
379 |
return open; |
|
380 |
} |
|
381 |
|
|
382 |
public void close() { |
|
383 |
for (int i = 0; i < providerList.size(); i++) { |
|
384 |
providerList.get(i).close(); |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
/** |
|
389 |
* @return Returns the dataType. |
|
390 |
*/ |
|
391 |
public int[] getDataType() { |
|
392 |
if(providerList.get(0).getDataType()[0] == Buffer.TYPE_BYTE) { |
|
393 |
int[] dt = new int[getBandCount()]; |
|
394 |
for (int i = 0; i < providerList.get(0).getDataType().length; i++) { |
|
395 |
dt[i] = providerList.get(0).getDataType()[i]; |
|
396 |
} |
|
397 |
dt[getBandCount() - 1] = Buffer.TYPE_BYTE; |
|
398 |
return dt; |
|
399 |
} |
|
400 |
return providerList.get(0).getDataType(); |
|
401 |
} |
|
402 |
|
|
403 |
/** |
|
404 |
* Gets the number of bands |
|
405 |
* @return |
|
406 |
*/ |
|
407 |
public int getBandCount() { |
|
408 |
if(providerList.get(0).getDataType()[0] == Buffer.TYPE_BYTE) |
|
409 |
return providerList.get(0).getBandCount() + 1; |
|
410 |
return providerList.get(0).getBandCount(); |
|
411 |
} |
|
412 |
|
|
413 |
public String[] getURIByProvider() { |
|
414 |
providerList = getParameters().getProviders(); |
|
415 |
String[] uris = new String[providerList.size()]; |
|
416 |
for (int i = 0; i < uris.length; i++) { |
|
417 |
uris[i] = providerList.get(i).getURI(); |
|
418 |
} |
|
419 |
return uris; |
|
420 |
} |
|
421 |
|
|
422 |
public int[] getBandCountByProvider() { |
|
423 |
int[] n = new int[providerList.size()]; |
|
424 |
for (int i = 0; i < providerList.size(); i++) { |
|
425 |
n[i] = providerList.get(i).getBandCount(); |
|
426 |
} |
|
427 |
return n; |
|
428 |
} |
|
429 |
|
|
430 |
public BandList getDefaultBandList() { |
|
431 |
BandList bandList = new BandListImpl(); |
|
432 |
int[] nBandsByProvider = getBandCountByProvider(); |
|
433 |
int nBands = 0; |
|
434 |
for (int i = 0; i < nBandsByProvider.length; i++) { |
|
435 |
nBands = Math.max(nBandsByProvider[i], nBands); |
|
436 |
} |
|
437 |
|
|
438 |
for (int iBand = 0; iBand < nBands; iBand++) { |
|
439 |
try { |
|
440 |
bandList.addBand(new DatasetBandImpl(getURI(), iBand, getDataType()[0], nBands)); |
|
441 |
} catch (BandNotFoundInListException e1) { |
|
442 |
} |
|
443 |
} |
|
444 |
|
|
445 |
int[] drawableBands = new int[bandList.getBandCount()]; |
|
446 |
for (int i = 0; i < bandList.getBandCount(); i++) { |
|
447 |
drawableBands[i] = i; |
|
448 |
} |
|
449 |
|
|
450 |
bandList.setDrawableBands(drawableBands); |
|
451 |
return bandList; |
|
452 |
} |
|
453 |
|
|
454 |
public String getURIByBand(int band) { |
|
455 |
//No matter which band be selected. In providers with one file is always the first URI |
|
456 |
return getURI(); |
|
457 |
} |
|
458 |
|
|
459 |
public double getPixelSizeX() { |
|
460 |
if(getParameters().hasParamsChanged()) |
|
461 |
calcMetadataFromParams(); |
|
462 |
return pixelSize; |
|
463 |
} |
|
464 |
|
|
465 |
public double getPixelSizeY() { |
|
466 |
if(getParameters().hasParamsChanged()) |
|
467 |
calcMetadataFromParams(); |
|
468 |
return pixelSize; |
|
469 |
} |
|
470 |
|
|
471 |
public NoData getNoDataValue() { |
|
472 |
if(getParameters().hasParamsChanged()) |
|
473 |
calcMetadataFromParams(); |
|
474 |
return noData; |
|
475 |
} |
|
476 |
|
|
477 |
public Extent getExtent() { |
|
478 |
if(getParameters().hasParamsChanged()) |
|
479 |
calcMetadataFromParams(); |
|
480 |
return extent; |
|
481 |
} |
|
482 |
|
|
483 |
public double getCellSize() { |
|
484 |
return pixelSize; |
|
485 |
} |
|
486 |
|
|
487 |
public Statistics getStatistics() { |
|
488 |
if(stats == null || getParameters().hasParamsChanged()) { |
|
489 |
//First of all read the statistics in the rmf. If these have not been calculated then |
|
490 |
//we'll read the statistics from simple files |
|
491 |
stats = super.getStatistics(); |
|
492 |
try { |
|
493 |
loadObjectFromRmf(SimpleProviderStatistics.class, stats); |
|
494 |
} catch (RmfSerializerException e) { |
|
495 |
// Si no se puede cargar del RMF, recalcularemos las estadisticas. |
|
496 |
} |
|
497 |
if(!stats.isCalculated()) { |
|
498 |
calcMetadataFromParams(); |
|
499 |
providerList = getParameters().getProviders(); |
|
500 |
stats = SimpleProviderStatistics.union(this, providerList); |
|
501 |
} |
|
502 |
} |
|
503 |
return stats; |
|
504 |
} |
|
505 |
|
|
506 |
public HistogramComputer getHistogramComputer() { |
|
507 |
if(histogram == null || getParameters().hasParamsChanged()) { |
|
508 |
calcMetadataFromParams(); |
|
509 |
providerList = getParameters().getProviders(); |
|
510 |
try { |
|
511 |
histogram = SimpleProviderHistogramComputer.union(this, providerList); |
|
512 |
} catch (HistogramException e) { |
|
513 |
return null; |
|
514 |
} catch (InterruptedException e) { |
|
515 |
return null; |
|
516 |
} |
|
517 |
} |
|
518 |
return histogram; |
|
519 |
} |
|
520 |
|
|
521 |
public String getURIOfFirstProvider() { |
|
522 |
return providerList.get(0).getURIOfFirstProvider(); |
|
523 |
} |
|
524 |
|
|
525 |
public long getFileSize() { |
|
526 |
if(getParameters().hasParamsChanged()) |
|
527 |
calcMetadataFromParams(); |
|
528 |
long sizeMosaic = 0; |
|
529 |
for (int i = 0; i < providerList.size(); i++) { |
|
530 |
long[] fs = providerList.get(i).getFileSizeByProvider(); |
|
531 |
for (int j = 0; j < fs.length; j++) { |
|
532 |
sizeMosaic += fs[j]; |
|
533 |
} |
|
534 |
} |
|
535 |
return sizeMosaic; |
|
536 |
} |
|
537 |
|
|
538 |
public IProjection getProjection() { |
|
539 |
return proj; |
|
540 |
} |
|
541 |
|
|
542 |
public void setProjection(IProjection p) { |
|
543 |
} |
|
544 |
|
|
545 |
public String getInfoByPoint(double x, double y, ICancellable cancellable) { |
|
546 |
return null; |
|
547 |
} |
|
548 |
|
|
549 |
public int[] getTileSize(int level) { |
|
550 |
return null; |
|
551 |
} |
|
552 |
|
|
553 |
public int getSourceType() { |
|
554 |
return RasterDataStore.MOSAIC; |
|
555 |
} |
|
556 |
|
|
557 |
public String translateFileName(String fileName) { |
|
558 |
return fileName; |
|
559 |
} |
|
560 |
|
|
561 |
public void setView(Extent e) { |
|
562 |
viewRequest = new ExtentImpl(e); |
|
563 |
} |
|
564 |
|
|
565 |
public Extent getView() { |
|
566 |
return viewRequest; |
|
567 |
} |
|
568 |
|
|
569 |
public double getWidth() { |
|
570 |
if(getParameters().hasParamsChanged()) |
|
571 |
calcMetadataFromParams(); |
|
572 |
return width; |
|
573 |
} |
|
574 |
|
|
575 |
public double getHeight() { |
|
576 |
if(getParameters().hasParamsChanged()) |
|
577 |
calcMetadataFromParams(); |
|
578 |
return height; |
|
579 |
} |
|
580 |
|
|
581 |
public Object readBlock(int pos, int blockHeight, double scale) |
|
582 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException { |
|
583 |
if(getParameters().hasParamsChanged()) |
|
584 |
calcMetadataFromParams(); |
|
585 |
blockHeight = pos + blockHeight > getHeight() ? (int)(getHeight() - pos) : blockHeight; |
|
586 |
Buffer buf = RasterLocator.getManager().createBuffer(getDataType()[0], (int)getWidth(), blockHeight, getBandCount(), true); |
|
587 |
BandList bandList = new BandListImpl(); |
|
588 |
bandList.clear(); |
|
589 |
int[] drawableBands = new int[getBandCount()]; |
|
590 |
for(int i = 0; i < getBandCount(); i++) { |
|
591 |
try { |
|
592 |
int dataType = getDataType()[i]; |
|
593 |
DatasetBand band = new DatasetBandImpl(getURIByBand(i), |
|
594 |
getBandPositionByProvider(i), |
|
595 |
dataType, |
|
596 |
getBandCount()); |
|
597 |
bandList.addBand(band, i); |
|
598 |
drawableBands[i] = i; |
|
599 |
} catch(BandNotFoundInListException ex) { |
|
600 |
//No a�adimos la banda |
|
601 |
} |
|
602 |
} |
|
603 |
bandList.setDrawableBands(drawableBands); |
|
604 |
return getWindow(0, pos, bandList, buf); |
|
605 |
} |
|
606 |
|
|
607 |
public Object getData(int x, int y, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
608 |
if(getParameters().hasParamsChanged()) |
|
609 |
calcMetadataFromParams(); |
|
610 |
return null; |
|
611 |
} |
|
612 |
|
|
613 |
public void getWindow(Extent ex, int bufWidth, int bufHeight, |
|
614 |
BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
615 |
if(getParameters().hasParamsChanged()) |
|
616 |
calcMetadataFromParams(); |
|
617 |
setView(extent); |
|
618 |
String layerName = getLayerNameFromSelection(getParameters().getTimeSelection()); |
|
619 |
List<Tile> tileList = null; |
|
620 |
try { |
|
621 |
tileList = getTileList(extent, bandList, bufWidth, bufHeight, layerName); |
|
622 |
tiledLayer.getTiles(tileList, listener, status); |
|
623 |
} catch (TileGettingException e) { |
|
624 |
throw new RasterDriverException("Error getting the tile list", e); |
|
625 |
} catch (TileBuildException e) { |
|
626 |
throw new RasterDriverException("Error building the tile list", e); |
|
627 |
} |
|
628 |
} |
|
629 |
|
|
630 |
public Buffer getWindow(Extent extent, BandList bandList, Buffer rasterBuf, TaskStatus status) |
|
631 |
throws ProcessInterruptedException, RasterDriverException { |
|
632 |
if(getParameters().hasParamsChanged()) |
|
633 |
calcMetadataFromParams(); |
|
634 |
setView(extent); |
|
635 |
String layerName = getLayerNameFromSelection(getParameters().getTimeSelection()); |
|
636 |
List<Tile> tileList = null; |
|
637 |
try { |
|
638 |
tileList = getTileList(extent, bandList, rasterBuf.getWidth(), rasterBuf.getHeight(), layerName); |
|
639 |
for (int i = 0; i < tileList.size(); i++) { |
|
640 |
tiledLayer.getTile(tileList.get(i)); |
|
641 |
} |
|
642 |
} catch (TileGettingException e) { |
|
643 |
throw new RasterDriverException("Error getting the tile list", e); |
|
644 |
} catch (TileBuildException e) { |
|
645 |
throw new RasterDriverException("Error building the tile list", e); |
|
646 |
} |
|
647 |
MemoryTileMatrixBuffer matrixBuffer = new MemoryTileMatrixBuffer(tileList); |
|
648 |
|
|
649 |
if( tileList.get(0).getData().length > 1 && |
|
650 |
getDataType()[0] == Buffer.TYPE_BYTE && |
|
651 |
rasterBuf.getBandCount() == 1 && |
|
652 |
bandList.getDrawableBands()[0] == getBandCount()) |
|
653 |
return matrixBuffer.getWindow(extent, rasterBuf, true); |
|
654 |
else |
|
655 |
return matrixBuffer.getWindow(extent, rasterBuf, false); |
|
656 |
} |
|
657 |
|
|
658 |
public Buffer getWindow(double ulx, double uly, double w, double h, |
|
659 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
660 |
//cut image |
|
661 |
if(getParameters().hasParamsChanged()) |
|
662 |
calcMetadataFromParams(); |
|
663 |
Extent ext = getExtent(); |
|
664 |
Point2D pInit = rasterToWorld(new Point2D.Double(0, 0)); |
|
665 |
Point2D pEnd = rasterToWorld(new Point2D.Double(getWidth(), getHeight())); |
|
666 |
double wRaster = Math.abs(pEnd.getX() - pInit.getX()); |
|
667 |
double hRaster = Math.abs(pEnd.getY() - pInit.getY()); |
|
668 |
double lrx = (((ext.getULX() - wRaster) > ext.maxX()) || ((ext.getULX() - wRaster) < ext.minX())) ? (ulx + w) : (ulx - w); |
|
669 |
double lry = (((ext.getULY() - hRaster) > ext.maxY()) || ((ext.getULY() - hRaster) < ext.minY())) ? (uly + h) : (uly - h); |
|
670 |
|
|
671 |
Extent selectedExtent = new ExtentImpl(ulx, uly, lrx, lry); |
|
672 |
setView(selectedExtent); |
|
673 |
return getWindow(selectedExtent, |
|
674 |
rasterBuf.getWidth(), rasterBuf.getHeight(), bandList, rasterBuf, false, status); |
|
675 |
} |
|
676 |
|
|
677 |
public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
|
678 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
679 |
//draw method |
|
680 |
if(getParameters().hasParamsChanged()) |
|
681 |
calcMetadataFromParams(); |
|
682 |
setView(extent); |
|
683 |
String layerName = getLayerNameFromSelection(getParameters().getTimeSelection()); |
|
684 |
List<Tile> tileList = null; |
|
685 |
try { |
|
686 |
tileList = getTileList(extent, bandList, bufWidth, bufHeight, layerName); |
|
687 |
for (int i = 0; i < tileList.size(); i++) { |
|
688 |
tiledLayer.getTile(tileList.get(i)); |
|
689 |
} |
|
690 |
} catch (TileGettingException e) { |
|
691 |
throw new RasterDriverException("Error getting the tile list", e); |
|
692 |
} catch (TileBuildException e) { |
|
693 |
throw new RasterDriverException("Error building the tile list", e); |
|
694 |
} |
|
695 |
MemoryTileMatrixBuffer matrixBuffer = new MemoryTileMatrixBuffer(tileList); |
|
696 |
|
|
697 |
if( tileList.get(0).getData().length > 1 && |
|
698 |
getDataType()[0] == Buffer.TYPE_BYTE && |
|
699 |
rasterBuf.getBandCount() == 1 && |
|
700 |
bandList.getDrawableBands()[0] == getBandCount()) |
|
701 |
return matrixBuffer.getWindow(extent, rasterBuf, true); |
|
702 |
else |
|
703 |
return matrixBuffer.getWindow(extent, rasterBuf, false); |
|
704 |
} |
|
705 |
|
|
706 |
public Buffer getWindow(int x, int y, |
|
707 |
BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException { |
|
708 |
//Layer with real resolution |
|
709 |
if(getParameters().hasParamsChanged()) |
|
710 |
calcMetadataFromParams(); |
|
711 |
int w = rasterBuf.getWidth(); |
|
712 |
int h = rasterBuf.getHeight(); |
|
713 |
Rectangle2D r = new Rectangle2D.Double(x, y, w, h); |
|
714 |
setView( |
|
715 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(), |
|
716 |
getWidth(), |
|
717 |
getHeight(), |
|
718 |
r)) |
|
719 |
); |
|
720 |
String layerName = getLayerNameFromSelection(getParameters().getTimeSelection()); |
|
721 |
|
|
722 |
CacheStruct struct = getTileServer(layerName).getStruct(); |
|
723 |
|
|
724 |
createTiledLayer(layerName); //Creates a new layer when the file type changes |
|
725 |
|
|
726 |
List<Tile> tileList = struct.getTileList(r); |
|
727 |
|
|
728 |
for (int i = 0; i < tileList.size(); i++) { |
|
729 |
tileList.get(i).setDownloaderParams("BandList", bandList.clone()); |
|
730 |
} |
|
731 |
|
|
732 |
try { |
|
733 |
for (int i = 0; i < tileList.size(); i++) { |
|
734 |
tiledLayer.getTile(tileList.get(i)); |
|
735 |
} |
|
736 |
} catch (TileGettingException e) { |
|
737 |
throw new RasterDriverException("Error getting the tile list", e); |
|
738 |
} |
|
739 |
|
|
740 |
MemoryTileMatrixBuffer matrixBuffer = new MemoryTileMatrixBuffer(tileList); |
|
741 |
return matrixBuffer.getWindow(r, rasterBuf); |
|
742 |
} |
|
743 |
|
|
744 |
public Buffer getWindow(int x, int y, int w, int h, |
|
745 |
BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
746 |
if(rasterBuf.getWidth() == w && rasterBuf.getHeight() == h) |
|
747 |
return getWindow(x, y, bandList, rasterBuf); |
|
748 |
|
|
749 |
if(getParameters().hasParamsChanged()) |
|
750 |
calcMetadataFromParams(); |
|
751 |
setView( |
|
752 |
new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(), |
|
753 |
getWidth(), |
|
754 |
getHeight(), |
|
755 |
new Rectangle2D.Double(x, y, w, h))) |
|
756 |
); |
|
757 |
return null; |
|
758 |
} |
|
759 |
|
|
760 |
public int getBlockSize() { |
|
761 |
return 0; |
|
762 |
} |
|
763 |
|
|
764 |
public boolean isTiled() { |
|
765 |
return false; |
|
766 |
} |
|
767 |
|
|
768 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
|
769 |
return 0; |
|
770 |
} |
|
771 |
|
|
772 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
|
773 |
return 0; |
|
774 |
} |
|
775 |
|
|
776 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
|
777 |
return 0; |
|
778 |
} |
|
779 |
|
|
780 |
public boolean isOverviewsSupported() { |
|
781 |
return false; |
|
782 |
} |
|
783 |
|
|
784 |
public boolean isReproyectable() { |
|
785 |
return false; |
|
786 |
} |
|
787 |
|
|
788 |
public String getName() { |
|
789 |
return NAME; |
|
790 |
} |
|
791 |
|
|
792 |
public void setStatus(RasterProvider provider) { |
|
793 |
if(provider instanceof MosaicProvider) { |
|
794 |
} |
|
795 |
} |
|
796 |
|
|
797 |
public boolean isTimeSupported() { |
|
798 |
return true; |
|
799 |
} |
|
800 |
|
|
801 |
public boolean isMosaic() { |
|
802 |
return true; |
|
803 |
} |
|
804 |
|
|
805 |
public void deleteLayerFromCache() { |
|
806 |
String layerName = getLayerNameFromSelection(null); |
|
807 |
TileCacheManager manager = TileCacheLocator.getManager(); |
|
808 |
TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache); |
|
809 |
TiledLayer newLayer = tileCache.createLayer(getTileServer(layerName), TileCacheLibrary.DEFAULT_STRUCTURE); |
|
810 |
tileCache.removeLayer(newLayer); |
|
811 |
} |
|
812 |
|
|
813 |
/** |
|
814 |
* Gets the layer name using the time selection and visibility |
|
815 |
* @param t |
|
816 |
* @return |
|
817 |
*/ |
|
818 |
private String getLayerNameFromSelection(Time t) { |
|
819 |
String name = ""; |
|
820 |
|
|
821 |
MessageDigest md = null; |
|
822 |
try { |
|
823 |
md = java.security.MessageDigest.getInstance("MD5"); |
|
824 |
} catch (NoSuchAlgorithmException e) { |
|
825 |
} |
|
826 |
|
|
827 |
//Without time selected |
|
828 |
if(t == null || selectedProviders.size() != providerList.size()) { |
|
829 |
selectedProviders.clear(); |
|
830 |
for (int i = 0; i < providerList.size(); i++) { |
|
831 |
RasterProvider prov = providerList.get(i); |
|
832 |
selectedProviders.add(prov); |
|
833 |
if(!((RasterDataParameters)prov.getDataParameters()).isVisible()) |
|
834 |
name += prov.getURI().substring(prov.getURI().lastIndexOf(File.separator) + 1, prov.getURI().length()); |
|
835 |
} |
|
836 |
} else { |
|
837 |
selectedProviders.clear(); |
|
838 |
for (int i = 0; i < providerList.size(); i++) { |
|
839 |
try { |
|
840 |
TimeSeries tSeries = providerList.get(i).getTimeSerials(); |
|
841 |
ArrayList<?> tList = tSeries.getTimeList(); |
|
842 |
for (int j = 0; j < tList.size(); j++) { |
|
843 |
Object obj = tList.get(i); |
|
844 |
RelativeInstant instant = null; |
|
845 |
if(obj instanceof Date) { |
|
846 |
Date s = (Date)obj; |
|
847 |
instant = TimeSupportLocator.getManager().createRelativeInstant(s); |
|
848 |
} |
|
849 |
if(obj instanceof Double) { |
|
850 |
long s = ((Double)obj).longValue(); |
|
851 |
instant = TimeSupportLocator.getManager().createRelativeInstant(s); |
|
852 |
} |
|
853 |
if( instant != null && |
|
854 |
t.intersects(instant) && |
|
855 |
!selectedProviders.contains(providerList.get(i))) { |
|
856 |
RasterProvider prov = providerList.get(i); |
|
857 |
selectedProviders.add(prov); |
|
858 |
if(!((RasterDataParameters)prov.getDataParameters()).isVisible()) |
|
859 |
name += prov.getURI().substring(prov.getURI().lastIndexOf(File.separator) + 1, prov.getURI().length()); |
|
860 |
} |
|
861 |
} |
|
862 |
} catch (RmfSerializerException e) { |
|
863 |
logger.debug("Error reading rmf time serials", e); |
|
864 |
} |
|
865 |
} |
|
866 |
} |
|
867 |
|
|
868 |
if(md != null) { |
|
869 |
md.update(name.getBytes()); |
|
870 |
return math.convertToHex(md.digest()); |
|
871 |
} else { |
|
872 |
return name; |
|
873 |
} |
|
874 |
} |
|
875 |
|
|
876 |
/** |
|
877 |
* Creates a new tiled layer if this hasn't been created yet or the ID has changed. |
|
878 |
* An ID could changed because the file type has changed when the user uses WMTS properties. |
|
879 |
*/ |
|
880 |
private TileCache createTiledLayer(String layerName) { |
|
881 |
TileCacheManager manager = TileCacheLocator.getManager(); |
|
882 |
TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache); |
|
883 |
TiledLayer newLayer = tileCache.createLayer(getTileServer(layerName), TileCacheLibrary.DEFAULT_STRUCTURE); |
|
884 |
if(tiledLayer == null || newLayer.getID().compareTo(tiledLayer.getID()) != 0) |
|
885 |
tiledLayer = newLayer; |
|
886 |
return tileCache; |
|
887 |
} |
|
888 |
|
|
889 |
/** |
|
890 |
* Gets the tile list in a selected extent |
|
891 |
* @param ex |
|
892 |
* @param bandList |
|
893 |
* @param bufWidth |
|
894 |
* @param bufHeight |
|
895 |
* @return |
|
896 |
* @throws TileBuildException |
|
897 |
*/ |
|
898 |
private List<Tile> getTileList(Extent ex, BandList bandList, int bufWidth, int bufHeight, String layerName) throws TileBuildException { |
|
899 |
CacheStruct struct = getTileServer(layerName).getStruct(); |
|
900 |
|
|
901 |
createTiledLayer(layerName); //Creates a new layer when the file type changes |
|
902 |
|
|
903 |
Extent adjustedExtent = util.intersection(getExtent(), ex); |
|
904 |
double newBufWidth = (adjustedExtent.width() * bufWidth) / ex.width(); |
|
905 |
double pixelSizeRequest = adjustedExtent.width() / newBufWidth; |
|
906 |
|
|
907 |
List<Tile> tileList = struct.getTileList(new Point2D.Double(adjustedExtent.getULX(), adjustedExtent.getULY()), |
|
908 |
new Point2D.Double(adjustedExtent.getLRX(), adjustedExtent.getLRY()), |
|
909 |
pixelSizeRequest); |
|
910 |
|
|
911 |
for (int i = 0; i < tileList.size(); i++) { |
|
912 |
tileList.get(i).setDownloaderParams("BandList", bandList.clone()); |
|
913 |
} |
|
914 |
return tileList; |
|
915 |
} |
|
916 |
|
|
917 |
public TileServer getTileServer() { |
|
918 |
if(tileServer == null) |
|
919 |
tileServer = new FileTileServer(this); |
|
920 |
return tileServer; |
|
921 |
} |
|
922 |
|
|
923 |
/** |
|
924 |
* Gets the tile server from the Hashmap |
|
925 |
* @param layerName |
|
926 |
* @return |
|
927 |
*/ |
|
928 |
public TileServer getTileServer(String layerName) { |
|
929 |
MosaicTileServer tileServer = tileServerMap.get(layerName); |
|
930 |
if(tileServer == null) { |
|
931 |
tileServer = new MosaicTileServer(this, |
|
932 |
providerList, |
|
933 |
layerName, |
|
934 |
getParameters().getOverlapMethod(), |
|
935 |
getParameters().getColorCorrectionMethod(), |
|
936 |
getNoDataValue()); |
|
937 |
tileServerMap.put(layerName, tileServer); |
|
938 |
} |
|
939 |
return tileServer; |
|
940 |
} |
|
941 |
} |
org.gvsig.raster.mosaic/trunk/org.gvsig.raster.mosaic/org.gvsig.raster.mosaic.io/src/main/java/org/gvsig/raster/mosaic/io/downloader/MosaicTileServer.java | ||
---|---|---|
33 | 33 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
34 | 34 |
import org.gvsig.raster.cache.tile.provider.Downloader; |
35 | 35 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
36 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
|
37 | 36 |
import org.gvsig.raster.impl.provider.RasterProvider; |
37 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
|
38 | 38 |
import org.gvsig.raster.mosaic.io.MosaicDataParameters; |
39 | 39 |
|
40 | 40 |
/** |
... | ... | |
44 | 44 |
public class MosaicTileServer implements TileServer { |
45 | 45 |
private CacheStruct struct = null; |
46 | 46 |
private Downloader downloader = null; |
47 |
private DefaultRasterProvider provider = null;
|
|
47 |
private DefaultRasterStore store = null;
|
|
48 | 48 |
private String suffix = "tif"; |
49 | 49 |
private String layerName = null; |
50 | 50 |
private List<RasterProvider> provList = null; |
... | ... | |
52 | 52 |
private int colorCorrectionMethod = MosaicDataParameters.NONE; |
53 | 53 |
private NoData noData = null; |
54 | 54 |
|
55 |
public MosaicTileServer(DefaultRasterProvider prov,
|
|
55 |
public MosaicTileServer(DefaultRasterStore store,
|
|
56 | 56 |
List<RasterProvider> provList, |
57 | 57 |
String layerName, |
58 | 58 |
int overlapMethod, |
59 | 59 |
int colorCorrectionMethod, |
60 | 60 |
NoData noData) { |
61 |
this.provider = prov;
|
|
61 |
this.store = store;
|
|
62 | 62 |
this.layerName = layerName; |
63 | 63 |
this.provList = provList; |
64 | 64 |
this.overlapMethod = overlapMethod; |
... | ... | |
74 | 74 |
if(downloader == null || |
75 | 75 |
((TileDownloaderForMosaics)downloader).getTileSize()[0] != TileCacheLibrary.DEFAULT_TILEWIDTH || |
76 | 76 |
((TileDownloaderForMosaics)downloader).getTileSize()[1] != TileCacheLibrary.DEFAULT_TILEHEIGHT) { |
77 |
downloader = new TileDownloaderForMosaics(provider,
|
|
77 |
downloader = new TileDownloaderForMosaics(store,
|
|
78 | 78 |
provList, |
79 | 79 |
getStruct(), |
80 | 80 |
TileCacheLibrary.DEFAULT_TILEWIDTH, |
... | ... | |
92 | 92 |
TileCacheManager manager = TileCacheLocator.getManager(); |
93 | 93 |
|
94 | 94 |
int coordinates = CacheStruct.FLAT; |
95 |
if(provider.getProjection() != null)
|
|
96 |
coordinates = (provider.getProjection() != null && provider.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
|
|
95 |
if(store.getProjection() != null)
|
|
96 |
coordinates = (store.getProjection() != null && store.getProjection().isProjected()) ? CacheStruct.FLAT : CacheStruct.GEOGRAFIC;
|
|
97 | 97 |
else { |
98 |
Extent e = provider.getExtent();
|
|
98 |
Extent e = store.getExtent();
|
|
99 | 99 |
if(e.getULX() >= -180 && e.getULX() <= 180 && e.getLRX() >= -180 && e.getLRX() <= 180 && |
100 | 100 |
e.getULY() >= -90 && e.getULY() <= 90 && e.getLRY() >= -90 && e.getLRY() <= 90) { |
101 | 101 |
coordinates = CacheStruct.GEOGRAFIC; |
... | ... | |
103 | 103 |
} |
104 | 104 |
|
105 | 105 |
String epsg = null; |
106 |
IProjection proj = provider.getProjection();
|
|
106 |
IProjection proj = store.getProjection();
|
|
107 | 107 |
if(proj != null) |
108 | 108 |
epsg = proj.getAbrev(); |
109 | 109 |
|
110 | 110 |
struct = manager.createCacheStructure(coordinates, |
111 | 111 |
TileCacheLibrary.DEFAULT_LEVELS, |
112 |
provider.getExtent().toRectangle2D(),
|
|
113 |
provider.getCellSize(),
|
|
112 |
store.getExtent().toRectangle2D(),
|
|
113 |
store.getCellSize(),
|
|
114 | 114 |
TileCacheLibrary.DEFAULT_TILEWIDTH, |
115 | 115 |
TileCacheLibrary.DEFAULT_TILEHEIGHT, |
116 | 116 |
layerName, |
... | ... | |
118 | 118 |
RasterLibrary.pathTileCache, |
119 | 119 |
getFileSuffix(), |
120 | 120 |
epsg, |
121 |
provider.getFileSize());
|
|
121 |
store.getFileSize());
|
|
122 | 122 |
} |
123 | 123 |
return struct; |
124 | 124 |
} |
... | ... | |
131 | 131 |
if(struct != null) { |
132 | 132 |
this.struct = struct; |
133 | 133 |
if(struct.getTileSizeByLevel(0) != null) { |
134 |
downloader = new TileDownloaderForMosaics(provider,
|
|
134 |
downloader = new TileDownloaderForMosaics(store,
|
|
135 | 135 |
provList, |
136 | 136 |
getStruct(), |
137 | 137 |
struct.getTileSizeByLevel(0)[0], |
org.gvsig.raster.mosaic/trunk/org.gvsig.raster.mosaic/org.gvsig.raster.mosaic.io/src/main/java/org/gvsig/raster/mosaic/io/downloader/TileDownloaderForMosaics.java | ||
---|---|---|
28 | 28 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
29 | 29 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
30 | 30 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
31 |
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand; |
|
32 | 31 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
33 | 32 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
34 |
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException; |
|
35 | 33 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
36 | 34 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
35 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
|
37 | 36 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
37 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
38 | 38 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
39 | 39 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
40 | 40 |
import org.gvsig.raster.cache.tile.Tile; |
41 | 41 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
42 | 42 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
43 | 43 |
import org.gvsig.raster.impl.DefaultRasterManager; |
44 |
import org.gvsig.raster.impl.buffer.DefaultRasterQuery; |
|
45 | 44 |
import org.gvsig.raster.impl.datastruct.BandListImpl; |
46 |
import org.gvsig.raster.impl.datastruct.DatasetBandImpl; |
|
47 | 45 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
48 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
|
49 | 46 |
import org.gvsig.raster.impl.provider.RasterProvider; |
50 | 47 |
import org.gvsig.raster.impl.provider.tile.BaseTileDownloader; |
48 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
|
51 | 49 |
import org.gvsig.raster.mosaic.io.MosaicDataParameters; |
52 | 50 |
|
53 | 51 |
/** |
... | ... | |
63 | 61 |
private int colorCorrectionMethod = MosaicDataParameters.NONE; |
64 | 62 |
private TileFusion tileFusion = null; |
65 | 63 |
|
66 |
public TileDownloaderForMosaics(DefaultRasterProvider prov,
|
|
64 |
public TileDownloaderForMosaics(DefaultRasterStore store,
|
|
67 | 65 |
List<RasterProvider> provList, |
68 | 66 |
CacheStruct struct, |
69 | 67 |
int tileWidth, |
... | ... | |
72 | 70 |
int overlapMethod, |
73 | 71 |
int colorCorrectionMethod, |
74 | 72 |
NoData noData) { |
75 |
super(prov, tileWidth, tileHeight);
|
|
73 |
super(store, tileWidth, tileHeight);
|
|
76 | 74 |
this.provList = provList; |
77 | 75 |
this.struct = struct; |
78 | 76 |
this.extension = extension; |
... | ... | |
94 | 92 |
if(!p.getDataParameters().isVisible()) |
95 | 93 |
continue; |
96 | 94 |
ci = p.getColorInterpretation(); |
97 |
Buffer bufPartialResult = clipTileFromProvider((DefaultRasterProvider)p, tile);
|
|
95 |
Buffer bufPartialResult = clipTileFromProvider(p, tile); |
|
98 | 96 |
if(bufPartialResult != null) { |
99 | 97 |
if(p.getDataType()[0] == Buffer.TYPE_BYTE && bufPartialResult.getBandCount() > p.getBandCount()) { |
100 | 98 |
alphaBand = true; //If one result has alpha band then the alpha band flag is on |
... | ... | |
138 | 136 |
return tile; |
139 | 137 |
} |
140 | 138 |
|
141 |
private Buffer clipTileFromProvider(DefaultRasterProvider p, Tile tile) throws RasterDriverException {
|
|
139 |
private Buffer clipTileFromProvider(RasterProvider p, Tile tile) throws RasterDriverException { |
|
142 | 140 |
Extent tileExtent = new ExtentImpl(tile.getUl(), tile.getLr()); |
143 | 141 |
|
144 | 142 |
//Escribe todas las bandas a disco |
... | ... | |
176 | 174 |
Buffer smallBuf = readSupersampledBuffer(ex, newBandList, newBufWidth, newBufHeight, nBandsBuffer); |
177 | 175 |
|
178 | 176 |
if(smallBuf == null) { //No ha habido resampleo |
179 |
smallBuf = DefaultRasterManager.getInstance().createMemoryBuffer(p.getDataType()[0], newBufWidth, newBufHeight, nBandsBuffer, true); |
|
180 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery(); |
|
177 |
//BufferParam bufParams = RasterLocator.getManager().getBufferFactory().createMemoryBufferParams(p.getDataType()[0], newBufWidth, newBufHeight, nBandsBuffer, true); |
|
178 |
// = RasterLocator.getManager().getBufferFactory().createBuffer(bufParams); |
|
179 |
DefaultRasterStore localStore = new DefaultRasterStore(); |
|
180 |
localStore.setProvider(p); |
|
181 |
|
|
182 |
RasterQuery q = RasterLocator.getManager().createQuery(); |
|
181 | 183 |
q.setAreaOfInterest(ex, newBufWidth, newBufHeight); |
182 |
q.setBandList(newBandList); |
|
183 |
q.setBuffer(smallBuf); |
|
184 |
q.setAdjustToExtent(true); |
|
185 |
smallBuf = p.getDataSet(q); |
|
186 |
//smallBuf = p.getWindow(ex, newBufWidth, newBufHeight, newBandList, smallBuf, true, null); |
|
184 |
q.setDrawableBands(newBandList.getDrawableBands()); |
|
185 |
try { |
|
186 |
smallBuf = localStore.query(q); |
|
187 |
} catch (QueryException e) { |
|
188 |
throw new RasterDriverException("Error reading mosaic", e); |
|
189 |
} |
|
187 | 190 |
} |
188 | 191 |
copyToBuffer(bufResult, tileExtent, smallBuf, ex, pixelSize); |
189 | 192 |
//} |
... | ... | |
194 | 197 |
} |
195 | 198 |
|
196 | 199 |
/** |
197 |
* Builds a Bandlist object to load tiles |
|
198 |
* @return |
|
199 |
* @deprecated It is only for multifile providers |
|
200 |
*/ |
|
201 |
@SuppressWarnings("unused") |
|
202 |
private BandList getBandList() { |
|
203 |
BandListImpl bandList = new BandListImpl(); |
|
204 |
for(int i = 0; i < prov.getBandCount(); i++) { |
|
205 |
try { |
|
206 |
int dataType = prov.getDataType()[i]; |
|
207 |
DatasetBand band = new DatasetBandImpl(prov.getURIByBand(i), i, dataType, prov.getBandCount()); |
|
208 |
bandList.addBand(band, i); |
|
209 |
} catch(BandNotFoundInListException ex) { |
|
210 |
//No a�adimos la banda |
|
211 |
} |
|
212 |
} |
|
213 |
return bandList; |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 | 200 |
* If the provider doesn't support resampling then this method reamples the result manually |
218 | 201 |
* @param tileExtent |
219 | 202 |
* @param newBandList |
... | ... | |
225 | 208 |
* @throws RasterDriverException |
226 | 209 |
*/ |
227 | 210 |
private Buffer readSupersampledBuffer(Extent tileExtent, BandList newBandList, int bufWidth, int bufHeight, int nBands) throws ProcessInterruptedException, RasterDriverException { |
228 |
int widthImgPx = (int)Math.abs(tileExtent.width() / prov.getPixelSizeX());
|
|
229 |
int heightImgPx = (int)Math.abs(tileExtent.height() / prov.getPixelSizeY());
|
|
211 |
int widthImgPx = (int)Math.abs(tileExtent.width() / store.getPixelSizeX());
|
|
212 |
int heightImgPx = (int)Math.abs(tileExtent.height() / store.getPixelSizeY());
|
|
230 | 213 |
boolean supersampling = ((bufWidth > widthImgPx) || (bufHeight > heightImgPx)) ? true : false; |
231 | 214 |
|
232 |
if(supersampling && !prov.isSupersamplingSupported()) {
|
|
215 |
if(supersampling /*&& !prov.isSupersamplingSupported()*/) {
|
|
233 | 216 |
//Ecw no supersamplea por lo que habr� que hacerlo a mano |
234 |
Buffer buf = buildTileBuffer(nBands, widthImgPx, heightImgPx); |
|
217 |
Buffer buf = null;//buildTileBuffer(nBands, widthImgPx, heightImgPx);
|
|
235 | 218 |
|
236 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
|
|
219 |
RasterQuery q = RasterLocator.getManager().createQuery();
|
|
237 | 220 |
q.setAreaOfInterest(tileExtent, widthImgPx, heightImgPx); |
238 |
q.setBandList(newBandList); |
|
239 |
q.setBuffer(buf); |
|
240 |
q.setAdjustToExtent(true); |
|
241 |
buf = prov.getDataSet(q); |
|
221 |
q.setDrawableBands(newBandList.getDrawableBands()); |
|
222 |
try { |
|
223 |
buf = store.query(q); |
|
224 |
} catch (QueryException e) { |
|
225 |
throw new RasterDriverException("Error reading mosaic", e); |
|
226 |
} |
|
242 | 227 |
|
243 | 228 |
//prov.getWindow(tileExtent, widthImgPx, heightImgPx, newBandList, buf, true, null); |
244 | 229 |
return buf.getAdjustedWindow(bufWidth, bufHeight, Buffer.INTERPOLATION_NearestNeighbour); |
... | ... | |
252 | 237 |
* @return |
253 | 238 |
*/ |
254 | 239 |
private Buffer buildTileBuffer(int nbands, int w, int h) { |
255 |
Buffer bufResult = DefaultRasterManager.getInstance().createMemoryBuffer(prov.getDataType()[0], w, h, nbands, true);
|
|
256 |
if(prov.getDataType()[0] != Buffer.TYPE_BYTE) {
|
|
240 |
Buffer bufResult = DefaultRasterManager.getInstance().createMemoryBuffer(store.getDataType()[0], w, h, nbands, true);
|
|
241 |
if(store.getDataType()[0] != Buffer.TYPE_BYTE) {
|
|
257 | 242 |
for (int i = 0; i < bufResult.getBandCount(); i++) { |
258 | 243 |
clearMaskBuffer(bufResult, i); |
259 | 244 |
} |
org.gvsig.raster.mosaic/trunk/org.gvsig.raster.mosaic/org.gvsig.raster.mosaic.io/src/main/java/org/gvsig/raster/mosaic/io/MosaicProvider.java | ||
---|---|---|
22 | 22 |
package org.gvsig.raster.mosaic.io; |
23 | 23 |
|
24 | 24 |
import java.awt.geom.AffineTransform; |
25 |
import java.awt.geom.Point2D; |
|
26 |
import java.awt.geom.Rectangle2D; |
|
27 | 25 |
import java.io.File; |
28 | 26 |
import java.io.IOException; |
29 | 27 |
import java.security.MessageDigest; |
... | ... | |
39 | 37 |
import org.gvsig.fmap.dal.DALLocator; |
40 | 38 |
import org.gvsig.fmap.dal.DataStore; |
41 | 39 |
import org.gvsig.fmap.dal.DataStoreParameters; |
42 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
43 | 40 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
44 | 41 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
45 | 42 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
46 |
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand; |
|
47 | 43 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
48 | 44 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
49 | 45 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
... | ... | |
55 | 51 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
56 | 52 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
57 | 53 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
54 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
|
58 | 55 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
59 | 56 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
60 | 57 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
58 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
|
61 | 59 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
60 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
62 | 61 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
62 |
import org.gvsig.fmap.dal.coverage.store.props.Metadata; |
|
63 | 63 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
64 | 64 |
import org.gvsig.fmap.dal.coverage.store.props.TimeSeries; |
65 | 65 |
import org.gvsig.fmap.dal.coverage.util.MathUtils; |
... | ... | |
74 | 74 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
75 | 75 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
76 | 76 |
import org.gvsig.metadata.MetadataLocator; |
77 |
import org.gvsig.raster.cache.tile.TileCache; |
|
78 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
|
79 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
|
80 |
import org.gvsig.raster.cache.tile.TileCacheManager; |
|
81 | 77 |
import org.gvsig.raster.cache.tile.exception.TileBuildException; |
82 |
import org.gvsig.raster.cache.tile.layer.TiledLayer; |
|
83 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
|
84 | 78 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
85 |
import org.gvsig.raster.impl.DefaultRasterManager;
|
|
79 |
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
|
|
86 | 80 |
import org.gvsig.raster.impl.datastruct.BandListImpl; |
87 | 81 |
import org.gvsig.raster.impl.datastruct.DatasetBandImpl; |
88 | 82 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
89 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
|
|
83 |
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
|
|
90 | 84 |
import org.gvsig.raster.impl.provider.RasterProvider; |
91 | 85 |
import org.gvsig.raster.impl.provider.fusion.BufferListFusion; |
92 | 86 |
import org.gvsig.raster.impl.provider.fusion.BufferListFusion.PixelSquareStructure; |
93 | 87 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
94 | 88 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
89 |
import org.gvsig.raster.impl.store.DefaultRasterStore; |
|
95 | 90 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
91 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
|
92 |
import org.gvsig.raster.impl.store.properties.DataStoreMetadata; |
|
96 | 93 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
97 | 94 |
import org.gvsig.raster.impl.store.properties.SimpleProviderHistogramComputer; |
98 | 95 |
import org.gvsig.raster.impl.store.properties.SimpleProviderStatistics; |
... | ... | |
109 | 106 |
* |
110 | 107 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
111 | 108 |
*/ |
112 |
public class MosaicProvider extends DefaultRasterProvider {
|
|
109 |
public class MosaicProvider extends AbstractRasterProvider {
|
|
113 | 110 |
public static String NAME = "Mosaic Raster"; |
114 | 111 |
public static String DESCRIPTION = "Mosaic Raster Support"; |
115 | 112 |
public final String METADATA_DEFINITION_NAME = NAME; |
... | ... | |
230 | 227 |
} catch (ParsingException e) { |
231 | 228 |
//No lee desde rmf |
232 | 229 |
} |
233 |
|
|
230 |
|
|
234 | 231 |
open = true; |
235 | 232 |
} |
236 | 233 |
|
... | ... | |
241 | 238 |
uri = getParameters().getURI(); |
242 | 239 |
providerList = getParameters().getProviders(); |
243 | 240 |
pixelSize = getParameters().getPixelSize(); |
244 |
setColorInterpretation(providerList.get(0).getColorInterpretation().cloneColorInterpretation()); |
|
241 |
ColorInterpretation ci = null; |
|
242 |
if(getBandCount() == 4) |
|
243 |
ci = DataStoreColorInterpretation.createARGBInterpretation(); |
|
244 |
if(getBandCount() == 3) |
|
245 |
ci = DataStoreColorInterpretation.createRGBInterpretation(); |
|
246 |
if(getBandCount() == 1) |
|
247 |
ci = DataStoreColorInterpretation.createGrayInterpretation(); |
|
245 | 248 |
|
249 |
setColorInterpretation(ci); |
|
250 |
|
|
246 | 251 |
//Se le pone banda de transparencia siempre |
247 | 252 |
if(providerList.get(0).getDataType()[0] == Buffer.TYPE_BYTE) { |
248 | 253 |
transparency = new DataStoreTransparency(); |
... | ... | |
578 | 583 |
@SuppressWarnings("deprecation") |
579 | 584 |
public Object readBlock(int pos, int blockHeight, double scale) |
580 | 585 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException { |
581 |
if(getParameters().hasParamsChanged()) |
|
586 |
/*if(getParameters().hasParamsChanged())
|
|
582 | 587 |
calcMetadataFromParams(); |
583 | 588 |
blockHeight = pos + blockHeight > getHeight() ? (int)(getHeight() - pos) : blockHeight; |
584 | 589 |
Buffer buf = RasterLocator.getManager().createBuffer(getDataType()[0], (int)getWidth(), blockHeight, getBandCount(), true); |
... | ... | |
599 | 604 |
} |
600 | 605 |
} |
601 | 606 |
bandList.setDrawableBands(drawableBands); |
602 |
return getWindow(0, pos, bandList, buf); |
|
607 |
return getWindow(0, pos, bandList, buf);*/ |
|
608 |
return null; |
|
603 | 609 |
} |
604 | 610 |
|
605 | 611 |
public Object getData(int x, int y, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
... | ... | |
608 | 614 |
return null; |
609 | 615 |
} |
610 | 616 |
|
611 |
// private Buffer getBuffersFusion(BandList bandList, TaskStatus status) throws RasterDriverException, ProcessInterruptedException { |
|
612 |
// List<Buffer> bufferList = new ArrayList<Buffer>(); |
|
613 |
// |
|
614 |
// for (int i = 0; i < providerList.size(); i++) { |
|
615 |
// RasterProvider provider = providerList.get(i); |
|
616 |
// Extent extIntersection = extent.intersection(provider.getExtent()); |
|
617 |
// Point2D ulPx = provider.worldToRaster(new Point2D.Double(extIntersection.getULX(), extIntersection.getULY())); |
|
618 |
// Point2D lrPx = provider.worldToRaster(new Point2D.Double(extIntersection.getLRX(), extIntersection.getLRY())); |
|
619 |
// Buffer partialBuffer = DefaultRasterManager.getInstance().createBuffer( |
|
620 |
// provider.getDataType()[0], |
|
621 |
// (int)Math.abs(lrPx.getX() - ulPx.getX() + 1), |
|
622 |
// (int)Math.abs(lrPx.getY() - ulPx.getY() + 1), |
|
623 |
// provider.getBandCount(), true); |
|
624 |
// partialBuffer = ((DefaultRasterProvider)provider).getWindow(extent, bandList, partialBuffer, status); |
|
625 |
// bufferList.add(partialBuffer); |
|
626 |
// } |
|
627 |
// |
|
628 |
// PixelSquareStructure pxSquare = BufferListFusion.buildPixelSquareStructure(getPixelSizeX(), getBandCount(), getDataType()[0]); |
|
629 |
// BufferListFusion bufferFusion = new BufferListFusion(bufferList, pxSquare, BufferListFusion.FIRST); |
|
630 |
// return bufferFusion.getWindow(); |
|
631 |
// } |
|
632 |
|
|
633 | 617 |
/** |
634 | 618 |
* Creates a <code>BandList</code> for each provider of this <code>MultiFileProvider</code>. |
635 | 619 |
* When a request is made, the <code>BandList</code> is global for all files. A specific |
... | ... | |
640 | 624 |
*/ |
641 | 625 |
private BandList createBandListByProvider(BandList globalBandList, RasterProvider provider) { |
642 | 626 |
if(provider.isTiled()) { |
643 |
//Si los proveedores que hay por debajo son tileados estos crear�n su propio buffer para escribir
|
|
644 |
//cada tile. Por ello no usar� el buffer que viene del store. Esto quiere decir que el BandList ha |
|
627 |
//Si los proveedores que hay por debajo son tileados estos crearan su propio buffer para escribir
|
|
628 |
//cada tile. Por ello no usara� el buffer que viene del store. Esto quiere decir que el BandList ha
|
|
645 | 629 |
//de ser distinto para que escriba bien en su buffer |
646 | 630 |
|
647 | 631 |
//TODO: De momento no se permiten MultiFiles con proveedores tileados. Esto es porque |
... | ... | |
684 | 668 |
RasterProvider provider = providerList.get(i); |
685 | 669 |
Extent extIntersection = getView().intersection(provider.getExtent()); |
686 | 670 |
|
671 |
if(extIntersection == null) |
|
672 |
continue; |
|
673 |
|
|
687 | 674 |
double relWidth = getView().width() / rasterBuf.getWidth(); |
688 | 675 |
double relHeight = getView().height() / rasterBuf.getHeight(); |
689 | 676 |
int w = (int)Math.ceil(adjustCoordinate(extIntersection.width() / relWidth)); |
690 | 677 |
int h = (int)Math.ceil(adjustCoordinate(extIntersection.height() / relHeight)); |
691 |
|
|
692 |
Buffer partialBuffer = DefaultRasterManager.getInstance().createBuffer( |
|
693 |
provider.getDataType()[0], w, h, rasterBuf.getBandCount(), true); |
|
694 |
BandList b = createBandListByProvider(bandList, provider); |
|
695 |
partialBuffer = ((DefaultRasterProvider)provider).getWindow(extIntersection, b, partialBuffer, status); |
|
696 |
partialBuffer.setDataExtent(extIntersection.toRectangle2D()); |
|
697 |
bufferList.add(partialBuffer); |
Also available in: Unified diff