//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //::: ::: //::: This routine calculates the distance between two points (given the ::: //::: latitude/longitude of those points). It is being used to calculate ::: //::: the distance between two locations using GeoDataSource(TM) products ::: //::: ::: //::: Definitions: ::: //::: South latitudes are negative, east longitudes are positive ::: //::: ::: //::: Passed to function: ::: //::: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) ::: //::: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) ::: //::: unit = the unit you desire for results ::: //::: where: 'M' is statute miles (default) ::: //::: 'K' is kilometers ::: //::: 'N' is nautical miles ::: //::: ::: //::: Worldwide cities and other features databases with latitude longitude ::: //::: are available at https://www.geodatasource.com ::: //::: ::: //::: For enquiries, please contact [email protected] ::: //::: ::: //::: Official Web site: https://www.geodatasource.com ::: //::: ::: //::: GeoDataSource.com (C) All Rights Reserved 2018 ::: //::: ::: //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: public double Distance(double lat1, double lon1, double lat2, double lon2, LenghtUnit lenghtUnit) { if ((-180 > lat1 && lat1 <= 180) || (-180 > lon1 && lon1 <= 180) || (-180 > lat2 && lat2 <= 180) || (-180 > lon2 && lon2 <= 180)) { throw new InvalidArgumentException("Coordinates have negative value"); } if ((lat1 == lat2) && (lon1 == lon2)) { return(0); } else { double theta = lon1 - lon2; double dist = Math.Sin(Deg2Rad(lat1)) * Math.Sin(Deg2Rad(lat2)) + Math.Cos(Deg2Rad(lat1)) * Math.Cos(Deg2Rad(lat2)) * Math.Cos(Deg2Rad(theta)); dist = Math.Acos(dist); dist = Rad2Deg(dist); dist = dist * 60 * 1.1515; if (lenghtUnit == LenghtUnit.Kilometers) { dist = dist * 1.609344; } else if (lenghtUnit == LenghtUnit.NauticalMiles) { dist = dist * 0.8684; } return(dist); } }
//TODO Check consistency/pertinence public static LenghtUnit GetLenghtUnit(string raw) { LenghtUnit result = 0; switch (raw) { case "FT": result = LenghtUnit.Feet; break; case "KM": result = LenghtUnit.Km; break; case "M": result = LenghtUnit.Meter; break; case "NM": result = LenghtUnit.NauticMile; break; case "SM": result = LenghtUnit.StatuteMile; break; default: result = LenghtUnit.Unspecified; break; } return(result); }
static void ConvertUnit() { LenghtUnit inputUnit = new LenghtUnit(); LenghtUnit outputUnit = new LenghtUnit(); Boolean correct = true; do { do { try { Console.WriteLine("Hej skriv enheten du vill byta ifrån? skriv T för tum, C för cm, Y för yard, M för meter, F för fot :) "); char input = char.ToUpper(Convert.ToChar(Console.ReadLine())); inputUnit.InputUnit = input; correct = true; } catch (Exception ex) { Console.WriteLine(ex.Message); correct = false; } } while (correct == false); if (inputUnit.InputUnit == 'T' || inputUnit.InputUnit == 'C' || inputUnit.InputUnit == 'Y' || inputUnit.InputUnit == 'M' || inputUnit.InputUnit == 'F') { correct = true; } else { correct = false; } } while (correct == false); if (inputUnit.InputUnit == 'T') { inputUnit.TumMetod(); } if (inputUnit.InputUnit == 'C') { inputUnit.CmMetod(); } if (inputUnit.InputUnit == 'Y') { inputUnit.YardMetod(); } if (inputUnit.InputUnit == 'M') { inputUnit.MeterMetod(); } if (inputUnit.InputUnit == 'F') { inputUnit.FotMetod(); } }
/// <summary> /// Convert the given Metar.Visibility distance value to desired unit. /// </summary> /// <param name="vis">Visibility.</param> /// <param name="toUnit">Unit to convert the value to.</param> public static Visibility Length(Visibility vis, LenghtUnit toUnit) { //Think make multi vis objects error proof, easy and intuitive! if (vis.Value.HasValue) { vis.Value = Length(vis.Value.Value, vis.Unit, toUnit); } vis.Unit = toUnit; return(vis); }
private void SetUnit() { if (this.DomVisibility != null || !this.DomVisibility.IsUndefined) { this.DomVisibility.Unit = this.Unit; } if (this.MinVisibility != null || !this.MinVisibility.IsUndefined) { this.MinVisibility.Unit = this.Unit; } }
/// <summary> /// Convert the given length/distance/height value to desired unit. /// </summary> /// <param name="value">Value to convert.</param> /// <param name="fromUnit">Value unit.</param> /// <param name="toUnit">Unit to convert the value to.</param> public static double Length(double value, LenghtUnit fromUnit, LenghtUnit toUnit) { switch (fromUnit) { case LenghtUnit.Feet: switch (toUnit) { case LenghtUnit.Km: value *= 0.0003048; break; case LenghtUnit.Meter: value *= 0.3048; break; case LenghtUnit.StatuteMile: value *= 0.0001893939; break; case LenghtUnit.NauticMile: value *= 0.0001645788; break; } break; case LenghtUnit.Km: switch (toUnit) { case LenghtUnit.Feet: value *= 3280.84; break; case LenghtUnit.Meter: value *= 1000; break; case LenghtUnit.StatuteMile: value *= 0.6213712; break; case LenghtUnit.NauticMile: value *= 0.5399565; break; } break; case LenghtUnit.Meter: switch (toUnit) { case LenghtUnit.Feet: value *= 3.28084; break; case LenghtUnit.Km: value *= 0.001; break; case LenghtUnit.StatuteMile: value *= 0.0006213712; break; case LenghtUnit.NauticMile: value *= 0.0005399565; break; } break; case LenghtUnit.StatuteMile: switch (toUnit) { case LenghtUnit.Feet: value *= 5280; break; case LenghtUnit.Km: value *= 1.609344; break; case LenghtUnit.Meter: value *= 1609.344; break; case LenghtUnit.NauticMile: value *= 0.8689758; break; } break; case LenghtUnit.NauticMile: switch (toUnit) { case LenghtUnit.Feet: value *= 6076.118; break; case LenghtUnit.Km: value *= 1.852; break; case LenghtUnit.Meter: value *= 1852; break; case LenghtUnit.StatuteMile: value *= 1.15078; break; } break; } return(value); }
public Visibility(double vis, LenghtUnit unit) { this.Value = vis; this.Unit = unit; }
public async Task <IActionResult> GetDistanceBetweenTwoAirports([FromRoute] string firstAirportCode, [FromRoute] string secondAirportCode, [FromRoute] LenghtUnit unit = LenghtUnit.Miles) { var distance = await _airportService.GetDistanceBetweenAirportsAsync(firstAirportCode, secondAirportCode, unit); return(Ok(new { Value = distance, Unit = unit.ToString() })); }
public async Task <double> GetDistanceBetweenAirportsAsync(string firstAirportCode, string secondAirportCode, LenghtUnit lenghtUnit = LenghtUnit.Miles) { firstAirportCode = firstAirportCode?.ToUpper(); secondAirportCode = secondAirportCode?.ToUpper(); if (!IsAirportCodeValid(firstAirportCode)) { throw new InvalidArgumentException($"'{firstAirportCode}' code is invalid"); } if (!IsAirportCodeValid(secondAirportCode)) { throw new InvalidArgumentException($"'{secondAirportCode}' code is invalid"); } var firstAirport = await GetAirportAsync(firstAirportCode); var secondAirport = await GetAirportAsync(secondAirportCode); var distance = _geoService.Distance( firstAirport.Latitude, firstAirport.Longitude, secondAirport.Latitude, secondAirport.Longitude, lenghtUnit); return(distance); }
public Altitude(double value, LenghtUnit unit) { this.Value = value; this.Unit = unit; }
public void Coordinates_CountDistance_ReturnCorrectResult(double lat1, double lon1, double lat2, double lon2, LenghtUnit lenghtUnit, double distance) { // arrange Init(); // act var result = _geoAppService.Distance(lat1, lon1, lat2, lon2, lenghtUnit); // assert Assert.Equal(result, distance); }
public Length(double len, LenghtUnit lenghtUnit) { this.len = len; this.lenghtUnit = lenghtUnit; }