X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2FModelledCRS.java;h=af0bf4182ee70ddd77d109c364fe9391867cee80;hb=b3108a7380f0492ddb40c839c223715d59bbfe9a;hp=fd129ff095e3d86b5a92b0db0b0ab5d44819ef8c;hpb=55f42e7fcc2f6733082ab8c150efe3a2b54ff22b;p=simantics%2Fdistrict.git 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 index fd129ff0..af0bf418 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java +++ b/org.simantics.district.network/src/org/simantics/district/network/ModelledCRS.java @@ -7,24 +7,53 @@ 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; +import org.simantics.layer0.Layer0; 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); + String code = graph.getRelatedValue2(type, Layer0.getInstance(graph).HasLabel, Bindings.STRING); + CoordinateReferenceSystem crs = org.geotools.referencing.CRS.decode(code); + 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(); + calculator.setStartingGeographicPoint(start[0], start[1]); + calculator.setDestinationGeographicPoint(end[0], end[1]); + double dist = calculator.getOrthodromicDistance(); + return dist; } + // TODO: these only work with Spherical Mercator + public static double xToLongitude(double x) { + return x; + } + + public static double yToLatitude(double y) { + double rad = Math.toRadians(y); + double sinh = Math.sinh(rad); + double atan = Math.atan(sinh); + double finald = Math.toDegrees(atan); + return finald; + } + + public static double longitudeToX(double lon) { + return lon; + } + + private static double asinh(double x) { + return Math.log(x + Math.sqrt(x*x + 1.0)); + } + + public static double latitudeToY(double lat) { + double frad = Math.toRadians(lat); + double ftan = Math.tan(frad); + double fsin = asinh(ftan); + double f = Math.toDegrees(fsin); + return f; + } }