|
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.wcs.io;
|
|
23 |
|
|
24 |
import java.awt.geom.AffineTransform;
|
|
25 |
import java.awt.geom.NoninvertibleTransformException;
|
|
26 |
import java.awt.geom.Point2D;
|
|
27 |
import java.awt.geom.Rectangle2D;
|
|
28 |
import java.io.File;
|
|
29 |
import java.io.IOException;
|
|
30 |
import java.net.URL;
|
|
31 |
import java.util.Hashtable;
|
|
32 |
|
|
33 |
import org.gvsig.compat.net.ICancellable;
|
|
34 |
import org.gvsig.fmap.dal.DALLocator;
|
|
35 |
import org.gvsig.fmap.dal.DataStore;
|
|
36 |
import org.gvsig.fmap.dal.DataStoreParameters;
|
|
37 |
import org.gvsig.fmap.dal.coverage.RasterLocator;
|
|
38 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
|
|
39 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
|
|
40 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
|
|
41 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
|
|
42 |
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
|
|
43 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
|
|
44 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
|
|
45 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
|
|
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.exception.RemoteServiceException;
|
|
49 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
|
|
50 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
|
|
51 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
|
|
52 |
import org.gvsig.fmap.dal.exception.InitializeException;
|
|
53 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
|
|
54 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
|
|
55 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
|
|
56 |
import org.gvsig.metadata.MetadataLocator;
|
|
57 |
import org.gvsig.raster.cache.tile.TileCacheLocator;
|
|
58 |
import org.gvsig.raster.cache.tile.TileCacheManager;
|
|
59 |
import org.gvsig.raster.cache.tile.exception.TileGettingException;
|
|
60 |
import org.gvsig.raster.cache.tile.provider.TileListener;
|
|
61 |
import org.gvsig.raster.cache.tile.provider.TileServer;
|
|
62 |
import org.gvsig.raster.impl.DefaultRasterManager;
|
|
63 |
import org.gvsig.raster.impl.buffer.DefaultRasterQuery;
|
|
64 |
import org.gvsig.raster.impl.datastruct.BandListImpl;
|
|
65 |
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
|
|
66 |
import org.gvsig.raster.impl.datastruct.ExtentImpl;
|
|
67 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
|
|
68 |
import org.gvsig.raster.impl.provider.RasterProvider;
|
|
69 |
import org.gvsig.raster.impl.provider.RemoteRasterProvider;
|
|
70 |
import org.gvsig.raster.impl.store.DefaultStoreFactory;
|
|
71 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
|
|
72 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
|
|
73 |
import org.gvsig.raster.impl.store.properties.RemoteDataStoreStatistics;
|
|
74 |
import org.gvsig.raster.impl.store.properties.RemoteStoreHistogram;
|
|
75 |
import org.gvsig.raster.util.DefaultProviderServices;
|
|
76 |
import org.gvsig.raster.wcs.io.downloader.WCSTileServer;
|
|
77 |
import org.gvsig.remoteclient.wcs.WCSStatus;
|
|
78 |
import org.gvsig.tools.ToolsLocator;
|
|
79 |
import org.gvsig.tools.task.TaskStatus;
|
|
80 |
import org.slf4j.Logger;
|
|
81 |
import org.slf4j.LoggerFactory;
|
|
82 |
/**
|
|
83 |
* Clase que representa al driver de acceso a datos de wcs.
|
|
84 |
*
|
|
85 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
|
86 |
*/
|
|
87 |
public class WCSProvider extends DefaultRasterProvider implements RemoteRasterProvider {
|
|
88 |
public static String NAME = "Wcs Store";
|
|
89 |
public static String DESCRIPTION = "Wcs Raster file";
|
|
90 |
public static final String METADATA_DEFINITION_NAME = "WcsStore";
|
|
91 |
|
|
92 |
private static final Logger logger = LoggerFactory.getLogger(WCSProvider.class);
|
|
93 |
private Extent viewRequest = null;
|
|
94 |
private static Hashtable<URL, WCSConnector>
|
|
95 |
drivers = new Hashtable<URL, WCSConnector> ();
|
|
96 |
private boolean open = false;
|
|
97 |
private DataStoreTransparency fileTransparency = null;
|
|
98 |
private File lastRequest = null;
|
|
99 |
private DefaultRasterProvider lastRequestProvider = null;
|
|
100 |
|
|
101 |
public static void register() {
|
|
102 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
|
|
103 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
|
|
104 |
dataman.registerStoreProvider(NAME,
|
|
105 |
WCSProvider.class, WCSDataParametersImpl.class);
|
|
106 |
}
|
|
107 |
|
|
108 |
if (!dataman.getExplorerProviders().contains(WCSServerExplorer.NAME)) {
|
|
109 |
dataman.registerExplorerProvider(WCSServerExplorer.NAME, WCSServerExplorer.class, WCSServerExplorerParameters.class);
|
|
110 |
}
|
|
111 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
|
|
112 |
}
|
|
113 |
|
|
114 |
public WCSProvider() throws NotSupportedExtensionException {
|
|
115 |
super();
|
|
116 |
}
|
|
117 |
|
|
118 |
/**
|
|
119 |
* Constructor. Abre el dataset.
|
|
120 |
* @param proj Proyecci?n
|
|
121 |
* @param fName Nombre del fichero
|
|
122 |
* @throws NotSupportedExtensionException
|
|
123 |
*/
|
|
124 |
public WCSProvider(String params) throws NotSupportedExtensionException {
|
|
125 |
super(params);
|
|
126 |
if(params instanceof String) {
|
|
127 |
WCSDataParametersImpl p = new WCSDataParametersImpl();
|
|
128 |
p.setURI((String)params);
|
|
129 |
super.init(p, null, ToolsLocator.getDynObjectManager()
|
|
130 |
.createDynObject(
|
|
131 |
MetadataLocator.getMetadataManager().getDefinition(
|
|
132 |
DataStore.METADATA_DEFINITION_NAME)));
|
|
133 |
init(p, null);
|
|
134 |
}
|
|
135 |
}
|
|
136 |
|
|
137 |
public WCSProvider(WCSDataParametersImpl params,
|
|
138 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
|
|
139 |
super(params, storeServices, ToolsLocator.getDynObjectManager()
|
|
140 |
.createDynObject(
|
|
141 |
MetadataLocator.getMetadataManager().getDefinition(
|
|
142 |
DataStore.METADATA_DEFINITION_NAME)));
|
|
143 |
init(params, storeServices);
|
|
144 |
}
|
|
145 |
|
|
146 |
/**
|
|
147 |
* Gets the connector from the URL
|
|
148 |
* @return
|
|
149 |
* @throws RemoteServiceException
|
|
150 |
*/
|
|
151 |
public WCSConnector getConnector() throws RemoteServiceException {
|
|
152 |
WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
|
|
153 |
URL url = null;
|
|
154 |
try {
|
|
155 |
url = new URL(p.getURI());
|
|
156 |
} catch (Exception e) {
|
|
157 |
throw new RemoteServiceException("Malformed URL",e);
|
|
158 |
}
|
|
159 |
try {
|
|
160 |
return WCSProvider.getConnectorFromURL(url);
|
|
161 |
} catch (IOException e) {
|
|
162 |
throw new RemoteServiceException("Error getting the connector",e);
|
|
163 |
}
|
|
164 |
}
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Crea las referencias al fichero y carga
|
|
168 |
* las estructuras con la informaci?n y los metadatos.
|
|
169 |
* @param proj Proyecci?n
|
|
170 |
* @param param Parametros de carga
|
|
171 |
* @throws NotSupportedExtensionException
|
|
172 |
*/
|
|
173 |
public void init (DataStoreParameters params,
|
|
174 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
|
|
175 |
setParam(storeServices, params);
|
|
176 |
open = true;
|
|
177 |
try {
|
|
178 |
loadInitialInfo();
|
|
179 |
} catch (RasterDriverException e) {
|
|
180 |
logger.info("Loaded default values in WCS provider", e);
|
|
181 |
}
|
|
182 |
|
|
183 |
stats = new RemoteDataStoreStatistics(this);
|
|
184 |
}
|
|
185 |
|
|
186 |
public static final WCSConnector getConnectorFromURL(URL url) throws IOException {
|
|
187 |
WCSConnector drv = (WCSConnector) drivers.get(url);
|
|
188 |
if (drv == null) {
|
|
189 |
drv = new WCSConnector(url);
|
|
190 |
drivers.put(url, drv);
|
|
191 |
}
|
|
192 |
return drv;
|
|
193 |
}
|
|
194 |
|
|
195 |
/**
|
|
196 |
* Obtiene el objeto que contiene que contiene la interpretaci?n de
|
|
197 |
* color por banda
|
|
198 |
* @return
|
|
199 |
*/
|
|
200 |
public ColorInterpretation getColorInterpretation() {
|
|
201 |
if(super.getColorInterpretation() == null) {
|
|
202 |
ColorInterpretation colorInterpretation = new DataStoreColorInterpretation();
|
|
203 |
colorInterpretation.initColorInterpretation(getBandCount());
|
|
204 |
if(getBandCount() == 3) {
|
|
205 |
colorInterpretation.setColorInterpValue(0, DataStoreColorInterpretation.RED_BAND);
|
|
206 |
colorInterpretation.setColorInterpValue(1, DataStoreColorInterpretation.GREEN_BAND);
|
|
207 |
colorInterpretation.setColorInterpValue(2, DataStoreColorInterpretation.BLUE_BAND);
|
|
208 |
} else {
|
|
209 |
for (int i = 0; i < getBandCount(); i++) {
|
|
210 |
colorInterpretation.setColorInterpValue(i, DataStoreColorInterpretation.GRAY_BAND);
|
|
211 |
}
|
|
212 |
}
|
|
213 |
setColorInterpretation(colorInterpretation);
|
|
214 |
}
|
|
215 |
return super.getColorInterpretation();
|
|
216 |
}
|
|
217 |
|
|
218 |
/**
|
|
219 |
* Gets WCS parameters
|
|
220 |
* @return
|
|
221 |
*/
|
|
222 |
public WCSDataParameters getParameters() {
|
|
223 |
return (WCSDataParameters)parameters;
|
|
224 |
}
|
|
225 |
|
|
226 |
/*
|
|
227 |
* (non-Javadoc)
|
|
228 |
* @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getAffineTransform()
|
|
229 |
*/
|
|
230 |
public AffineTransform getAffineTransform() {
|
|
231 |
Extent e = getExtent();
|
|
232 |
double resolutionX = e.width() / getWidth();
|
|
233 |
double resolutionY = e.height() / getHeight();
|
|
234 |
ownTransformation = new AffineTransform(
|
|
235 |
resolutionX,
|
|
236 |
0,
|
|
237 |
0,
|
|
238 |
-resolutionY,
|
|
239 |
e.getULX() - (resolutionX / 2),
|
|
240 |
e.getULY() - (resolutionY / 2));
|
|
241 |
externalTransformation = (AffineTransform) ownTransformation.clone();
|
|
242 |
return ownTransformation;
|
|
243 |
}
|
|
244 |
|
|
245 |
/**
|
|
246 |
* Calcula el extent en coordenadas del mundo real
|
|
247 |
* @return Extent
|
|
248 |
*/
|
|
249 |
public Extent getExtent() {
|
|
250 |
WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
|
|
251 |
try {
|
|
252 |
Rectangle2D r = getConnector().getFullExtent(p.getCoverageName(), p.getSRSCode());
|
|
253 |
return new ExtentImpl(r.getX(), r.getY() + r.getHeight(), r.getX() + r.getWidth(), r.getY());
|
|
254 |
} catch (RemoteServiceException e1) {
|
|
255 |
e1.printStackTrace();
|
|
256 |
} catch (IOException e) {
|
|
257 |
e.printStackTrace();
|
|
258 |
}
|
|
259 |
return null;
|
|
260 |
}
|
|
261 |
|
|
262 |
|
|
263 |
/*
|
|
264 |
* (non-Javadoc)
|
|
265 |
* @see org.gvsig.raster.impl.provider.RemoteRasterProvider#getLayerExtent(java.lang.String, java.lang.String)
|
|
266 |
*/
|
|
267 |
public Rectangle2D getLayerExtent(String layerName, String srs) throws RemoteServiceException {
|
|
268 |
return null;
|
|
269 |
}
|
|
270 |
|
|
271 |
/*
|
|
272 |
* (non-Javadoc)
|
|
273 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#load()
|
|
274 |
*/
|
|
275 |
public RasterProvider load() {
|
|
276 |
return this;
|
|
277 |
}
|
|
278 |
|
|
279 |
/*
|
|
280 |
* (non-Javadoc)
|
|
281 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isOpen()
|
|
282 |
*/
|
|
283 |
public boolean isOpen() {
|
|
284 |
return open;
|
|
285 |
}
|
|
286 |
|
|
287 |
/*
|
|
288 |
* (non-Javadoc)
|
|
289 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close()
|
|
290 |
*/
|
|
291 |
public void close() {
|
|
292 |
open = false;
|
|
293 |
}
|
|
294 |
|
|
295 |
/*
|
|
296 |
* (non-Javadoc)
|
|
297 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency()
|
|
298 |
*/
|
|
299 |
public Transparency getTransparency() {
|
|
300 |
if(fileTransparency == null)
|
|
301 |
fileTransparency = new DataStoreTransparency();
|
|
302 |
return fileTransparency;
|
|
303 |
}
|
|
304 |
|
|
305 |
/*
|
|
306 |
* (non-Javadoc)
|
|
307 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#translateFileName(java.lang.String)
|
|
308 |
*/
|
|
309 |
public String translateFileName(String fileName) {
|
|
310 |
return fileName;
|
|
311 |
}
|
|
312 |
|
|
313 |
/*
|
|
314 |
* (non-Javadoc)
|
|
315 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setView(org.gvsig.fmap.dal.coverage.datastruct.Extent)
|
|
316 |
*/
|
|
317 |
public void setView(Extent e) {
|
|
318 |
viewRequest = e;
|
|
319 |
}
|
|
320 |
|
|
321 |
/*
|
|
322 |
* (non-Javadoc)
|
|
323 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView()
|
|
324 |
*/
|
|
325 |
public Extent getView() {
|
|
326 |
return viewRequest;
|
|
327 |
}
|
|
328 |
|
|
329 |
/*
|
|
330 |
* (non-Javadoc)
|
|
331 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth()
|
|
332 |
*/
|
|
333 |
public double getWidth() {
|
|
334 |
WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
|
|
335 |
try {
|
|
336 |
return getConnector().getWidth(p.getCoverageName());
|
|
337 |
} catch (RemoteServiceException e) {
|
|
338 |
e.printStackTrace();
|
|
339 |
}
|
|
340 |
return 0;
|
|
341 |
}
|
|
342 |
|
|
343 |
/*
|
|
344 |
* (non-Javadoc)
|
|
345 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight()
|
|
346 |
*/
|
|
347 |
public double getHeight() {
|
|
348 |
WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
|
|
349 |
try {
|
|
350 |
return getConnector().getHeight(p.getCoverageName());
|
|
351 |
} catch (RemoteServiceException e) {
|
|
352 |
e.printStackTrace();
|
|
353 |
}
|
|
354 |
return 0;
|
|
355 |
}
|
|
356 |
|
|
357 |
/*
|
|
358 |
* (non-Javadoc)
|
|
359 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#readCompleteLine(int, int)
|
|
360 |
*/
|
|
361 |
public Object readCompleteLine(int line, int band)
|
|
362 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
|
|
363 |
return null;
|
|
364 |
}
|
|
365 |
|
|
366 |
/**
|
|
367 |
* When the remote layer has fixed size this method downloads the file and return its reference.
|
|
368 |
* File layer has in the long side FIXED_SIZE pixels and the bounding box is complete. This file could be
|
|
369 |
* useful to build an histogram or calculate statistics. This represents a sample of data.
|
|
370 |
* @return
|
|
371 |
* @throws RasterDriverException
|
|
372 |
*/
|
|
373 |
public File getFileLayer() throws RasterDriverException {
|
|
374 |
Extent e = getExtent();
|
|
375 |
Rectangle2D bBox = new Rectangle2D.Double(e.getULX(), e.getLRY(), e.width(), e.height());
|
|
376 |
WCSStatus wcsStatus = loadWCSStatus(bBox);
|
|
377 |
|
|
378 |
return downloadFile(wcsStatus, e.getULX(), e.getULY(), e.getLRX(), e.getLRY(),
|
|
379 |
(int)getWidth(), (int)getHeight());
|
|
380 |
}
|
|
381 |
|
|
382 |
/**
|
|
383 |
* Reads a complete block of data and returns an tridimensional array of the right type. This function is useful
|
|
384 |
* to read a file very fast without setting a view. In a WCS service when the size is fixed then it will read the
|
|
385 |
* entire image but when the source hasn't pixel size it will read a sample of data. This set of data will have
|
|
386 |
* the size defined in FIXED_SIZE.
|
|
387 |
*
|
|
388 |
* @param pos Posici?n donde se empieza a leer
|
|
389 |
* @param blockHeight Altura m?xima del bloque leido
|
|
390 |
* @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
|
|
391 |
* @throws InvalidSetViewException
|
|
392 |
* @throws FileNotOpenException
|
|
393 |
* @throws RasterDriverException
|
|
394 |
*/
|
|
395 |
public Object readBlock(int pos, int blockHeight, double scale)
|
|
396 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
|
|
397 |
File lastFile = getFileLayer();
|
|
398 |
BandList bandList = new BandListImpl();
|
|
399 |
for (int i = 0; i < 3; i++) {
|
|
400 |
try {
|
|
401 |
bandList.addBand(new DatasetBandImpl(lastFile.getPath(), pos, Buffer.TYPE_BYTE, 3), pos);
|
|
402 |
} catch (BandNotFoundInListException e1) {
|
|
403 |
}
|
|
404 |
}
|
|
405 |
bandList.setDrawableBands(new int[]{0, 1, 2});
|
|
406 |
|
|
407 |
try {
|
|
408 |
lastRequestProvider = openLastRequest();
|
|
409 |
return lastRequestProvider.readBlock(pos, blockHeight, scale);
|
|
410 |
} catch (ProviderNotRegisteredException exc) {
|
|
411 |
throw new RasterDriverException("Error building GdalDriver", exc);
|
|
412 |
} catch (InitializeException exc) {
|
|
413 |
throw new RasterDriverException("Error building GdalDriver", exc);
|
|
414 |
}
|
|
415 |
}
|
|
416 |
|
|
417 |
/*
|
|
418 |
* (non-Javadoc)
|
|
419 |
* @see org.gvsig.raster.impl.provider.RemoteRasterProvider#getLastRequestHeight()
|
|
420 |
*/
|
|
421 |
public double getLastRequestHeight() throws RasterDriverException {
|
|
422 |
if(lastRequestProvider == null) {
|
|
423 |
try {
|
|
424 |
lastRequestProvider = openLastRequest();
|
|
425 |
} catch (ProviderNotRegisteredException e) {
|
|
426 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
427 |
} catch (InitializeException e) {
|
|
428 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
429 |
}
|
|
430 |
}
|
|
431 |
return lastRequestProvider.getHeight();
|
|
432 |
}
|
|
433 |
|
|
434 |
/*
|
|
435 |
* (non-Javadoc)
|
|
436 |
* @see org.gvsig.raster.impl.provider.RemoteRasterProvider#getLastRequestWidth()
|
|
437 |
*/
|
|
438 |
public double getLastRequestWidth() throws RasterDriverException {
|
|
439 |
if(lastRequestProvider == null) {
|
|
440 |
try {
|
|
441 |
lastRequestProvider = openLastRequest();
|
|
442 |
} catch (ProviderNotRegisteredException e) {
|
|
443 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
444 |
} catch (InitializeException e) {
|
|
445 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
446 |
}
|
|
447 |
}
|
|
448 |
return lastRequestProvider.getWidth();
|
|
449 |
}
|
|
450 |
|
|
451 |
/*
|
|
452 |
* (non-Javadoc)
|
|
453 |
* @see org.gvsig.raster.impl.provider.RemoteRasterProvider#getLastRequest()
|
|
454 |
*/
|
|
455 |
public File getLastRequest() {
|
|
456 |
return lastRequest;
|
|
457 |
}
|
|
458 |
|
|
459 |
/*
|
|
460 |
* (non-Javadoc)
|
|
461 |
* @see org.gvsig.raster.impl.provider.RemoteRasterProvider#getBufferLastRequest()
|
|
462 |
*/
|
|
463 |
public Buffer getBufferLastRequest() throws ProcessInterruptedException, RasterDriverException {
|
|
464 |
try {
|
|
465 |
lastRequestProvider = openLastRequest();
|
|
466 |
|
|
467 |
BandList bandList = new BandListImpl();
|
|
468 |
for (int i = 0; i < lastRequestProvider.getBandCount(); i++) {
|
|
469 |
try {
|
|
470 |
bandList.addBand(new DatasetBandImpl(lastRequest.getPath(), i, Buffer.TYPE_BYTE, 3), i);
|
|
471 |
} catch (BandNotFoundInListException e1) {
|
|
472 |
}
|
|
473 |
}
|
|
474 |
bandList.setDrawableBands(new int[]{0, 1, 2});
|
|
475 |
Buffer newBuffer = DefaultRasterManager.getInstance().createBuffer(lastRequestProvider.getDataType()[0], (int)lastRequestProvider.getWidth(), (int)lastRequestProvider.getHeight(), lastRequestProvider.getBandCount(), true);
|
|
476 |
|
|
477 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
|
|
478 |
q.setAreaOfInterest(lastRequestProvider.getExtent(),
|
|
479 |
(int)lastRequestProvider.getWidth(),
|
|
480 |
(int)lastRequestProvider.getHeight());
|
|
481 |
q.setBandList(bandList);
|
|
482 |
q.setBuffer(newBuffer);
|
|
483 |
q.setAdjustToExtent(true);
|
|
484 |
|
|
485 |
return lastRequestProvider.getDataSet(q);
|
|
486 |
} catch (ProviderNotRegisteredException e) {
|
|
487 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
488 |
} catch (InitializeException e) {
|
|
489 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
490 |
}
|
|
491 |
}
|
|
492 |
|
|
493 |
/**
|
|
494 |
* Opens the last request downloaded
|
|
495 |
* @return
|
|
496 |
* @throws ProviderNotRegisteredException
|
|
497 |
* @throws InitializeException
|
|
498 |
* @throws RasterDriverException
|
|
499 |
*/
|
|
500 |
private DefaultRasterProvider openLastRequest() throws ProviderNotRegisteredException, InitializeException, RasterDriverException {
|
|
501 |
if(lastRequestProvider != null)
|
|
502 |
lastRequestProvider.close();
|
|
503 |
File lastFile = getFileLayer();
|
|
504 |
lastRequestProvider = DefaultProviderServices.loadProvider(new File(lastFile.getPath()));
|
|
505 |
return lastRequestProvider;
|
|
506 |
}
|
|
507 |
|
|
508 |
|
|
509 |
/*
|
|
510 |
* (non-Javadoc)
|
|
511 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int)
|
|
512 |
*/
|
|
513 |
public Object getData(int x, int y, int band)
|
|
514 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
|
|
515 |
return null;
|
|
516 |
}
|
|
517 |
|
|
518 |
/**
|
|
519 |
* Gets the georeferencing file name form a raster file
|
|
520 |
* @param file
|
|
521 |
* a raster file
|
|
522 |
* @return
|
|
523 |
* a georeferencing file
|
|
524 |
*/
|
|
525 |
private String getWorldFile(String file){
|
|
526 |
String worldFile = file;
|
|
527 |
int index = file.lastIndexOf(".");
|
|
528 |
if (index > 0) {
|
|
529 |
worldFile = file.substring(0, index) + getExtensionWorldFile();
|
|
530 |
} else {
|
|
531 |
worldFile = file + getExtensionWorldFile();
|
|
532 |
}
|
|
533 |
return worldFile;
|
|
534 |
}
|
|
535 |
|
|
536 |
/**
|
|
537 |
* Obtiene la extensi?n del fichero de georreferenciaci?n
|
|
538 |
* @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
|
|
539 |
* del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
|
|
540 |
*/
|
|
541 |
private String getExtensionWorldFile() {
|
|
542 |
WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
|
|
543 |
String extWorldFile = ".wld";
|
|
544 |
if(p.getFormat().equals("image/tif") || p.getFormat().equals("image/tiff")) {
|
|
545 |
extWorldFile = ".tfw";
|
|
546 |
}
|
|
547 |
return extWorldFile;
|
|
548 |
}
|
|
549 |
|
|
550 |
private WCSStatus loadWCSStatus(Rectangle2D bBox) {
|
|
551 |
WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
|
|
552 |
WCSStatus wcsStatus = new WCSStatus();
|
|
553 |
wcsStatus.setCoveraName(p.getCoverageName());
|
|
554 |
wcsStatus.setSrs(p.getSRSCode());
|
|
555 |
wcsStatus.setFormat(p.getFormat());
|
|
556 |
wcsStatus.setOnlineResource(p.getOnlineResource() != null ? (String) p.getOnlineResource().get("GetCoverage") : null);
|
|
557 |
wcsStatus.setExtent(bBox);
|
|
558 |
wcsStatus.setHeight(p.getHeight());
|
|
559 |
wcsStatus.setWidth(p.getWidth());
|
|
560 |
wcsStatus.setDepth(p.getDepth());
|
|
561 |
wcsStatus.setParameters(p.getParameter());
|
|
562 |
wcsStatus.setTime(p.getTime());
|
|
563 |
return wcsStatus;
|
|
564 |
}
|
|
565 |
|
|
566 |
/*
|
|
567 |
* (non-Javadoc)
|
|
568 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#needEnhanced()
|
|
569 |
*/
|
|
570 |
public boolean needEnhanced() {
|
|
571 |
return (getDataType()[0] != Buffer.TYPE_BYTE ||
|
|
572 |
(getBandCount() == 1 && getDataType()[0] == Buffer.TYPE_BYTE));
|
|
573 |
}
|
|
574 |
|
|
575 |
/**
|
|
576 |
* This function downloads the file and creates the georeferencing file
|
|
577 |
* @param wcsStatus
|
|
578 |
* @param ulx
|
|
579 |
* @param uly
|
|
580 |
* @param lrx
|
|
581 |
* @param lry
|
|
582 |
* @param w
|
|
583 |
* @param h
|
|
584 |
* @return
|
|
585 |
* @throws RasterDriverException
|
|
586 |
*/
|
|
587 |
private File downloadFile(WCSStatus wcsStatus, double ulx, double uly, double lrx, double lry, int w, int h) throws RasterDriverException {
|
|
588 |
try {
|
|
589 |
lastRequest = getConnector().getCoverage(wcsStatus, ((WCSDataParametersImpl)parameters).getCancellable());
|
|
590 |
} catch (RemoteServiceException e) {
|
|
591 |
throw new RasterDriverException(e.getMessage(), e);
|
|
592 |
}
|
|
593 |
|
|
594 |
String nameWorldFile = getWorldFile(lastRequest.getPath());
|
|
595 |
try {
|
|
596 |
fileUtil.createWorldFile(nameWorldFile, new ExtentImpl(ulx, uly, lrx, lry), w, h);
|
|
597 |
} catch (IOException e) {
|
|
598 |
throw new RasterDriverException("Error downloading file", e);
|
|
599 |
}
|
|
600 |
|
|
601 |
return lastRequest;
|
|
602 |
}
|
|
603 |
|
|
604 |
/**
|
|
605 |
* Assigns the list of bands RGB and read a window of data
|
|
606 |
* @param rasterBuf
|
|
607 |
* @param bandList
|
|
608 |
* @param lastFile
|
|
609 |
* @param ulx
|
|
610 |
* @param uly
|
|
611 |
* @param lrx
|
|
612 |
* @param lry
|
|
613 |
* @return
|
|
614 |
* @throws RasterDriverException
|
|
615 |
* @throws ProcessInterruptedException
|
|
616 |
*/
|
|
617 |
public Buffer getBuffer(Buffer rasterBuf, BandList bandList, File lastFile,
|
|
618 |
double ulx, double uly, double lrx, double lry) throws RasterDriverException, ProcessInterruptedException {
|
|
619 |
try {
|
|
620 |
//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
|
|
621 |
String serverName = bandList.getBand(0).getFileName();
|
|
622 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
623 |
bandList.getBand(i).setFileName(lastFile.getPath());
|
|
624 |
}
|
|
625 |
|
|
626 |
DefaultRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastFile.getPath()));
|
|
627 |
|
|
628 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
|
|
629 |
q.setAreaOfInterest(new ExtentImpl(ulx, uly, lrx, lry));
|
|
630 |
q.setBandList(bandList);
|
|
631 |
q.setBuffer(rasterBuf);
|
|
632 |
|
|
633 |
Buffer buf = driver.getDataSet(q);
|
|
634 |
|
|
635 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
636 |
bandList.getBand(i).setFileName(serverName);
|
|
637 |
}
|
|
638 |
|
|
639 |
return buf;
|
|
640 |
} catch (ProviderNotRegisteredException e) {
|
|
641 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
642 |
} catch (InitializeException e) {
|
|
643 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
644 |
}
|
|
645 |
}
|
|
646 |
|
|
647 |
/*
|
|
648 |
* (non-Javadoc)
|
|
649 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener)
|
|
650 |
*/
|
|
651 |
public void getWindow(Extent ex, int bufWidth, int bufHeight,
|
|
652 |
BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
|
|
653 |
|
|
654 |
Buffer raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, 3, true);
|
|
655 |
getWindow(ex, bufWidth, bufHeight, bandList, raster, true, null);
|
|
656 |
raster.setDataExtent(ex.toRectangle2D());
|
|
657 |
|
|
658 |
TileCacheManager m = TileCacheLocator.getManager();
|
|
659 |
org.gvsig.raster.cache.tile.Tile t = m.createTile(-1, 0, 0);
|
|
660 |
t.setData(new Object[]{raster});
|
|
661 |
t.setUl(new Point2D.Double(ex.getULX(), ex.getULY()));
|
|
662 |
t.setLr(new Point2D.Double(ex.getLRX(), ex.getLRY()));
|
|
663 |
t.setDownloaderParams("AffineTransform", getAffineTransform());
|
|
664 |
t.setDownloaderParams("Tiling", new Boolean(false));
|
|
665 |
try {
|
|
666 |
listener.tileReady(t);
|
|
667 |
} catch (TileGettingException e) {
|
|
668 |
throw new RasterDriverException("Error throwing a tile", e);
|
|
669 |
}
|
|
670 |
|
|
671 |
//listener.nextBuffer(raster, null, new ExtentImpl(minX, minY, maxX, maxY), getAffineTransform(), null, false);
|
|
672 |
listener.endReading();
|
|
673 |
|
|
674 |
}
|
|
675 |
|
|
676 |
/*
|
|
677 |
* (non-Javadoc)
|
|
678 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
|
679 |
*/
|
|
680 |
public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status)
|
|
681 |
throws ProcessInterruptedException, RasterDriverException {
|
|
682 |
Rectangle2D bBox = ex.toRectangle2D();
|
|
683 |
WCSStatus wcsStatus = loadWCSStatus(bBox);
|
|
684 |
|
|
685 |
lastRequest = downloadFile(wcsStatus, ex.getULX(), ex.getULY(), ex.getLRX(), ex.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
|
|
686 |
|
|
687 |
if (lastRequest == null) {
|
|
688 |
return rasterBuf;
|
|
689 |
}
|
|
690 |
|
|
691 |
try {
|
|
692 |
DefaultRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
|
|
693 |
/*bandCount = driver.getBandCount();
|
|
694 |
setDataType(driver.getDataType());
|
|
695 |
rasterBuf = changeBufferDataType(getDataType()[0], rasterBuf, bandList);*/
|
|
696 |
|
|
697 |
//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
|
|
698 |
String serverName = bandList.getBand(0).getFileName();
|
|
699 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
700 |
bandList.getBand(i).setFileName(lastRequest.getPath());
|
|
701 |
}
|
|
702 |
|
|
703 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
|
|
704 |
q.setAreaOfInterest(ex);
|
|
705 |
q.setBandList(bandList);
|
|
706 |
q.setBuffer(rasterBuf);
|
|
707 |
Buffer buf = driver.getDataSet(q);
|
|
708 |
|
|
709 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
710 |
bandList.getBand(i).setFileName(serverName);
|
|
711 |
}
|
|
712 |
driver.close();
|
|
713 |
return buf;
|
|
714 |
} catch (ProviderNotRegisteredException e) {
|
|
715 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
716 |
} catch (InitializeException e) {
|
|
717 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
718 |
}
|
|
719 |
}
|
|
720 |
|
|
721 |
/*
|
|
722 |
* (non-Javadoc)
|
|
723 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
|
|
724 |
*/
|
|
725 |
public Buffer getWindow(double ulx, double uly, double w, double h,
|
|
726 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
|
|
727 |
Rectangle2D bBox = new Rectangle2D.Double(ulx, uly, w, h);
|
|
728 |
WCSStatus wcsStatus = loadWCSStatus(bBox);
|
|
729 |
|
|
730 |
lastRequest = downloadFile(wcsStatus, ulx, uly, ulx + w, uly - h, rasterBuf.getWidth(), rasterBuf.getHeight());
|
|
731 |
|
|
732 |
if (lastRequest == null) {
|
|
733 |
return rasterBuf;
|
|
734 |
}
|
|
735 |
|
|
736 |
try {
|
|
737 |
DefaultRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
|
|
738 |
/*bandCount = driver.getBandCount();
|
|
739 |
setDataType(driver.getDataType());
|
|
740 |
rasterBuf = changeBufferDataType(getDataType()[0], rasterBuf, bandList);*/
|
|
741 |
|
|
742 |
//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
|
|
743 |
String serverName = bandList.getBand(0).getFileName();
|
|
744 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
745 |
bandList.getBand(i).setFileName(lastRequest.getPath());
|
|
746 |
}
|
|
747 |
|
|
748 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
|
|
749 |
q.setAreaOfInterest(ulx, uly, w, h);
|
|
750 |
q.setBandList(bandList);
|
|
751 |
q.setBuffer(rasterBuf);
|
|
752 |
q.setAdjustToExtent(adjustToExtent);
|
|
753 |
|
|
754 |
Buffer buf = driver.getDataSet(q);
|
|
755 |
|
|
756 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
757 |
bandList.getBand(i).setFileName(serverName);
|
|
758 |
}
|
|
759 |
driver.close();
|
|
760 |
return buf;
|
|
761 |
} catch (ProviderNotRegisteredException e) {
|
|
762 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
763 |
} catch (InitializeException e) {
|
|
764 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
765 |
}
|
|
766 |
}
|
|
767 |
|
|
768 |
/*
|
|
769 |
* (non-Javadoc)
|
|
770 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
|
|
771 |
*/
|
|
772 |
public Buffer getWindow(Extent extent, int bufWidth, int bufHeight,
|
|
773 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
|
|
774 |
WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
|
|
775 |
Rectangle2D bBox = null;
|
|
776 |
p.setWidth(bufWidth);
|
|
777 |
p.setHeight(bufHeight);
|
|
778 |
|
|
779 |
/*if(p.getExtent() != null) {
|
|
780 |
bBox = p.getExtent();
|
|
781 |
extent = new ExtentImpl(p.getExtent());
|
|
782 |
} else {*/
|
|
783 |
bBox = extent.toRectangle2D();
|
|
784 |
//}
|
|
785 |
|
|
786 |
//extent.toRectangle2D();//new Rectangle2D.Double(ulx, lry, Math.abs(lrx - ulx), Math.abs(lry - uly));
|
|
787 |
WCSStatus wcsStatus = loadWCSStatus(bBox);
|
|
788 |
lastRequest = downloadFile(wcsStatus, extent.getULX(), extent.getULY(), extent.getLRX(), extent.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
|
|
789 |
|
|
790 |
if (lastRequest == null) {
|
|
791 |
return rasterBuf;
|
|
792 |
}
|
|
793 |
|
|
794 |
try {
|
|
795 |
DefaultRasterProvider driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
|
|
796 |
/*bandCount = driver.getBandCount();
|
|
797 |
setDataType(driver.getDataType());
|
|
798 |
rasterBuf = changeBufferDataType(getDataType()[0], rasterBuf, bandList);*/
|
|
799 |
|
|
800 |
//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
|
|
801 |
String serverName = bandList.getBand(0).getFileName();
|
|
802 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
803 |
bandList.getBand(i).setFileName(lastRequest.getPath());
|
|
804 |
}
|
|
805 |
|
|
806 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
|
|
807 |
q.setAreaOfInterest(extent, bufWidth, bufHeight);
|
|
808 |
q.setBandList(bandList);
|
|
809 |
q.setBuffer(rasterBuf);
|
|
810 |
q.setAdjustToExtent(adjustToExtent);
|
|
811 |
|
|
812 |
Buffer buf = driver.getDataSet(q);
|
|
813 |
|
|
814 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
815 |
bandList.getBand(i).setFileName(serverName);
|
|
816 |
}
|
|
817 |
driver.close();
|
|
818 |
return buf;
|
|
819 |
} catch (ProviderNotRegisteredException e) {
|
|
820 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
821 |
} catch (InitializeException e) {
|
|
822 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
823 |
}
|
|
824 |
}
|
|
825 |
|
|
826 |
/*
|
|
827 |
* (non-Javadoc)
|
|
828 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
|
829 |
*/
|
|
830 |
// public Buffer getWindow(int x, int y,
|
|
831 |
// BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
|
|
832 |
// int w = rasterBuf.getWidth();
|
|
833 |
// int h = rasterBuf.getHeight();
|
|
834 |
// Point2D p1 = rasterToWorld(new Point2D.Double(x, y));
|
|
835 |
// Point2D p2 = rasterToWorld(new Point2D.Double(x + w, y + h));
|
|
836 |
// Rectangle2D bBox = new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p1.getX() - p1.getX()), Math.abs(p1.getY() - p2.getY()));
|
|
837 |
// WCSStatus wcsStatus = loadWCSStatus(bBox);
|
|
838 |
//
|
|
839 |
// lastRequest = downloadFile(wcsStatus, p1.getX(), p1.getY(), p2.getX(), p2.getY(), rasterBuf.getWidth(), rasterBuf.getHeight());
|
|
840 |
//
|
|
841 |
// if (lastRequest == null) {
|
|
842 |
// return rasterBuf;
|
|
843 |
// }
|
|
844 |
//
|
|
845 |
// DefaultRasterProvider driver = null;
|
|
846 |
// try {
|
|
847 |
// driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
|
|
848 |
// /*bandCount = driver.getBandCount();
|
|
849 |
// setDataType(driver.getDataType());
|
|
850 |
// rasterBuf = changeBufferDataType(getDataType()[0], rasterBuf,bandList);*/
|
|
851 |
//
|
|
852 |
// //El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
|
|
853 |
// String serverName = bandList.getBand(0).getFileName();
|
|
854 |
// for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
855 |
// bandList.getBand(i).setFileName(lastRequest.getPath());
|
|
856 |
// }
|
|
857 |
//
|
|
858 |
// Buffer buf = driver.getWindow(0, 0, w, h, rasterBuf.getWidth(), rasterBuf.getHeight(), bandList, rasterBuf);
|
|
859 |
//
|
|
860 |
// for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
861 |
// bandList.getBand(i).setFileName(serverName);
|
|
862 |
// }
|
|
863 |
// driver.close();
|
|
864 |
// return buf;
|
|
865 |
// } catch (ProviderNotRegisteredException e) {
|
|
866 |
// throw new RasterDriverException("Error building GdalDriver", e);
|
|
867 |
// } catch (InitializeException e) {
|
|
868 |
// throw new RasterDriverException("Error building GdalDriver", e);
|
|
869 |
// }
|
|
870 |
// }
|
|
871 |
|
|
872 |
/**
|
|
873 |
* When a WCS provider is opened the information of data type and number of bands is not
|
|
874 |
* available. Only after the first time a raster has been downloaded it can be know.
|
|
875 |
* @param newDataType
|
|
876 |
* @param buf
|
|
877 |
* @param bandList
|
|
878 |
* @return
|
|
879 |
* @throws RasterDriverException
|
|
880 |
*/
|
|
881 |
private void loadInitialInfo() throws RasterDriverException {
|
|
882 |
WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
|
|
883 |
Extent ext = getExtent();
|
|
884 |
Rectangle2D bBox = ext.toRectangle2D();
|
|
885 |
int w = 0;
|
|
886 |
int h = 0;
|
|
887 |
if(ext.width() > ext.height()) {
|
|
888 |
w = 200;
|
|
889 |
h = (int)((ext.height() * w) / ext.width());
|
|
890 |
} else {
|
|
891 |
h = 200;
|
|
892 |
w = (int)((ext.width() * h) / ext.height());
|
|
893 |
}
|
|
894 |
p.setWidth(w);
|
|
895 |
p.setHeight(h);
|
|
896 |
p.setExtent(bBox);
|
|
897 |
WCSStatus wcsStatus = loadWCSStatus(bBox);
|
|
898 |
|
|
899 |
lastRequest = downloadFile(wcsStatus, ext.getULX(), ext.getULY(), ext.getLRX(), ext.getLRY(), w, h);
|
|
900 |
DefaultRasterProvider driver;
|
|
901 |
try {
|
|
902 |
driver = DefaultProviderServices.loadProvider(lastRequest);
|
|
903 |
setDataType(driver.getDataType());
|
|
904 |
bandCount = driver.getBandCount();
|
|
905 |
driver.close();
|
|
906 |
} catch (ProviderNotRegisteredException e) {
|
|
907 |
throw new RasterDriverException("", e);
|
|
908 |
} catch (InitializeException e) {
|
|
909 |
throw new RasterDriverException("", e);
|
|
910 |
}
|
|
911 |
}
|
|
912 |
|
|
913 |
/**
|
|
914 |
* When a WCS provider is opened the information of data type and number of bands is not
|
|
915 |
* available. Only after the first time a raster has been downloaded it can be know.
|
|
916 |
* @param newDataType
|
|
917 |
* @param buf
|
|
918 |
* @param bandList
|
|
919 |
* @return
|
|
920 |
*/
|
|
921 |
/*private Buffer changeBufferDataType(int newDataType, Buffer buf, BandList bandList) {
|
|
922 |
Buffer newBuffer = null;
|
|
923 |
if(buf.getDataType() != newDataType) {
|
|
924 |
newBuffer = DefaultRasterManager.getInstance().createReadOnlyBuffer(newDataType, buf.getWidth(), buf.getHeight(), buf.getBandCount());
|
|
925 |
buf.free();
|
|
926 |
} else
|
|
927 |
return buf;
|
|
928 |
|
|
929 |
bandList.clear();
|
|
930 |
for(int i = 0; i < getBandCount(); i++)
|
|
931 |
try {
|
|
932 |
int dataType = getDataType()[i];
|
|
933 |
DatasetBand band = new DatasetBandImpl(getFName(), i, dataType, getBandCount());
|
|
934 |
bandList.addBand(band, i);
|
|
935 |
} catch(BandNotFoundInListException ex) {
|
|
936 |
//No a?adimos la banda
|
|
937 |
}
|
|
938 |
return newBuffer;
|
|
939 |
}*/
|
|
940 |
|
|
941 |
/*
|
|
942 |
* (non-Javadoc)
|
|
943 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
|
944 |
*/
|
|
945 |
public Buffer getWindow(int x, int y, int w, int h,
|
|
946 |
BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
|
|
947 |
Point2D p1 = rasterToWorld(new Point2D.Double(x, y));
|
|
948 |
Point2D p2 = rasterToWorld(new Point2D.Double(x + w, y + h));
|
|
949 |
Rectangle2D bBox = new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p1.getX() - p1.getX()), Math.abs(p1.getY() - p2.getY()));
|
|
950 |
WCSStatus wcsStatus = loadWCSStatus(bBox);
|
|
951 |
|
|
952 |
lastRequest = downloadFile(wcsStatus, p1.getX(), p1.getY(), p2.getX(), p2.getY(), rasterBuf.getWidth(), rasterBuf.getHeight());
|
|
953 |
|
|
954 |
if (lastRequest == null) {
|
|
955 |
return rasterBuf;
|
|
956 |
}
|
|
957 |
|
|
958 |
DefaultRasterProvider driver = null;
|
|
959 |
try {
|
|
960 |
driver = DefaultProviderServices.loadProvider(new File(lastRequest.getPath()));
|
|
961 |
/*bandCount = driver.getBandCount();
|
|
962 |
setDataType(driver.getDataType());
|
|
963 |
rasterBuf = changeBufferDataType(getDataType()[0], rasterBuf,bandList);*/
|
|
964 |
|
|
965 |
//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
|
|
966 |
String serverName = bandList.getBand(0).getFileName();
|
|
967 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
968 |
bandList.getBand(i).setFileName(lastRequest.getPath());
|
|
969 |
}
|
|
970 |
|
|
971 |
DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
|
|
972 |
q.setAreaOfInterest(0, 0, w, h);
|
|
973 |
q.setBandList(bandList);
|
|
974 |
q.setBuffer(rasterBuf);
|
|
975 |
Buffer buf = driver.getDataSet(q);
|
|
976 |
|
|
977 |
for (int i = 0; i < bandList.getBandCount(); i++) {
|
|
978 |
bandList.getBand(i).setFileName(serverName);
|
|
979 |
}
|
|
980 |
driver.close();
|
|
981 |
return buf;
|
|
982 |
} catch (ProviderNotRegisteredException e) {
|
|
983 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
984 |
} catch (InitializeException e) {
|
|
985 |
throw new RasterDriverException("Error building GdalDriver", e);
|
|
986 |
}
|
|
987 |
}
|
|
988 |
|
|
989 |
/*
|
|
990 |
* (non-Javadoc)
|
|
991 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize()
|
|
992 |
*/
|
|
993 |
public int getBlockSize() {
|
|
994 |
return 0;
|
|
995 |
}
|
|
996 |
|
|
997 |
/*
|
|
998 |
* (non-Javadoc)
|
|
999 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setAffineTransform(java.awt.geom.AffineTransform)
|
|
1000 |
*/
|
|
1001 |
public void setAffineTransform(AffineTransform t){
|
|
1002 |
|
|
1003 |
}
|
|
1004 |
|
|
1005 |
/*
|
|
1006 |
* (non-Javadoc)
|
|
1007 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewCount(int)
|
|
1008 |
*/
|