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(); } }