Package org.geotools.data.wms.request

Examples of org.geotools.data.wms.request.GetMapRequest


    public void testIssueGetMapRequest() throws Exception {
        WebMapServer wms = new WebMapServer(serverURL);

        WMSCapabilities capabilities = wms.getCapabilities();

        GetMapRequest request = wms.createGetMapRequest();

        //request.setVersion("1.1.1");

        Layer[] layers = WMSUtils.getNamedLayers(capabilities);
        Iterator iter = Arrays.asList(layers).iterator();
        int count = -1;
        while (iter.hasNext()) {

            Layer layer = (Layer) iter.next();
            count++;
            if (count >= 5) {
                break;
            }
                       
            List styles = layer.getStyles();

            if (styles.size() == 0) {
                request.addLayer(layer);
                continue;
            }

            Random random = new Random();
            int randomInt = random.nextInt(styles.size());
           
            request.addLayer(layer, (StyleImpl) styles.get(randomInt));
        }

        Set srss = WMSUtils.getSRSs(capabilities);
        request.setSRS((String) srss.iterator().next());
        request.setDimensions("400", "400");

        String format = "image/gif";
        List formats = wms.getCapabilities().getRequest().getGetMap().getFormats();
        if (!formats.contains("image/gif")) {
            format = (String) formats.get(0);
        }
        request.setFormat(format);

        request.setBBox("366800,2170400,816000,2460400");

        //System.out.println(request.getFinalURL());
        GetMapResponse response = (GetMapResponse) wms.issueRequest(request);

        assertEquals(response.getContentType(), format);
View Full Code Here


        assertEquals(envelope.getMaximum(1), 89.8254, 0.0);
    }
   
    public void testServiceExceptions  () throws Exception {
      WebMapServer wms = new WebMapServer(featureURL);
      GetMapRequest request = wms.createGetMapRequest();
      request.addLayer("NoLayer", "NoStyle");
      try {
        //System.out.println(request.getFinalURL());
        GetMapResponse response = wms.issueRequest(request);
        assertTrue(false);
      } catch (ServiceException e) {
View Full Code Here

            }
        }


        out.print("Performing GetMap operation...");
        GetMapRequest request = wms.createGetMapRequest();
       
        request.addLayer(layer);
        CRSEnvelope bbox = layer.getLatLonBoundingBox();
        request.setBBox(bbox);
        request.setFormat(format);
        request.setSRS("EPSG:4326");
        request.setDimensions("100","100");

        try {
            GetMapResponse response = wms.issueRequest(request);
            out.println("received a response.");

            out.print("Checking returned format...");
            if (response.getContentType().indexOf(format) == -1) {
                out.println("server returned bad format. Expected "+format+", got "+response.getContentType()+".");
                passed = false;
            } else {
                out.println("passed.");
            }

            out.print("Checking dimensions...");
            BufferedImage image = ImageIO.read(response.getInputStream());
            if (image == null) {
              out.println("returned a bad image. ContentType is "+response.getContentType());
              passed = false;
            } else if (image.getWidth() != 100 || image.getHeight() != 100) {
                out.println("server returned bad dimensions. Expect 100, 100. Returned "+image.getWidth()+","+image.getHeight());
                passed = false;
            } else {
                out.println("passed.");
            }
        } catch (ServiceException e) {
            out.println("failed.");
            passed = false;
            while (e != null) {
                if (e.getLocator() != null && e.getLocator().length() != 0) {
                    out.println("ServiceException at "+e.getLocator()+": "+e.getMessage()+"("+e.getCode()+")");
                }
                out.println("ServiceException: "+e.getMessage()+"("+e.getCode()+")");
                e = e.getNext();
            }
        } catch (IOException e) {
            out.println("failed.");
            passed = false;
            out.println("IOException: "+e.getMessage());
            e.printStackTrace(out);
        } catch (SAXException e) {
            out.println("failed.");
            passed = false;
            out.println("SAXException: "+e.getMessage());
            e.printStackTrace(out);
        } finally {
            out.println(request.getFinalURL());
        }

