1

I am trying to mock GetMap requests and had an issue on how to create valid BBox values for the requests so they would HIT the cached layer. I got an answer from Ian Turton How properly calculate BBox for mocked GetMap request? on how to calculate valid BBox but I. However I need to automate this process and parsing WMTS capabilities document is not what I would like to do. Ian's suggested usage of WMTS instead of WMS has a drawback - I need to know rows and columns for each zoom level I want to hit and I want to hit specific area only. I see no easy way to automate correct zoom level/column/row combination selection. What I think is the best way to generate correct BBox parameters for GetMap requests is to call org.geotools.data.wmts.client.WMTSTileFactory.findTileAtCoordinate(...) with the random coordinates I can easily generate. Later I would get ReferencedEnvelope from the Tile and would ask for the lower and upper corner coords and that would be it but... findTileAtCoordinate(...) needs parameter of type org.geotools.tile.TileService and in order to create WMTSTileService object I need to pass a bunch of parameters among which is org.geotools.data.wmts.model.TileMatrixSet. Now I don't want to manually parse WMTS capabilities document to create TileMatrixSet object. I would expect there should be a way to create service which needs only GeoServer address and a layer name so it could fetch all the data about layer (BoundingBox, EPSGCode, TileMatrixSet and so on) so I could pass them to WMTSTileFactory.findTileAtCoordinate(...). Is there a such service? Maybe I am doing wrong approach?

1

IIRC (and I was supposed to document this last year) you need to create a WMSTSTileService which takes the base URL of the server. You can then either issue a getTiles request or grab the TileMatrixSet from it using getTileMatrixSet().

    String serverURL="http://localhost:8080/geoserver/gwc/service/wmts?"
    WebMapTileServer wmts = new WebMapTileServer(serverURL);
    WMTSCapabilities capabilities = wmts.getCapabilities();
    WMTSLayer layer = (WMTSLayer) capabilities.getLayer("topp:states");

    request.setLayer(layer);

    request.setRequestedWidth(800);
    request.setRequestedHeight(400);

    String format = "image/png";
    List<String> formats = layer.getFormats();

    if (!formats.contains("image/png")) {
        format = (String) formats.get(0);
    }
    request.setFormat(format);

    ReferencedEnvelope re = new ReferencedEnvelope(-180, 180, -90, 90, CRS.decode("EPSG:4326"));
    request.setRequestedBBox(re);

    // System.out.println(request.getFinalURL());
    Set<Tile> responses = (Set<Tile>) wmts.issueRequest(request);

    for (Tile response : responses) {
        // System.out.println("Content Type: " + response.getContentType());
        // System.out.println(response.getTileIdentifier());
        BufferedImage image = response.getBufferedImage();
        //do what ever you want with the image.
    }
  • Is it possible to get capabilities of a single layer (without removing "Advertised" flag for unwanted layers)? I am asking this because when current capabilities document is being parsed I get Parsing failed for MinTileRow: java.lang.IllegalArgumentException: Value '-3' must be non-negative (0 or above). I have checked - a number of layers have negative values for MinTileRow in the current capabilities document. – user435421 Jan 8 '18 at 7:44
  • that sounds like a bug on the server, negative tile numbers seem to make no sense. But, no there is no way to get layer info without parsing the whole capabilities document. – Ian Turton Jan 8 '18 at 8:34
  • Uh, one problem after another..... – user435421 Jan 8 '18 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.