Package org.geotools.data.wms.request

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


        }
        String desiredFormat = desiredInfoFormat( wms );               
        if( desiredFormat == null ){
            return null;
        }
        GetMapRequest getmap = wms.createGetMapRequest();       
        String code = BasicWMSRenderer2.findRequestCRS(
                Collections.singletonList( wmslayer ), map.getViewportModel().getCRS(), map );

        getmap.setBBox( bbox );
        String srs = CRS.toSRS(bbox.getCoordinateReferenceSystem() );
        //getmap.setSRS( code != null ? code : srs );
       
        getmap.setProperty( GetMapRequest.LAYERS, wmslayer.getName() );
        int width = map.getRenderManager().getMapDisplay().getWidth();
        int height = map.getRenderManager().getMapDisplay().getHeight();
        getmap.setDimensions(width, height);
        //getmap.setSRS(code);
       
        List<String> formats = wms.getCapabilities().getRequest().getGetMap().getFormats();
        if (formats.contains("image/png")) { //$NON-NLS-1$
            getmap.setProperty(GetMapRequest.FORMAT, "image/png"); //$NON-NLS-1$
        } else if (formats.contains("image/gif")) { //$NON-NLS-1$
            getmap.setProperty(GetMapRequest.FORMAT, "image/gif"); //$NON-NLS-1$
        } else if (formats.contains("image/jpeg")) { //$NON-NLS-1$
            getmap.setProperty(GetMapRequest.FORMAT, "image/jpeg"); //$NON-NLS-1$
        } else if (formats.contains("image/bmp")) { //$NON-NLS-1$
            getmap.setProperty(GetMapRequest.FORMAT, "image/bmp"); //$NON-NLS-1$
        }
       
        StyleImpl wmsStyle = (StyleImpl) layer.getStyleBlackboard().get(WMSStyleContent.WMSSTYLE);
        if (wmsStyle != null) {
            getmap.setProperty(GetMapRequest.STYLES, wmsStyle.getName());
        }
        else {
            // supply an empty String as per UDIG-1507
            getmap.setProperty(GetMapRequest.STYLES, "");
        }
       
        final GetFeatureInfoRequest request = wms.createGetFeatureInfoRequest( getmap );                      
        request.setInfoFormat( desiredFormat );
        request.setQueryPoint( centre.x, centre.y );               
View Full Code Here


            getContext().setStatus(ILayer.WAIT);

            WebMapServer wms = getWMS();
           
            GetMapRequest request = wms.createGetMapRequest();
           
            // put in default exception format we understand as a client
            // (if suppoted by the server)
            WMSCapabilities capabilities = wms.getCapabilities();
            if( capabilities.getRequest().getGetMap().getFormats().contains(GetMapRequest.EXCEPTION_XML) ){
                request.setExceptions(GetMapRequest.EXCEPTION_XML);
            }
            setImageFormat(wms, request);

            if (monitor.isCanceled())
                return;

            double currScale = getContext().getViewportModel().getScaleDenominator();
            List<ILayer> layers = getLayers();
            for( int i = layers.size() - 1; i >= 0; i-- ) {
                ILayer ilayer = layers.get(i);
                Layer layer;
                double minScale = 0;
                double maxScale = Double.MAX_VALUE;
                layer = ilayer.getResource(org.geotools.data.ows.Layer.class, null);
                // check if there are min/max scale rules
                StyleBlackboard sb = (StyleBlackboard) ilayer.getStyleBlackboard();
                Style style = (Style) sb.lookup(Style.class);
                if (style != null) {
                    Rule rule = style.getFeatureTypeStyles()[0].getRules()[0];
                    minScale = rule.getMinScaleDenominator();
                    maxScale = rule.getMaxScaleDenominator();
                }

                if (currScale >= minScale && currScale <= maxScale) {
                    // check for a wms style
                    StyleImpl wmsStyle = (StyleImpl) ilayer.getStyleBlackboard().get(
                            WMSStyleContent.WMSSTYLE);
                    if (wmsStyle != null) {
                        request.addLayer(layer, wmsStyle);
                    } else {
                        request.addLayer(layer);
                    }
                }
            }

            if (monitor.isCanceled())
                return;

            List<Layer> wmsLayers = getWMSLayers();
            if (wmsLayers == null || wmsLayers.isEmpty()){
                endLayerStatus = ILayer.WARNING;
                return;
            }
           
            // figure out request CRS
            CoordinateReferenceSystem viewportCRS = getViewportCRS();
            IMap map = getContext().getMap();
           
            String requestCRScode = findRequestCRS(wmsLayers, viewportCRS, map);
           
            // TODO: make findRequestCRS more efficient (we are running CRS.decode at *least* twice)
            CoordinateReferenceSystem requestCRS = CRS.decode(requestCRScode);

            // figure out viewport
