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