Revision 1083 org.gvsig.raster.wms/trunk/org.gvsig.raster.wms/org.gvsig.raster.wms.io/src/main/java/org/gvsig/raster/wms/io/WMSProvider.java
WMSProvider.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.raster.wms.io; |
23 | 23 |
|
24 |
import java.awt.Image; |
|
24 | 25 |
import java.awt.geom.AffineTransform; |
25 | 26 |
import java.awt.geom.NoninvertibleTransformException; |
26 | 27 |
import java.awt.geom.Point2D; |
... | ... | |
31 | 32 |
import java.util.Hashtable; |
32 | 33 |
import java.util.Vector; |
33 | 34 |
|
35 |
import javax.swing.ImageIcon; |
|
36 |
|
|
34 | 37 |
import org.gvsig.compat.net.ICancellable; |
35 | 38 |
import org.gvsig.fmap.dal.DALLocator; |
36 | 39 |
import org.gvsig.fmap.dal.DataStore; |
... | ... | |
79 | 82 |
import org.gvsig.tools.ToolsLocator; |
80 | 83 |
import org.gvsig.tools.task.Cancellable; |
81 | 84 |
import org.gvsig.tools.task.TaskStatus; |
85 |
import org.slf4j.Logger; |
|
86 |
import org.slf4j.LoggerFactory; |
|
82 | 87 |
/** |
83 | 88 |
* Clase que representa al driver de acceso a datos de wms. |
84 | 89 |
* |
... | ... | |
89 | 94 |
public static String NAME = "Wms Store"; |
90 | 95 |
public static String DESCRIPTION = "Wms Raster file"; |
91 | 96 |
public static final String METADATA_DEFINITION_NAME = "WmsStore"; |
97 |
private static final Logger logger = LoggerFactory.getLogger(WMSProvider.class); |
|
92 | 98 |
private static final int FIXED_SIZE = 800; |
93 | 99 |
private Extent viewRequest = null; |
94 | 100 |
private static Hashtable<String, WMSConnector> |
... | ... | |
192 | 198 |
setDataType(new int[]{Buffer.TYPE_BYTE, Buffer.TYPE_BYTE, Buffer.TYPE_BYTE}); |
193 | 199 |
bandCount = 3; |
194 | 200 |
open = true; |
201 |
try { |
|
202 |
loadInitialInfo(); |
|
203 |
} catch (RasterDriverException e) { |
|
204 |
logger.info("Loaded default values in WMS provider", e); |
|
205 |
} |
|
195 | 206 |
} |
196 | 207 |
|
208 |
/** |
|
209 |
* When a WMS provider is opened the information of data type, number of bands and transparency |
|
210 |
* is not available. Only after the first time a raster has been downloaded it can be know. |
|
211 |
* @param newDataType |
|
212 |
* @param buf |
|
213 |
* @param bandList |
|
214 |
* @return |
|
215 |
* @throws RasterDriverException |
|
216 |
*/ |
|
217 |
private void loadInitialInfo() throws RasterDriverException { |
|
218 |
WMSDataParametersImpl p = (WMSDataParametersImpl)parameters; |
|
219 |
Extent ext = getExtent(); |
|
220 |
Rectangle2D bBox = ext.toRectangle2D(); |
|
221 |
int w = 0; |
|
222 |
int h = 0; |
|
223 |
if(ext.width() > ext.height()) { |
|
224 |
w = 200; |
|
225 |
h = (int)((ext.height() * w) / ext.width()); |
|
226 |
} else { |
|
227 |
h = 200; |
|
228 |
w = (int)((ext.width() * h) / ext.height()); |
|
229 |
} |
|
230 |
p.setWidth(w); |
|
231 |
p.setHeight(h); |
|
232 |
p.setExtent(bBox); |
|
233 |
WMSStatus wmsStatus = loadWMSStatus(bBox); |
|
234 |
|
|
235 |
lastRequest = downloadFile(wmsStatus, ext.getULX(), ext.getULY(), ext.getLRX(), ext.getLRY(), w, h); |
|
236 |
DefaultRasterProvider driver; |
|
237 |
try { |
|
238 |
driver = DefaultProviderServices.loadProvider(lastRequest); |
|
239 |
setDataType(driver.getDataType()); |
|
240 |
bandCount = driver.getBandCount(); |
|
241 |
if(bandCount > 3) { |
|
242 |
getColorInterpretation().setColorInterpValue(3, DataStoreColorInterpretation.ALPHA_BAND); |
|
243 |
getTransparency().setTransparencyBand(3); |
|
244 |
} |
|
245 |
driver.close(); |
|
246 |
} catch (ProviderNotRegisteredException e) { |
|
247 |
throw new RasterDriverException("", e); |
|
248 |
} catch (InitializeException e) { |
|
249 |
throw new RasterDriverException("", e); |
|
250 |
} |
|
251 |
} |
|
252 |
|
|
197 | 253 |
public static final WMSConnector getConnectorFromURL(URL url) throws IOException { |
198 | 254 |
WMSConnector drv = (WMSConnector) drivers.get(url.toString()); |
199 | 255 |
if (drv == null) { |
... | ... | |
949 | 1005 |
} |
950 | 1006 |
} |
951 | 1007 |
|
1008 |
public Image getImageLegend() { |
|
1009 |
try { |
|
1010 |
if (getConnector().hasLegendGraphic()) { |
|
1011 |
WMSStatus wmsStatus = loadWMSStatus(getExtent().toRectangle2D()); |
|
1012 |
wmsStatus.setOnlineResource((String) getParameters().getOnlineResource().get("GetLegendGraphic")); |
|
1013 |
File file = getConnector().getLegendGraphic(wmsStatus, getParameters().getLayerQuery(), null); |
|
1014 |
Image img = null; |
|
1015 |
if ((file != null) && (file.length() > 0)) { |
|
1016 |
img = new ImageIcon(file.getAbsolutePath()).getImage(); |
|
1017 |
} |
|
1018 |
return img; |
|
1019 |
} |
|
1020 |
} catch (Exception e) { |
|
1021 |
logger.info("Problems in GetLegendGraphic", e); |
|
1022 |
} |
|
1023 |
return null; |
|
1024 |
} |
|
1025 |
|
|
952 | 1026 |
/* |
953 | 1027 |
* (non-Javadoc) |
954 | 1028 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize() |
Also available in: Unified diff