//        if (caps.getRequest().getGetFeatureInfo() != null) {
//            out.println("");
//            out.println("Server supports GetFeatureInfo requests. Beginning tests.");
View Full Code Here

            }
        } catch (Exception e) {
            throw new IOException("Could not reproject the request envelope", e);
        }

        GetMapRequest mapRequest = wms.createGetMapRequest();
        // for some silly reason GetMapRequest will list the layers in the opposite order...
        List<Layer> reversed = new ArrayList<Layer>(layers);
        Collections.reverse(reversed);
        for (Layer layer : reversed) {
            mapRequest.addLayer(layer);
        }
        mapRequest.setDimensions(width, height);
        mapRequest.setFormat(format);
        if(backgroundColor == null) {
            mapRequest.setTransparent(true);
        } else {
            String rgba = Integer.toHexString(backgroundColor.getRGB());
            String rgb = rgba.substring(2, rgba.length());
            mapRequest.setBGColour("0x" + rgb.toUpperCase());
            mapRequest.setTransparent(backgroundColor.getAlpha() < 255);
        }

        try {
            this.requestCRS = CRS.decode(requestSrs);
        } catch(Exception e) {
            throw new IOException("Could not decode request SRS " + requestSrs);
        }
       
        ReferencedEnvelope requestEnvelope = gridEnvelope;
        mapRequest.setBBox(requestEnvelope);
        mapRequest.setSRS(requestSrs);
       
        this.mapRequest = mapRequest;
        this.requestedEnvelope = gridEnvelope;
        this.width = width;
        this.height = height;
View Full Code Here

     * @throws IOException
     */
    public String getFeatureInfoAsText(DirectPosition2D pos, int featureCount) throws IOException {
        BufferedReader br = null;
        try {
            GetMapRequest mapRequest = getReader().mapRequest;
            InputStream is = getReader().getFeatureInfo(pos, "text/plain", featureCount, mapRequest);
            br = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuilder sb = new StringBuilder();
            while ((line = br.readLine()) != null) {
View Full Code Here

     * @return
     * @throws IOException
     */
    public InputStream getFeatureInfo(DirectPosition2D pos, String infoFormat, int featureCount)
            throws IOException {
        GetMapRequest mapRequest = getReader().mapRequest;
        return getReader().getFeatureInfo(pos, infoFormat, featureCount, mapRequest);
    }
View Full Code Here

            at.inverseTransform(screenPos, worldPos);
            DirectPosition2D fromPos = new DirectPosition2D(worldPos.getX(), worldPos.getY());
            DirectPosition2D toPos = new DirectPosition2D();
            MathTransform mt = CRS.findMathTransform(bbox.getCoordinateReferenceSystem(), getReader().requestCRS, true);
            mt.transform(fromPos, toPos);
            GetMapRequest mapRequest = getReader().mapRequest;
            return getReader().getFeatureInfo(toPos, infoFormat, featureCount, mapRequest);
        } catch(IOException e) {
            throw e;
        } catch(Throwable t) {
            throw (IOException) new IOException("Unexpected issue during GetFeatureInfo execution").initCause(t);
View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void testNoSideEffectsOnGetFinalUrl() throws Exception {
        GetMapRequest request = new org.geotools.data.wms.WMS1_0_0().createGetMapRequest(new URL("http://test?"));
        SecuredGetMapRequest securedRequest = new SecuredGetMapRequest(request);
        Layer wmsLayer = new Layer();
        wmsLayer.setName("layer1");
        Layer layer = new SecuredWMSLayer(wmsLayer, WrapperPolicy.hide(null));
        securedRequest.addLayer(layer);
View Full Code Here

TOP

Related Classes of org.geotools.data.wms.request.GetMapRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.