package org.simantics.maps.elevation.server;
import java.awt.geom.Rectangle2D;
+import java.io.Closeable;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.index.strtree.STRtree;
-public class TiffTileInterface {
+public class TiffTileInterface implements Closeable {
private static final Logger LOGGER = LoggerFactory.getLogger(TiffTileInterface.class);
private Path tilesFolder;
+ private Map<Path, Envelope> envelopes = new ConcurrentHashMap<>();
private LoadingCache<Path, TiffInterface> interfaceCache;
private int openInterfacesSize;
private STRtree index;
});
}
- private Map<Path, Envelope> envelopes = new ConcurrentHashMap<>();
-
public Collection<Rectangle2D> getBoundingBoxes() {
Collection<Rectangle2D> rects = envelopes.values().stream().map(env -> {
double x = env.getMinX();
}
public Number lookup(double x, double y) {
- LOGGER.info("Looking up x={} y={}", x, y);
+ LOGGER.trace("Looking up x={} y={}", x, y);
DirectPosition p = new DirectPosition2D(c4326, x, y);
List<Path> tifFiles = (List<Path>) index.query(new Envelope(new Coordinate(x, y)));
for (Path tifFile : tifFiles) {
}
return new Double(0); // use 0 by default for now
}
+
+ @Override
+ public void close() throws IOException {
+ interfaceCache.invalidateAll();
+ interfaceCache.cleanUp();
+
+ envelopes.clear();
+ envelopes = null;
+ index = null;
+ interfaceCache = null;
+ }
}
\ No newline at end of file