//            ReferencedEnvelope viewport;
//            Envelope viewportBBox = getViewportBBox();
//            CoordinateReferenceSystem viewportCRS = getViewportCRS();
//            if (viewportBBox == null) {
//                // change viewport to world
//                viewportBBox = new Envelope(-180, 180, -90, 90);
//                if (!DefaultGeographicCRS.WGS84.equals(viewportCRS)) { // reproject
//                    viewport = new ReferencedEnvelope(viewportBBox, DefaultGeographicCRS.WGS84);
//                    viewportBBox = viewport.transform(viewportCRS, true);
//                }
//            }


            ReferencedEnvelope requestBBox = null;
            Envelope backprojectedBBox = null; // request bbox projected to the viewport crs
//            viewport = new ReferencedEnvelope(viewportBBox, viewportCRS);
//            requestBBox = calculateRequestBBox(wmsLayers, viewport, requestCRS);
           
            requestBBox = calculateRequestBBox(wmsLayers, bounds, requestCRS, capabilities.getVersion() );

            // check that a request is needed (not out of a bounds, invalid, etc)
            if (requestBBox == NILL_BOX) {
                endLayerStatus = ILayer.WARNING;
                return;
            }
            assert requestBBox.getCoordinateReferenceSystem().equals(requestCRS);

            if (requestBBox.getCoordinateReferenceSystem().equals(viewportCRS)) {
                backprojectedBBox = (Envelope) requestBBox;
            } else {
                backprojectedBBox = (Envelope) requestBBox.transform(viewportCRS, true);
            }

            if (WMSPlugin.isDebugging(Trace.RENDER)) {
                WMSPlugin.trace("Viewport CRS: " + viewportCRS.getName()); //$NON-NLS-1$
                WMSPlugin.trace("Request CRS: " + requestCRS.getName()); //$NON-NLS-1$
                WMSPlugin.trace("Context Image bounds: " + getContext().getImageBounds()); //$NON-NLS-1$
                WMSPlugin.trace("Request BBox  bounds: " + requestBBox); //$NON-NLS-1$
                WMSPlugin.trace("Backprojected request bounds: " + backprojectedBBox); //$NON-NLS-1$
            }

            Service wmsService = capabilities.getService();
            Dimension maxDimensions = new Dimension(wmsService.getMaxWidth(), wmsService
                    .getMaxHeight());
//            Dimension imageDimensions = calculateImageDimensions(getContext().getMapDisplay()
//                    .getDisplaySize(), maxDimensions, getViewportBBox(), backprojectedBBox);
            Dimension imageDimensions = calculateImageDimensions(getContext().getImageSize(), maxDimensions, bounds, backprojectedBBox);
            if (imageDimensions.height < 1 || imageDimensions.width < 1) {
                endLayerStatus = ILayer.WARNING;
                return;
            }
            request.setDimensions(imageDimensions.width + "", imageDimensions.height + ""); //$NON-NLS-1$ //$NON-NLS-2$
            // epsg could be under identifiers or authority.
            Set<ReferenceIdentifier> identifiers = requestCRS.getIdentifiers();
            String srs = identifiers.isEmpty() ? EPSG_4326 : identifiers.iterator().next().toString();           
            request.setSRS(srs); // EPSG_4326
            request.setBBox( requestBBox );
            // request.setBBox(requestBBox.getMinX() + "," + requestBBox.getMinY()+ "," + requestBBox.getMaxX()+ "," + requestBBox.getMaxY());
           
            if (monitor.isCanceled())
                return;

