Search in sources :

Example 1 with GetMapResponse

use of org.geotools.data.wms.response.GetMapResponse in project polymap4-core by Polymap4.

the class WmsRenderProcessor method getMapRequest.

@Override
public void getMapRequest(GetMapRequest request, ProcessorContext context) throws Exception {
    int width = request.getWidth();
    int height = request.getHeight();
    BoundingBox bbox = request.getBoundingBox();
    log.debug("bbox=" + bbox + ", imageSize=" + width + "x" + height);
    org.geotools.data.wms.request.GetMapRequest getMap = wms.createGetMapRequest();
    getMap.setFormat(request.getFormat());
    getMap.setDimensions(width, height);
    getMap.setTransparent(true);
    Color color = request.getBgColor();
    if (color != null) {
        getMap.setBGColour(String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue()));
    }
    setBBox(getMap, bbox);
    getMap.setSRS(request.getCRS());
    getMap.addLayer(layer);
    // log.info( "    WMS URL:" + getMap.getFinalURL() );
    InputStream in = null;
    try {
        long start = System.currentTimeMillis();
        GetMapResponse wmsResponse = wms.issueRequest(getMap);
        log.debug("Got repsonse (" + (System.currentTimeMillis() - start) + "ms). providing data: " + wmsResponse.getContentType());
        in = wmsResponse.getInputStream();
        int count = 0;
        byte[] buf = new byte[4 * 1024];
        for (int c = in.read(buf); c != -1; c = in.read(buf)) {
            context.sendResponse(new EncodedImageResponse(buf, c));
            buf = new byte[8 * 1024];
            log.debug("    ---> data sent: " + c);
            count += c;
        }
        if (count == 0) {
            throw new IOException("WMSResponse is empty.");
        }
        context.sendResponse(ProcessorResponse.EOP);
        log.debug("...all data send.");
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : InputStream(java.io.InputStream) Color(java.awt.Color) IOException(java.io.IOException) GetMapResponse(org.geotools.data.wms.response.GetMapResponse) EncodedImageResponse(org.polymap.core.data.image.EncodedImageResponse) BoundingBox(org.opengis.geometry.BoundingBox)

Aggregations

Color (java.awt.Color)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 GetMapResponse (org.geotools.data.wms.response.GetMapResponse)1 BoundingBox (org.opengis.geometry.BoundingBox)1 EncodedImageResponse (org.polymap.core.data.image.EncodedImageResponse)1