【发布时间】:2019-08-09 17:49:15
【问题描述】:
我必须使用 java 和 GeoTools 编写代码来执行 WMS 请求,获取图像并将其保存到我计算机上的特定位置。我已经按照 GeoTools WMS 教程进行了代码编译,没有错误,但我不知道如何检查它是否有效或如何保存请求的图像?
代码如下:
public class WmsConnectorMaven {
public static void main(String[] args) {
URL url = null;
try {
url = new URL("http://ows.mundialis.de/services/service?service=wms&version=1.3.0&request=GetCapabilities");
} catch (MalformedURLException e) {
//will not happen
}
WebMapServer wms = null;
try {
wms = new WebMapServer(url);
GetMapRequest request = wms.createGetMapRequest();
request.addLayer("OSM-Overlay-WMS", "defualt");
request.setFormat("image/png");
request.setDimensions("800", "800"); //sets the dimensions of the image to be returned from the server
request.setTransparent(true);
request.setSRS("EPSG:4326");
request.setBBox("47.75,12.98,47.86,13.12");
GetMapResponse response = (GetMapResponse) wms.issueRequest(request);
BufferedImage image = ImageIO.read(response.getInputStream());
/* File outputfile = new File("saved.png");
ImageIO.write(image, "png", outputfile); */
// FileOutputStream img = new FileOutputStream("C:\\Users\\Edhem\\Desktop\\WMSimage.png");
} catch (IOException e) {
//There was an error communicating with the server
//For example, the server is down
} catch (ServiceException e) {
//The server returned a ServiceException (unusual in this case)
}
}
}
【问题讨论】: