]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java
Lots of changes to district stuff
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / ModelledCRS.java
diff --git a/org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java b/org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java
new file mode 100644 (file)
index 0000000..fd129ff
--- /dev/null
@@ -0,0 +1,30 @@
+package org.simantics.district.network;
+
+import org.geotools.referencing.GeodeticCalculator;
+import org.opengis.referencing.FactoryException;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+
+public class ModelledCRS implements CRS {
+
+    private GeodeticCalculator calculator;
+
+    public ModelledCRS(ReadGraph graph, Resource type) throws DatabaseException, FactoryException {
+        String wkt = graph.getRelatedValue2(type, DistrictNetworkResource.getInstance(graph).HasSRTEXT, Bindings.STRING);
+        CoordinateReferenceSystem crs = org.geotools.referencing.CRS.parseWKT(wkt);
+        this.calculator = new GeodeticCalculator(crs);
+    }
+    
+    @Override
+    public double calculateDistance(double[] start, double[] end) {
+        // TODO: fix the scale..
+        calculator.setStartingGeographicPoint(start[0] / 100000, start[1] / 100000);
+        calculator.setDestinationGeographicPoint(end[0] / 100000, end[1] / 100000);
+        return calculator.getOrthodromicDistance();
+    }
+
+}