View Full Code Here

    public static URI makeWmsGetLayerRequest(final MfClientHttpRequestFactory requestFactory,
                                             final WmsLayerParam wmsLayerParam,
                                             final URI commonURI,
                                             final Dimension imageSize,
                                             final ReferencedEnvelope bounds) throws FactoryException, URISyntaxException, IOException {
        final GetMapRequest getMapRequest = WmsVersion.lookup(wmsLayerParam.version).getGetMapRequest(commonURI.toURL());
        getMapRequest.setBBox(bounds);
        getMapRequest.setDimensions(imageSize.width, imageSize.height);
        getMapRequest.setFormat(wmsLayerParam.imageFormat);
        getMapRequest.setSRS(CRS.lookupIdentifier(bounds.getCoordinateReferenceSystem(), false));

        for (int i = 0; i < wmsLayerParam.layers.length; i++) {
            String layer = wmsLayerParam.layers[i];
            String style = "";
            if (wmsLayerParam.styles != null) {
                style = wmsLayerParam.styles[i];
            }
            getMapRequest.addLayer(layer, style);
        }
        final URI getMapUri = getMapRequest.getFinalURL().toURI();

        Multimap<String, String> extraParams = HashMultimap.create();
        extraParams.putAll(wmsLayerParam.getMergeableParams());
        extraParams.putAll(wmsLayerParam.getCustomParams());
        return URIUtils.addParams(getMapUri, extraParams, Collections.<String>emptySet());
View Full Code Here

        CRSEnvelope latLon = layer.getLatLonBoundingBox();
        GeneralEnvelope envelope = wms.getEnvelope(layer, crs);
        assertFalse(envelope.isEmpty() || envelope.isNull() || envelope.isInfinite());
        assertNotNull("Envelope "+CRS.toSRS(crs), envelope);

        GetMapRequest getMap = wms.createGetMapRequest();
        OperationType operationType = wms.getCapabilities().getRequest().getGetMap();

        getMap.addLayer(layer);
        String version = wms.getCapabilities().getVersion();
       
        getMap.setBBox(envelope);
       
        Properties properties = getMap.getProperties();
        String srs = null;
        if( properties.containsKey("SRS")){
            srs = properties.getProperty("SRS");
        }
        else if( properties.containsKey("CRS")){
            srs = properties.getProperty("CRS");
        }
        assertNotNull( "setBBox supplied SRS information", srs );
        String expectedSRS = CRS.toSRS(envelope.getCoordinateReferenceSystem());
        assertEquals( "srs matches CRS.toSRS", expectedSRS, srs );
       
        assertTrue( "cite authority:"+srs, srs.contains("CRS") || srs.contains("EPSG") );
       
        //getMap.setSRS( srs );
       
        String format = format(operationType, "jpeg");
        getMap.setFormat(format);
        getMap.setDimensions(500, 500);

        URL url = getMap.getFinalURL();
        GetMapResponse response = wms.issueRequest(getMap);
        assertEquals("image/jpeg", response.getContentType());

        InputStream stream = response.getInputStream();
        BufferedImage image = ImageIO.read(stream);
View Full Code Here

        CRSEnvelope latLon = layer.getLatLonBoundingBox();
        GeneralEnvelope envelope = wms.getEnvelope(layer, crs);
        assertFalse(envelope.isEmpty() || envelope.isNull() || envelope.isInfinite());
        assertNotNull("Envelope "+CRS.toSRS(crs), envelope);
   
        GetMapRequest getMap = wms.createGetMapRequest();
        OperationType operationType = wms.getCapabilities().getRequest().getGetMap();

        getMap.addLayer(layer);
        String version = wms.getCapabilities().getVersion();
        String srs = CRS.toSRS(envelope.getCoordinateReferenceSystem());
        getMap.setBBox(envelope);
        String format = format(operationType, "jpeg");
        getMap.setFormat(format);
        getMap.setDimensions(500, 500);
        URL url = getMap.getFinalURL();
       
        GetFeatureInfoRequest getFeatureInfo = wms.createGetFeatureInfoRequest( getMap );
        getFeatureInfo.setInfoFormat("text/html");
        getFeatureInfo.setQueryLayers( Collections.singleton(layer));
        getFeatureInfo.setQueryPoint( 75100 );
View Full Code Here

   
    public void testCreateGetMapRequest() throws Exception {
        try{
            WebMapServer wms = new WebMapServer(server);
            WMSCapabilities caps = wms.getCapabilities();
            GetMapRequest request = wms.createGetMapRequest();
            request.setFormat("image/jpeg");
            //System.out.println(request.getFinalURL().toExternalForm());
           
            String externalForm = request.getFinalURL().toExternalForm();
            assertTrue(externalForm.indexOf("image%2Fjpeg") >= 0);
        } catch(java.net.ConnectException ce){
            if(ce.getMessage().indexOf("timed out")>0){
                System.err.println("Unable to test - timed out: "+ce);
            } else{
View Full Code Here

public class AbstractGetMapRequestTest extends TestCase {

  public void testGetFinalURL() throws Exception {
    URL badURL = new URL("http://test.com/map.php?LAYERS=Provincial Boundary");
   
    GetMapRequest request = new RequestTestHelp(badURL, null);
   
    request.addLayer("Provincial Boundary", "Two words");
    request.addLayer("Layer2", "");
   
    URL finalURL = request.getFinalURL();
        //System.out.println(finalURL);
    String processedURL = finalURL.toExternalForm();
    assertTrue(processedURL.indexOf("LAYERS=Layer2,Provincial+Boundary") != -1);
    assertTrue(processedURL.indexOf("STYLES=,Two+words") != -1);
        assertTrue(processedURL.indexOf("SERVICE=WMS") != -1);
View Full Code Here

          e.printStackTrace();
        }
    }
    public void testCreateGetMapRequest() throws Exception {
        WebMapServer wms = new WebMapServer(server2);
        GetMapRequest request = wms.createGetMapRequest();
        request.setFormat("image/jpeg");
        System.out.println(request.getFinalURL().toExternalForm());
       
        assertTrue(request.getFinalURL().toExternalForm().indexOf("image%2Fjpeg") >= 0);
    }
View Full Code Here

            WebMapServer wms = getCustomWMS(featureURL);
            WMSCapabilities caps = wms.getCapabilities();
            assertNotNull(caps);
            assertNotNull(caps.getRequest().getGetFeatureInfo());
           
            GetMapRequest getMapRequest = wms.createGetMapRequest();
           
            getMapRequest.setProperty(GetMapRequest.LAYERS, "ETOPO2:Foundation");
//        List simpleLayers = getMapRequest.getAvailableLayers();
//        Iterator iter = simpleLayers.iterator();
//        while (iter.hasNext()) {
//                SimpleLayer simpleLayer = (SimpleLayer) iter.next();
//                Object[] styles = simpleLayer.getValidStyles().toArray();
//                if (styles.length == 0) {
//                        simpleLayer.setStyle("");
//                        continue;
//                }
//                Random random = new Random();
//                int randomInt = random.nextInt(styles.length);
//                simpleLayer.setStyle((String) styles[randomInt]);
//        }
//        getMapRequest.setLayers(simpleLayers);
           
            getMapRequest.setSRS("EPSG:4326");
            getMapRequest.setDimensions("400", "400");
            getMapRequest.setFormat("image/png");
//        http://demo.cubewerx.com/cipi12/cubeserv/cubeserv.cgi?INFO_FORMAT=text/html&LAYERS=ETOPO2:Foundation&FORMAT=image/png&HEIGHT=400&J=200&REQUEST=GetFeatureInfo&I=200&BBOX=-34.12087,15.503481,1.8462441,35.6043956&WIDTH=400&STYLES=&SRS=EPSG:4326&QUERY_LAYERS=ETOPO2:Foundation&VERSION=1.3.0
            getMapRequest.setBBox("-34.12087,15.503481,1.8462441,35.6043956");
            URL url2 = getMapRequest.getFinalURL();
           
            GetFeatureInfoRequest request = wms.createGetFeatureInfoRequest(getMapRequest);
//        request.setQueryLayers(request.getQueryableLayers());
            request.setProperty(GetFeatureInfoRequest.QUERY_LAYERS, "ETOPO2:Foundation");
            request.setQueryPoint(200, 200);
View Full Code Here

   
    public void testCreateGetMapRequest() throws Exception {
        try{
            CustomWMS wms = new CustomWMS(server);
            WMSCapabilities caps = wms.getCapabilities();
            GetMapRequest request = wms.createGetMapRequest();
            request.setFormat("image/jpeg");
            System.out.println(request.getFinalURL().toExternalForm());
           
            assertTrue(request.getFinalURL().toExternalForm().indexOf("jpeg") >= 0);
        } catch(java.net.ConnectException ce){
            if(ce.getMessage().indexOf("timed out")>0){
                System.err.println("Unable to test - timed out: "+ce);
            } else{
                throw(ce);
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.