@Override public double getBinOverlap (TileIndex tile, BinIndex bin, Rectangle2D area) { Rectangle2D binBounds = getBinBounds(tile, bin); // We actually work in lat/lon, so this is what we want. double minx = (area.getMinX()-binBounds.getMinX())/binBounds.getWidth(); double maxx = (area.getMaxX()-binBounds.getMinX())/binBounds.getWidth(); double miny = (area.getMinY()-binBounds.getMinY())/binBounds.getHeight(); double maxy = (area.getMaxY()-binBounds.getMinY())/binBounds.getHeight(); minx = Math.min(Math.max(minx, 0.0), 1.0); maxx = Math.min(Math.max(maxx, 0.0), 1.0); miny = Math.min(Math.max(miny, 0.0), 1.0); maxy = Math.min(Math.max(maxy, 0.0), 1.0); return Math.abs((maxx-minx) * (maxy-miny)); }
@Override public BinIndex rootToBin (Point2D point, TileIndex tile) { return rootToBin(point.getX(), point.getY(), tile); }
@Override public TileIndex rootToTile (double x, double y, int level) { return rootToTile(x, y, level, 256, 256); }
/** * Get the tiling projection used to create the tile pyramid described by * this metadata object. */ public TilePyramid getTilePyramid () { try { String projection = _metaData.getString("projection"); if ("EPSG:4326".equals(projection)) { JSONArray bounds = _metaData.getJSONArray("bounds"); double xMin = bounds.getDouble(0); double yMin = bounds.getDouble(1); double xMax = bounds.getDouble(2); double yMax = bounds.getDouble(3); return new AOITilePyramid(xMin, yMin, xMax, yMax); } else if ("EPSG:900913".equals(projection) || "EPSG:3857".equals(projection)) { return new WebMercatorTilePyramid(); } } catch (JSONException e) { LOGGER.log(Level.WARNING, "Bad projection data in tile pyramid", e); } return null; }
@Test public void getTileBoundsTest() { Rectangle2D tileBounds = _aoi.getTileBounds(_tile); Assert.assertEquals(2.0, tileBounds.getMinX(), EPSILON); Assert.assertEquals(4.0, tileBounds.getMaxX(), EPSILON); Assert.assertEquals(4.0, tileBounds.getMinY(), EPSILON); Assert.assertEquals(6.0, tileBounds.getMaxY(), EPSILON); }
@Override protected TilePyramid create () throws ConfigurationException { String pyramidType = getPropertyValue(PYRAMID_TYPE).toLowerCase(); if ("webmercator".equals(pyramidType) || "epsg:900913".equals(pyramidType) || "epsg:3857".equals(pyramidType)) { return new WebMercatorTilePyramid(); } else if ("areaofinterest".equals(pyramidType) || "epsg:4326".equals(pyramidType)) { double minX = getPropertyValue(MINIMUM_X); double maxX = getPropertyValue(MAXIMUM_X); double minY = getPropertyValue(MINIMUM_Y); double maxY = getPropertyValue(MAXIMUM_Y); return new AOITilePyramid(minX, minY, maxX, maxY); } else { throw new ConfigurationException("Unrecognized pyramid type "+pyramidType); } } }
@Override public TileIndex rootToTile (Point2D point, int level, int xBins, int yBins) { return rootToTile(point.getX(), point.getY(), level, xBins, yBins); }
@Before public void setup () { _pyramid = new AOITilePyramid(0.0, 0.0, 16.0, 16.0); _comparator = new PyramidComparator(_pyramid, 4); _points = new ArrayList<>(8); for (int y = 0; y < 8; ++y) { _points.add(new ArrayList<Point2D>()); for (int x = 0; x < 8; ++x) { _points.get(y).add(new Point2D.Double((double) x, (double) y)); } } _order = Arrays.asList(Arrays.asList(1, 2, 5, 6, 17, 18, 21, 22), Arrays.asList(3, 4, 7, 8, 19, 20, 23, 24), Arrays.asList(9, 10, 13, 14, 25, 26, 29, 30), Arrays.asList(11, 12, 15, 16, 27, 28, 31, 32), Arrays.asList(33, 34, 37, 38, 49, 50, 53, 54), Arrays.asList(35, 36, 39, 40, 51, 52, 55, 56), Arrays.asList(41, 42, 45, 46, 57, 58, 61, 62), Arrays.asList(43, 44, 47, 48, 59, 60, 63, 64)); }
@Test public void getBinBoundsTest() { Rectangle2D binBounds = _aoi.getBinBounds(_tile, _bin); Assert.assertEquals(3.5000000, binBounds.getMinX(), EPSILON); Assert.assertEquals(3.5078125, binBounds.getMaxX(), EPSILON); Assert.assertEquals(5.5000000, binBounds.getMinY(), EPSILON); Assert.assertEquals(5.5078125, binBounds.getMaxY(), EPSILON); } }
@Test public void rooToBinTest() { BinIndex bin = _aoi.rootToBin(_point, _tile); Assert.assertEquals(_bin, bin); }
@Override public TileIndex rootToTile (Point2D point, int level) { return rootToTile(point.getX(), point.getY(), level, 256, 256); }
@Test public void rooToTileTest() { TileIndex tile = _aoi.rootToTile(_point, 3); Assert.assertEquals(_tile, tile); }