source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ scl/
--- /dev/null
+
+importJava "org.simantics.maps.elevation.server.SingletonTiffTileInterface" where
+ @JavaName lookupd
+ lookupElevation :: Double -> Double -> <Proc> Double
\ No newline at end of file
Path tilesFolder = Paths.get("tifsFolder");
if (TIFS_FOLDER != null) {
Path potTilesFolder = Paths.get(TIFS_FOLDER);
- if (!Files.exists(potTilesFolder)) {
+ if (Files.exists(potTilesFolder)) {
// use default from working directory
tilesFolder = potTilesFolder;
}
tileInterface = new TiffTileInterface(tilesFolder);
}
+ public static double lookupd(double x, double y) {
+ return lookup(x, y).doubleValue();
+ }
+
public static Number lookup(double x, double y) {
return instance.tileInterface.lookup(x, y);
}
-
+
public static Collection<Rectangle2D> getBoundingBoxes() {
return instance.tileInterface.getBoundingBoxes();
}
package org.simantics.maps.elevation.server;
+import java.awt.geom.Point2D;
import java.awt.image.DataBuffer;
import java.nio.file.Path;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.geometry.Envelope2D;
+import org.geotools.geometry.TransformedDirectPosition;
import org.opengis.geometry.DirectPosition;
+import org.opengis.geometry.Envelope;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.operation.TransformException;
import org.simantics.maps.elevation.server.prefs.MapsElevationServerPreferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
}
+ public boolean contains(DirectPosition pos) {
+ ensureInit();
+ Envelope2D e = coverage.getEnvelope2D();
+ try {
+ TransformedDirectPosition tdp = new TransformedDirectPosition(pos.getCoordinateReferenceSystem(), crs, null);
+ tdp.transform(pos);
+
+ Point2D p = tdp.toPoint2D();
+
+ boolean contains = e.contains(p);
+ return contains;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ return false;
+ }
+ }
+
public Number lookup(DirectPosition pos) {
ensureInit();
Object r = coverage.evaluate(pos);
public Number lookup(double x, double y) {
LOGGER.info("Looking up x={} y={}", x, y);
DirectPosition p = new DirectPosition2D(c4326, x, y);
- List<Path> tifFile = (List<Path>) index.query(new Envelope(new Coordinate(x, y)));
- if (!tifFile.isEmpty()) {
- TiffInterface tifInterface = openTifInterface(tifFile.get(0));
- try {
- return tifInterface.lookup(p);
- } finally {
- tifInterface.close();
+ List<Path> tifFiles = (List<Path>) index.query(new Envelope(new Coordinate(x, y)));
+ for (Path tifFile : tifFiles) {
+ TiffInterface tifInterface = openTifInterface(tifFile);
+ if (tifInterface.contains(p)) {
+ try {
+ return tifInterface.lookup(p);
+ } finally {
+ tifInterface.close();
+ }
+ } else {
+ System.out.println("not found");
}
- } else {
- return new Double(0); // use 0 by default for now
}
+ return new Double(0); // use 0 by default for now
}
}
\ No newline at end of file