/// <summary> /// 获取指定速度下行驶时长后线中的点 /// </summary> /// <param name="localtions">线路中的点</param> /// <param name="startLocation">当前点</param> /// <param name="speed">速度,单位km/h</param> /// <param name="interval">间隔时间,单位s</param> /// <param name="nextIndex">下一个关键点的索引</param> /// <returns></returns> public static LocationDto GetNextLation(List <LocationDto> localtions, LocationDto startLocation, double speed, int interval, ref int nextIndex) { var logger = Jt808TerminalEmulator.Core.DependencyInjectionExtensions.ServiceProvider.CreateScope().ServiceProvider.GetRequiredService <ILogger <LocationInterpolation> >(); if (nextIndex >= localtions.Count) { return(null); } var intervalDistance = speed / 3.6 * interval; var nextDistance = intervalDistance; for (; nextIndex < localtions.Count;) { var distance = LocationInterpolation.CalculateDistanceBetweenLocations(startLocation, localtions[nextIndex]); if (distance < nextDistance) { nextDistance -= distance; startLocation = localtions[nextIndex]; nextIndex++; continue; } var endLocation = LocationInterpolation.IntermediaryLocation(startLocation, localtions[nextIndex], nextDistance); distance = LocationInterpolation.CalculateDistanceBetweenLocations(endLocation, localtions[nextIndex]); logger.LogInformation($"当前索引:{nextIndex},差值{distance}起点[{startLocation.Logintude},{startLocation.Latitude}]终点,[{endLocation.Logintude},{endLocation.Latitude}],第{localtions[nextIndex].Order}个关键点[{localtions[nextIndex].Logintude},{localtions[nextIndex].Latitude}]"); return(endLocation); } return(default);
/// <summary> /// 重新插值 /// </summary> /// <param name="dto">线路</param> /// <param name="speed">速度</param> /// <param name="interval">间隔时间</param> /// <param name="alldistance">线路总长度,单位m</param> /// <returns></returns> public static List <LocationDto> Reinterpolation(LineDto dto, double speed, int interval, out double alldistance) { var intervalDistance = speed / 3.6 * interval; alldistance = 0d; var locations = new List <LocationDto> { dto.Locations.First() }; var nextDistance = intervalDistance; var startLocation = locations.Last(); for (int i = 1; i < dto.Locations.Count - 1; i++) { var endLocation = dto.Locations[i]; alldistance += LocationInterpolation.CalculateDistanceBetweenLocations(dto.Locations[i - 1], endLocation); while (true) { var distance = LocationInterpolation.CalculateDistanceBetweenLocations(startLocation, endLocation); if (distance < nextDistance) { nextDistance -= distance; startLocation = endLocation; break; } nextDistance = intervalDistance; startLocation = LocationInterpolation.IntermediaryLocation(startLocation, endLocation, intervalDistance); locations.Add(startLocation); } } return(locations); }