@Override public void validate(IValidatable<List<Grid>> validatable) { ValidationError error = new ValidationError(); List<Grid> grids = validatable.getValue(); if (grids == null || grids.size() == 0) { error.setMessage(new ResourceModel("TileMatrixSetEditor.validation.empty").getObject()); validatable.error(error); return; } for (int i = 1; i < grids.size(); i++) { Grid prev = grids.get(i - 1); Grid curr = grids.get(i); if (curr.getResolution() >= prev.getResolution()) { String message = "Each resolution should be lower than it's prior one. Res[" + i + "] == " + curr.getResolution() + ", Res[" + (i - 1) + "] == " + prev.getResolution() + "."; error.setMessage(message); validatable.error(error); return; } if (curr.getScaleDenominator() >= prev.getScaleDenominator()) { String message = "Each scale denominator should be lower " + "than it's prior one. Scale[" + i + "] == " + curr.getScaleDenominator() + ", Scale[" + (i - 1) + "] == " + prev.getScaleDenominator() + "."; error.setMessage(message); validatable.error(error); return; } } }
Integer findClosestZoom(GridSet gridSet, WMSMapContent map) { double reqScale = RendererUtilities.calculateOGCScale(bounds(map), gridSet.getTileWidth(), null); int i = 0; double error = Math.abs(gridSet.getGrid(i).getScaleDenominator() - reqScale); while (i < gridSet.getNumLevels() - 1) { Grid g = gridSet.getGrid(i + 1); double e = Math.abs(g.getScaleDenominator() - reqScale); if (e > error) { break; } else { error = e; } i++; } return Math.max(i, 0); }
private void tileMatrix( StringBuilder str, Grid grid, double[] tlCoordinates, int tileWidth, int tileHeight, boolean scaleWarning) { str.append(" <TileMatrix>\n"); if (scaleWarning) { str.append( " <ows:Abstract>The grid was not well-defined, the scale therefore assumes 1m per map unit.</ows:Abstract>"); } str.append(" <ows:Identifier>" + grid.getName() + "</ows:Identifier>\n"); str.append(" <ScaleDenominator>" + grid.getScaleDenominator() + "</ScaleDenominator>\n"); str.append( " <TopLeftCorner>" + tlCoordinates[0] + " " + tlCoordinates[1] + "</TopLeftCorner>\n"); str.append(" <TileWidth>" + tileWidth + "</TileWidth>\n"); str.append(" <TileHeight>" + tileHeight + "</TileHeight>\n"); str.append(" <MatrixWidth>" + grid.getNumTilesWide() + "</MatrixWidth>\n"); str.append(" <MatrixHeight>" + grid.getNumTilesHigh() + "</MatrixHeight>\n"); str.append(" </TileMatrix>\n"); }
public void addZoomLevel(ReferencedEnvelope bbox, int tileWidth, int tileHeight) { List<Grid> list = grids.getModelObject(); final Grid newGrid = new Grid(); if (list.isEmpty()) { BoundingBox extent = new BoundingBox(bbox.getMinX(), bbox.getMinY(), bbox.getMaxX(), bbox.getMaxY()); final int levels = 1; GridSet tmpGridset = GridSetFactory.createGridSet( "stub", SRS.getEPSG4326(), extent, false, levels, 1D, GridSetFactory.DEFAULT_PIXEL_SIZE_METER, tileWidth, tileHeight, false); Grid grid = tmpGridset.getGridLevels()[0]; newGrid.setResolution(grid.getResolution()); newGrid.setScaleDenominator(grid.getScaleDenominator()); } else { Grid prev = list.get(list.size() - 1); newGrid.setResolution(prev.getResolution() / 2); newGrid.setScaleDenominator(prev.getScaleDenominator() / 2); } list.add(newGrid); grids.setModelObject(list); // TileMatrixSetEditor.this.convertInput(); }
void addTileLayers(GeoPackage geopkg, List<MapLayerInfo> mapLayers, WMSMapContent map) throws IOException { if (mapLayers.isEmpty()) { return; } // figure out a name for the file entry String tileEntryName = null; Map formatOpts = map.getRequest().getFormatOptions(); if (formatOpts.containsKey("tileset_name")) { tileEntryName = (String) formatOpts.get("tileset_name"); } if (tileEntryName == null) { tileEntryName = map.getTitle(); } if (tileEntryName == null && mapLayers.size() == 1) { Iterator<MapLayerInfo> it = mapLayers.iterator(); tileEntryName = it.next().getLayerInfo().getName(); } GridSubset gridSubset = findBestGridSubset(map); int[] minmax = findMinMaxZoom(gridSubset, map); BoundingBox bbox = bbox(map); TileEntry e = new TileEntry(); e.setTableName(tileEntryName); if (mapLayers.size() == 1) { ResourceInfo r = mapLayers.get(0).getResource(); e.setIdentifier(r.getTitle()); e.setDescription(r.getAbstract()); } e.setBounds( new ReferencedEnvelope( findTileBounds(gridSubset, bbox, minmax[0]), map.getCoordinateReferenceSystem())); e.setSrid(srid(map)); GridSet gridSet = gridSubset.getGridSet(); for (int z = minmax[0]; z < minmax[1]; z++) { Grid g = gridSet.getGrid(z); TileMatrix m = new TileMatrix(); m.setZoomLevel(z); m.setMatrixWidth((int) g.getNumTilesWide()); m.setMatrixHeight((int) g.getNumTilesHigh()); m.setTileWidth(gridSubset.getTileWidth()); m.setTileHeight(gridSubset.getTileHeight()); // TODO: not sure about this m.setXPixelSize(g.getResolution()); m.setYPixelSize(g.getResolution()); // m.setXPixelSize(gridSet.getPixelSize()); // m.setYPixelSize(gridSet.getPixelSize()); e.getTileMatricies().add(m); } // figure out the actual bounds of the tiles to be renderered LOGGER.fine("Creating tile entry" + e.getTableName()); geopkg.create(e); // create a prototype getmap request GetMapRequest req = new GetMapRequest(); OwsUtils.copy(map.getRequest(), req, GetMapRequest.class); req.setLayers(mapLayers); String imageFormat = formatOpts.containsKey("format") ? parseFormatFromOpts(formatOpts) : findBestFormat(map); req.setFormat(imageFormat); req.setWidth(gridSubset.getTileWidth()); req.setHeight(gridSubset.getTileHeight()); // count tiles as we generate them int ntiles = 0; // flag determining if tile row indexes we store in database should be inverted boolean flipy = Boolean.valueOf((String) formatOpts.get("flipy")); for (int z = minmax[0]; z < minmax[1]; z++) { long[] intersect = gridSubset.getCoverageIntersection(z, bbox); for (long x = intersect[0]; x <= intersect[2]; x++) { for (long y = intersect[1]; y <= intersect[3]; y++) { BoundingBox box = gridSubset.boundsFromIndex(new long[] {x, y, z}); req.setBbox(new Envelope(box.getMinX(), box.getMaxX(), box.getMinY(), box.getMaxY())); Tile t = new Tile(); t.setZoom(z); t.setColumn((int) x); t.setRow((int) (flipy ? gridSubset.getNumTilesHigh(z) - (y + 1) : y)); WebMap result = webMapService.getMap(req); t.setData(toBytes(result)); geopkg.add(e, t); // images we encode are actually kept around, we need to clean them up if (ntiles++ == TILE_CLEANUP_INTERVAL) { cleanUpImages(); ntiles = 0; } } } } }