private File getXDir (String basePath, TileIndex tile) { return new File(String.format("%s/" + PyramidIO.TILES_FOLDERNAME + "/%d/%d/", _rootPath + basePath, tile.getLevel(), tile.getX() )); }
@Override public void encodeJSON (JSONNode propertyNode, TileIndex value) throws JSONException { JSONObject result = new JSONObject(); result.put("level", value.getLevel()); result.put("xIndex", value.getX()); result.put("yIndex", value.getY()); result.put("xBinCount", value.getXBins()); result.put("yBinCount", value.getYBins()); propertyNode.setAsJSONObject(result); }
@Override public BinIndex rootToBin (Point2D point, TileIndex tile) { Point2D tileMercator = rootToTileMercator(point, tile.getLevel()); return new BinIndex((int) Math.floor((tileMercator.getX()-tile.getX())*tile.getXBins()), tile.getYBins()-1-(int) Math.floor((tileMercator.getY()-tile.getY())*tile.getYBins())); }
private Point getTileCoordinates (double x, double y) { Point2D point = new Point2D.Double(x, y); TileIndex tile = _pyramid.rootToTile(point, _level); return new Point(tile.getX(), tile.getY()); }
@Override public BinIndex rootToBin (double x, double y, TileIndex tile) { Point2D tileMercator = rootToTileMercator(x, y, tile.getLevel()); return new BinIndex((int) Math.floor((tileMercator.getX()-tile.getX())*tile.getXBins()), tile.getYBins()-1-(int) Math.floor((tileMercator.getY()-tile.getY())*tile.getYBins())); }
private File getTileFile (String basePath, TileIndex tile) { return new File(String.format("%s/" + PyramidIO.TILES_FOLDERNAME + "/%d/%d/%d." + _extension, _rootPath + basePath, tile.getLevel(), tile.getX(), tile.getY())); }
private Point getBinCoordinates (double x, double y) { Point2D point = new Point2D.Double(x, y); TileIndex tile = _pyramid.rootToTile(point, _level); if (tile.getXBins() != _numXBins && tile.getYBins() != _numYBins) { tile = new TileIndex(tile.getLevel(), tile.getX(), tile.getY(), _numXBins, _numYBins); } BinIndex bin = _pyramid.rootToBin(point, tile); return new Point(tile.getX()*tile.getXBins()+bin.getX(), tile.getY()*tile.getYBins()+(tile.getYBins()-1-bin.getY())); }
@Override protected InputStream getSourceTileStream(String basePath, TileIndex tile) { String tileLocation = String.format("%s/"+PyramidIO.TILES_FOLDERNAME+"/%d/%d/%d." + _extension, _rootPath + basePath, tile.getLevel(), tile.getX(), tile.getY()); return ResourcePyramidSource.class.getResourceAsStream(tileLocation); }
@Override public Rectangle2D getBinBounds(TileIndex tile, BinIndex bin) { long pow2 = 1L << tile.getLevel(); double tileXSize = (_maxX-_minX)/pow2; double tileYSize = (_maxY-_minY)/pow2; double binXSize = tileXSize/tile.getXBins(); double binYSize = tileYSize/tile.getYBins(); int adjustedBinY = tile.getYBins()-1-bin.getY(); return new Rectangle2D.Double(_minX+tileXSize*tile.getX()+binXSize*bin.getX(), _minY+tileYSize*tile.getY()+binYSize*adjustedBinY, binXSize, binYSize); }
@Override protected InputStream getSourceTileStream(String basePath, TileIndex tile) { String location = String.format( "http://" + _host + "/%s/" + PyramidIO.TILES_FOLDERNAME + "/%d/%d/%d." + _extension, basePath, tile.getLevel(), tile.getX(), tile.getY()); try { return new URL(location).openStream(); } catch (MalformedURLException e){ LOGGER.error("Malformed URL supplied", e); return null; } catch (IOException e){ return null; } }
@Override public Rectangle2D getBinBounds (TileIndex tile, BinIndex bin) { int level = tile.getLevel(); double binXInc = 1.0/tile.getXBins(); double baseX = tile.getX()+bin.getX()*binXInc; double binYInc = 1.0/tile.getYBins(); double baseY = tile.getY()+(tile.getYBins()-1-bin.getY())*binYInc; double north = tileToLat(baseY + binYInc, level); double south = tileToLat(baseY, level); double east = tileToLon(baseX + binXInc, level); double west = tileToLon(baseX, level); return new Rectangle2D.Double(west, south, east-west, north-south); }
@Override public Rectangle2D getTileBounds (TileIndex tile) { long pow2 = 1L << tile.getLevel(); double tileXSize = (_maxX-_minX)/pow2; double tileYSize = (_maxY-_minY)/pow2; return new Rectangle2D.Double(_minX+tileXSize*tile.getX(), _minY+tileYSize*tile.getY(), tileXSize, tileYSize); }
@Test public void testSimpleTwoLevels () { SubTileDataView<Integer> underTest = SubTileDataView.fromSourceAbsolute(source16, new TileIndex(2, 1, 1)); Assert.assertEquals(2, underTest.getDefinition().getLevel()); Assert.assertEquals(1, underTest.getDefinition().getX()); Assert.assertEquals(1, underTest.getDefinition().getY()); Assert.assertEquals(1, underTest.getDefinition().getXBins()); Assert.assertEquals(1, underTest.getDefinition().getYBins()); Assert.assertEquals(9, (int)underTest.getBin(0,0)); }
/** * Determine the row ID we use in HBase for a given tile index */ public static String rowIdFromTileIndex (TileIndex tile) { // Use the minimum possible number of digits for the tile key int digits = (int) Math.floor(Math.log10(1 << tile.getLevel()))+1; return String.format("%02d,%0"+digits+"d,%0"+digits+"d", tile.getLevel(), tile.getX(), tile.getY()); }
@Test public void testSimple () { SubTileDataView<Integer> underTest = SubTileDataView.fromSourceAbsolute(source16, new TileIndex(1, 1, 1)); Assert.assertEquals(1, underTest.getDefinition().getLevel()); Assert.assertEquals(1, underTest.getDefinition().getX()); Assert.assertEquals(1, underTest.getDefinition().getY()); Assert.assertEquals(2, underTest.getDefinition().getXBins()); Assert.assertEquals(2, underTest.getDefinition().getYBins()); Assert.assertEquals(2, (int)underTest.getBin(0,0)); Assert.assertEquals(7, (int)underTest.getBin(1,1)); }
@Override public <T> List<TileData<T>> readTiles (String pyramidId, TileSerializer<T> serializer, Iterable<TileIndex> tiles) throws IOException { List<TileData<T>> results = new ArrayList<>(); for (TileIndex rawIndex: tiles) { TileIndex index = new TileIndex(rawIndex.getLevel(), rawIndex.getX(), rawIndex.getY(), 1, 1); TileData<T> tile = new DenseTileData<>(index); results.add(tile); } return results; }
@Override public <T> InputStream getTileStream (String pyramidId, TileSerializer<T> serializer, TileIndex rawIndex) throws IOException { TileIndex index = new TileIndex(rawIndex.getLevel(), rawIndex.getX(), rawIndex.getY(), 1, 1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); serializer.serialize(new DenseTileData<T>(index), baos); return new ByteArrayInputStream(baos.toByteArray()); }
@Override public Rectangle2D getTileBounds (TileIndex tile) { int level = tile.getLevel(); double north = tileToLat(tile.getY()+1, level); double south = tileToLat(tile.getY(), level); double east = tileToLon(tile.getX()+1, level); double west = tileToLon(tile.getX(), level); return new Rectangle2D.Double(west, south, east-west, north-south); }
@Override protected InputStream getSourceTileStream (String basePath, TileIndex tile) throws IOException { String tileLocation = String.format("%s/"+PyramidIO.TILES_FOLDERNAME+"/%d/%d/%d." + _tileExtension, basePath, tile.getLevel(), tile.getX(), tile.getY()); ZipArchiveEntry entry = _tileSetArchive.getEntry(tileLocation); return _tileSetArchive.getInputStream(entry); }
private void read() { TileIndex tile = getRandomTile(); long start = System.currentTimeMillis(); List<AnnotationData<?>> scan = readTile( tile ); long end = System.currentTimeMillis(); double time = ((end-start)/1000.0); LOGGER.debug( "Thread " + _name + " read " + scan.size() + " entries from " + tile.getLevel() + ", " + tile.getX() + ", " + tile.getY() + " in " + time + " sec" ); }