public Port(PortId id, string code, string name, string country, GeographicPoint point) : base(id) { this.UNTACD = code; this.Name = name; this.Country = country; this.Position = point; }
public IActionResult GetNearestInterestPoint(GeographicPoint point) { if (!ModelState.IsValid) { return(BadRequest(Json(new { result = "missing or invalid parameters" }))); } return(Ok(Json(_interestPointsService.GetNearestInterestPoint(point)))); }
// more info: https://www.movable-type.co.uk/scripts/latlong.html private int CalculateDistance(InterestPoint point, GeographicPoint currentLocation) { int earthRadiusMeters = (int)6371e3; float firstLatitudeRadians = (float)(currentLocation.latitude * (Math.PI / 180)); float secondLatitudeRadians = (float)(point.latitude * (Math.PI / 180)); float deltaLatitude = (float)((secondLatitudeRadians - firstLatitudeRadians) * (Math.PI / 180)); float deltaLongitude = (float)((point.longitude - currentLocation.longitude) * (Math.PI / 180)); float haversineA = (float)(Math.Sin(deltaLatitude / 2) * Math.Sin(deltaLatitude / 2) + Math.Cos(firstLatitudeRadians) * Math.Cos(secondLatitudeRadians) * Math.Sin(deltaLongitude / 2) * Math.Sin(deltaLongitude / 2)); float haversineC = (float)(2 * Math.Atan2(Math.Sqrt(haversineA), Math.Sqrt(1 - haversineA))); return((int)(earthRadiusMeters * haversineC)); }
private InterestPoint FindNearestPoint(List <InterestPoint> interestPoints, GeographicPoint currentLocation) { int smallestIndex = 0; float smallestDistance = float.MaxValue; int currentDistance; foreach (var item in interestPoints.Select((point, i) => new { i, point })) { currentDistance = CalculateDistance(item.point, currentLocation); if (currentDistance < smallestDistance) { smallestIndex = item.i; smallestDistance = currentDistance; } } return(interestPoints[smallestIndex]); }
static void Main(string[] args) { Random rn = new Random((int)DateTime.Now.Ticks); GeographicPoint[] gp = new GeographicPoint[10]; for (int i = 0; i < gp.Length; i++) { GeographicPoint _gp = new GeographicPoint(rn.Next(0, 10), rn.Next(0, 10), rn.Next(0, 100)); gp[i] = _gp; } GeographicPoint[] wh = new GeographicPoint[2]; for (int i = 0; i < wh.Length; i++) { GeographicPoint _wh = new GeographicPoint(rn.Next(0, 10), rn.Next(0, 10), rn.Next(0, 100)); wh[i] = _wh; } Vehicle[] ven = new Vehicle[3]; ven[0] = new Vehicle { LiftingCapacity = 10 }; ven[1] = new Vehicle { LiftingCapacity = 10 }; ven[2] = new Vehicle { LiftingCapacity = 10 }; RoutingTask rt = new RoutingTask(wh, gp, ven); var v = new RoutingTaskSolver(rt).Solve(); SimpeExample.Execute(); OpenCLTemplate.CLCalc.InitCL(); List <Cloo.ComputeDevice> L = OpenCLTemplate.CLCalc.CLDevices; foreach (object o in L) { Console.WriteLine("\n" + o.ToString()); } SpeedTest(10000); Console.ReadKey(); }
public static GeographicPoint ConvertUtmPointToGeographic(UtmPoint utmPoint, Dataset ds) { SpatialReference monUtm = new SpatialReference(ds.GetProjectionRef()); var geoPoint = new GeographicPoint(); SpatialReference monGeo = new SpatialReference(ds.GetProjectionRef()); monGeo.ImportFromEPSG(4326); double[] res = new double[3]; CoordinateTransformation coordTrans = new CoordinateTransformation(monUtm, monGeo); coordTrans.TransformPoint(res, utmPoint.Easting, utmPoint.Northing, 0); geoPoint.Longitude = res[0]; geoPoint.Latitude = res[1]; return(geoPoint); }
private BoundingBox GetPointBoundingBox(GeographicPoint point) { float kilometersPerDegree = 111; //could be constants float oneKilometerToDegrees = 1 / kilometersPerDegree; float fiveKilometersToDegress = 5 * oneKilometerToDegrees; float smallerLatitude = (float)point.latitude - fiveKilometersToDegress; float largerLatitude = (float)point.latitude + fiveKilometersToDegress; float latitudeToRadians = (float)((Math.PI / 180) * point.latitude); float smallerLongitude = (float)(point.longitude - (fiveKilometersToDegress / Math.Cos(latitudeToRadians))); float largerLongitude = (float)(point.longitude + (fiveKilometersToDegress / Math.Cos(latitudeToRadians))); return(new BoundingBox() { smallerLatitude = smallerLatitude, smallerLongitude = smallerLongitude, largerLatitude = largerLatitude, largerLongitude = largerLongitude }); }
public InterestPoint GetNearestInterestPoint(GeographicPoint point) { BoundingBox boundingBox = GetPointBoundingBox(point); return(FindNearestPoint(_interestPointRepository.GetPointsInsideBoundingBox(boundingBox), point)); }