/** * @param info * @param files * @param rasters * @param options */ public DiskBasedTileContainer( QTreeInfo info, List<File> files, List<AbstractRaster> rasters, RasterIOOptions options) { qtree = new QTree<File>(createEnvelope(info.envelope), info.numberOfObjects); envelope = info.envelope; AbstractRaster raster = rasters.iterator().next(); rasterDataInfo = raster.getRasterDataInfo(); rasterGeoReference = info.rasterGeoReference; resolutionInfo = raster.getResolutionInfo(); this.options = options; Iterator<File> iter = files.iterator(); for (AbstractRaster r : rasters) { File f = iter.next(); qtree.insert(createEnvelope(r.getEnvelope()), f); cache.put(f, new SoftReference<AbstractRaster>(r)); } initialized = true; }
public List<AbstractRaster> getTiles(Envelope env) { List<File> files = qtree.query(createEnvelope(env)); List<AbstractRaster> result = new ArrayList<AbstractRaster>(files.size()); for (File f : files) { SoftReference<AbstractRaster> ref = cache.get(f); AbstractRaster raster = ref == null ? null : ref.get(); if (raster != null) { result.add(raster); } else { try { result.add(raster = loadRasterFromFile(f, options)); cache.put(f, new SoftReference<AbstractRaster>(raster)); } catch (IOException e) { LOG.debug("Raster file '{}' could not be loaded: '{}'.", f, e.getLocalizedMessage()); LOG.trace("Stack trace:", e); } } } return result; }