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