]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Add SCL interface for District Elevation server 43/3043/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 24 Jul 2019 06:51:14 +0000 (09:51 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 24 Jul 2019 06:51:14 +0000 (09:51 +0300)
gitlab #45

Change-Id: Icef31a8ac3280670f2a36a5354bea8c2dd3f8af7

org.simantics.maps.elevation.server/build.properties
org.simantics.maps.elevation.server/scl/Simantics/District/Elevation.scl [new file with mode: 0644]
org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/SingletonTiffTileInterface.java
org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/TiffInterface.java
org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/TiffTileInterface.java

index 34d2e4d2dad529ceaeb953bfcdb63c51d69ffed2..a4fd10d42b06ab6b214686f7551426f933ad7f76 100644 (file)
@@ -1,4 +1,5 @@
 source.. = src/
 output.. = bin/
 bin.includes = META-INF/,\
-               .
+               .,\
+               scl/
diff --git a/org.simantics.maps.elevation.server/scl/Simantics/District/Elevation.scl b/org.simantics.maps.elevation.server/scl/Simantics/District/Elevation.scl
new file mode 100644 (file)
index 0000000..9edd6da
--- /dev/null
@@ -0,0 +1,4 @@
+
+importJava "org.simantics.maps.elevation.server.SingletonTiffTileInterface" where
+    @JavaName lookupd
+    lookupElevation :: Double -> Double -> <Proc> Double
\ No newline at end of file
index 3fc9616c7080e5210aea4b987bb298945276909a..a8163bb200b3b8c2570ba2408ddbbdddaf65e307 100644 (file)
@@ -26,7 +26,7 @@ public class SingletonTiffTileInterface {
         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;
             }
@@ -39,10 +39,14 @@ public class SingletonTiffTileInterface {
         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();
     }
index 9e0a651407cd71acd1e70e587b8e0395c8a96976..f679762cb8998f221d0f9b7fe44a8608599b9248 100644 (file)
@@ -1,13 +1,17 @@
 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;
@@ -43,6 +47,23 @@ public class TiffInterface {
         }
     }
 
+    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);
index d6f1910e7057efce2c19b6f64e77d64de0c4df2b..b85f234c72d935ef4121877e8d9cc299d73b3fed 100644 (file)
@@ -121,16 +121,19 @@ public class TiffTileInterface {
     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