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