private async Task <WorkReportGeometry> PerformSpatialValidationAndConversionAsync(WorkReportTyped typedRow) { var submissionRow = _submissionRows[(decimal)typedRow.RowNum]; var workReport = new WorkReportGeometry(typedRow, null); if (typedRow.SpatialData == SpatialData.Gps) { await PerformSpatialGpsValidation(workReport, submissionRow); SetVarianceWarningDetail(submissionRow, typedRow.HighwayUnique, GetGpsString(typedRow.StartLatitude, typedRow.StartLongitude), GetGpsString(typedRow.EndLatitude, typedRow.EndLongitude), typedRow.SpThresholdLevel); } else if (typedRow.SpatialData == SpatialData.Lrs) { await PerformSpatialLrsValidation(workReport, submissionRow); SetVarianceWarningDetail(submissionRow, typedRow.HighwayUnique, GetOffsetString(typedRow.StartOffset), GetOffsetString(typedRow.EndOffset), typedRow.SpThresholdLevel); } return(workReport); }
private async Task PerformSpatialLrsValidation(WorkReportGeometry workReport, HmrSubmissionRow submissionRow) { var errors = new Dictionary <string, List <string> >(); var typedRow = workReport.WorkReportTyped; //remeber that feature type line/point has been replaced either line or point in PerformGpsEitherLineOrPointValidation(). if (typedRow.FeatureType == FeatureType.Point) { var result = await _spatialService.ValidateLrsPointAsync((decimal)typedRow.StartOffset, typedRow.HighwayUnique, Fields.HighwayUnique, typedRow.SpThresholdLevel, errors); if (result.result == SpValidationResult.Fail) { SetErrorDetail(submissionRow, errors, _statusService.FileLocationError); } else if (result.result == SpValidationResult.Success) { typedRow.HighwayUniqueLength = result.rfiSegment.Length; typedRow.HighwayUniqueName = result.rfiSegment.Descr; typedRow.StartLongitude = result.point.Longitude; typedRow.StartLatitude = result.point.Latitude; workReport.Geometry = _geometryFactory.CreatePoint(result.point.ToTopologyCoordinate()); submissionRow.StartVariance = typedRow.StartOffset - result.snappedOffset; } } else if (typedRow.FeatureType == FeatureType.Line) { var result = await _spatialService .ValidateLrsLineAsync((decimal)typedRow.StartOffset, (decimal)typedRow.EndOffset, typedRow.HighwayUnique, Fields.HighwayUnique, typedRow.SpThresholdLevel, errors); if (result.result == SpValidationResult.Fail) { SetErrorDetail(submissionRow, errors, _statusService.FileLocationError); } else if (result.result == SpValidationResult.Success) { typedRow.HighwayUniqueLength = result.rfiSegment.Length; typedRow.HighwayUniqueName = result.rfiSegment.Descr; typedRow.StartLongitude = result.startPoint.Longitude; typedRow.StartLatitude = result.startPoint.Latitude; submissionRow.StartVariance = typedRow.StartOffset - result.snappedStartOffset; typedRow.EndLongitude = result.endPoint.Longitude; typedRow.EndLatitude = result.endPoint.Latitude; submissionRow.EndVariance = typedRow.EndOffset - result.snappedEndOffset; typedRow.WorkLength = result.snappedEndOffset - result.snappedStartOffset; if (result.lines.Count == 1) { if (result.lines[0].ToTopologyCoordinates().Length >= 2) { workReport.Geometry = _geometryFactory.CreateLineString(result.lines[0].ToTopologyCoordinates()); } else if (result.lines[0].ToTopologyCoordinates().Length == 1) { _logger.LogInformation($"[Hangfire] Row [{typedRow.RowNum}] [Original: Start[{typedRow.StartOffset}]" + $" End[{typedRow.EndOffset}] were converted to a Start[{result.snappedStartOffset}] End[{result.snappedEndOffset}]"); workReport.Geometry = _geometryFactory.CreatePoint(result.lines[0].ToTopologyCoordinates()[0]); } } else if (result.lines.Count > 1) { var lineStrings = new List <LineString>(); foreach (var line in result.lines) { lineStrings.Add(_geometryFactory.CreateLineString(line.ToTopologyCoordinates())); } workReport.Geometry = _geometryFactory.CreateMultiLineString(lineStrings.ToArray()); } } } }