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