1 package org.simantics.district.network;
3 import org.geotools.referencing.GeodeticCalculator;
4 import org.opengis.referencing.FactoryException;
5 import org.opengis.referencing.crs.CoordinateReferenceSystem;
6 import org.simantics.databoard.Bindings;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.district.network.ontology.DistrictNetworkResource;
12 public class ModelledCRS implements CRS {
14 private GeodeticCalculator calculator;
16 public ModelledCRS(ReadGraph graph, Resource type) throws DatabaseException, FactoryException {
17 String wkt = graph.getRelatedValue2(type, DistrictNetworkResource.getInstance(graph).HasSRTEXT, Bindings.STRING);
18 CoordinateReferenceSystem crs = org.geotools.referencing.CRS.parseWKT(wkt);
19 this.calculator = new GeodeticCalculator(crs);
23 public double calculateDistance(double[] start, double[] end) {
24 // TODO: fix the scale..
25 calculator.setStartingGeographicPoint(start[0] / 100000, start[1] / 100000);
26 calculator.setDestinationGeographicPoint(end[0] / 100000, end[1] / 100000);
27 return calculator.getOrthodromicDistance();