01: package org.geotools.demo.example;
02:
03: import java.net.URL;
04: import java.util.Iterator;
05:
06: import org.geotools.data.ows.CRSEnvelope;
07: import org.geotools.data.ows.Layer;
08: import org.geotools.data.ows.WMSCapabilities;
09: import org.geotools.data.wms.WebMapServer;
10: import org.geotools.data.wms.request.GetMapRequest;
11: import org.geotools.data.wms.response.GetMapResponse;
12:
13: /**
14: * This example also works against a local geoserver.
15: *
16: * @author Jody Garnett
17: */
18: public class WMSExample {
19:
20: public static void main(String args[]) {
21: try {
22: localWMS();
23: } catch (Exception ignore) {
24: ignore.printStackTrace();
25: }
26: }
27:
28: public static void localWMS() throws Exception {
29: URL url = new URL(
30: "http://localhost:8080/geoserver/wms?REQUEST=GetCapabilities");
31: WebMapServer wms = new WebMapServer(url);
32:
33: WMSCapabilities caps = wms.getCapabilities();
34:
35: Layer layer = null;
36: for (Iterator i = caps.getLayerList().iterator(); i.hasNext();) {
37: Layer test = (Layer) i.next();
38: if (test.getName() != null && test.getName().length() != 0) {
39: layer = test;
40: break;
41: }
42: }
43: GetMapRequest mapRequest = wms.createGetMapRequest();
44: mapRequest.addLayer(layer);
45:
46: mapRequest.setDimensions("400", "400");
47: mapRequest.setFormat("image/png");
48:
49: CRSEnvelope bbox = new CRSEnvelope("EPSG:4326", -100.0, -70,
50: 25, 40);
51: mapRequest.setBBox(bbox);
52:
53: System.out.println(mapRequest.getFinalURL());
54:
55: GetMapResponse response = wms.issueRequest(mapRequest);
56: System.out.println(response.getContentType());
57: }
58: }
|