/// <summary> /// Method to update the DP location based on UDPRN. /// </summary> /// <param name="addressLocationUSRPOSTDTO"></param> /// <param name="notificationType">Notification Type</param> private async Task UpdateDPLocation(AddressLocationUSRPOSTDTO addressLocationUSRPOSTDTO, Guid notificationType) { DbGeometry spatialLocationXY = GetSpatialLocation(addressLocationUSRPOSTDTO); PostalAddressDataDTO postalAddressDataDTO = await addressLocationDataService.GetPostalAddressData(addressLocationUSRPOSTDTO.UDPRN.Value); // If Delivery Point Exists for the given Postal Address if (postalAddressDataDTO != null && postalAddressDataDTO.DeliveryPoints != null && postalAddressDataDTO.DeliveryPoints.Count > 0 && spatialLocationXY != null) { DeliveryPointDTO deliveryPointDTO = await thirdPartyAddressLocationIntegrationService.GetDeliveryPointByPostalAddress(postalAddressDataDTO.ID); if (deliveryPointDTO != null && deliveryPointDTO.LocationXY != null) { double?toleranceDistance = spatialLocationXY.Distance(deliveryPointDTO.LocationXY); deliveryPointDTO.LocationXY = spatialLocationXY; // Update the location details for the delivery point await thirdPartyAddressLocationIntegrationService.UpdateDeliveryPointById(deliveryPointDTO); // Check Tolerance. Story: RFMO-279 CheckToleranceForLocation(toleranceDistance, false, notificationType, addressLocationUSRPOSTDTO.UDPRN.Value, postalAddressDataDTO); } } }
public override double Distance(DbGeometry geometryValue, DbGeometry otherGeometry) { if (geometryValue == null) { throw new ArgumentNullException("geometryValue"); } if (otherGeometry == null) { throw new ArgumentNullException("otherGeometry"); } DbGeometry mysqlValue = DbGeometry.FromText(geometryValue.ProviderValue.ToString()); Double?result = mysqlValue.Distance(otherGeometry); if (result != null) { return(result.Value); } return(0); }
/// <summary> /// Get the nearest street for operational object. /// </summary> /// <param name="operationalObjectPoint">Operational object unique identifier.</param> /// <param name="streetName">Street name.</param> /// <param name="referenceDataCategoryList">The reference data category list.</param> /// <returns>Nearest street and the intersection point.</returns> public Tuple <NetworkLinkDataDTO, SqlGeometry> GetNearestNamedRoad(DbGeometry operationalObjectPoint, string streetName, List <ReferenceDataCategoryDTO> referenceDataCategoryList) { using (loggingHelper.RMTraceManager.StartTrace("DataService.GetNearestNamedRoad")) { string methodName = typeof(StreetNetworkDataService) + "." + nameof(GetNearestNamedRoad); loggingHelper.LogMethodEntry(methodName, priority, entryEventId); SqlGeometry networkIntersectionPoint = SqlGeometry.Null; NetworkLinkDataDTO networkLink = null; // find the nearest named road for the provided operational object. var nearestNamedRoad = DataContext.StreetNames .Where(m => m.Descriptor == streetName || m.DesignatedName == streetName || m.LocalName == streetName) .OrderBy(n => operationalObjectPoint.Distance(n.Geometry)) .Select(l => new StreetNameDataDTO { ID = l.ID, StreetType = l.StreetType, NationalRoadCode = l.NationalRoadCode, DesignatedName = l.DesignatedName, Descriptor = l.Descriptor }).FirstOrDefault(); if (nearestNamedRoad != null) { // check if the there are no intersections with any other roads and the access link // intersection point Guid networkPathLinkType = referenceDataCategoryList.Where(x => x.CategoryName.Replace(" ", string.Empty) == ReferenceDataCategoryNames.NetworkLinkType) .SelectMany(x => x.ReferenceDatas) .Single(x => x.ReferenceDataValue == ReferenceDataValues.NetworkLinkPathLink).ID; Guid networkRoadLinkType = referenceDataCategoryList.Where(x => x.CategoryName.Replace(" ", string.Empty) == ReferenceDataCategoryNames.NetworkLinkType) .SelectMany(x => x.ReferenceDatas) .Single(x => x.ReferenceDataValue == ReferenceDataValues.NetworkLinkRoadLink).ID; networkLink = DataContext.NetworkLinks.AsNoTracking().Where(m => m.StreetNameGUID == nearestNamedRoad.ID) .OrderBy(n => n.LinkGeometry.Distance(operationalObjectPoint)) .Select(l => new NetworkLinkDataDTO { ID = l.ID, LinkGeometry = l.LinkGeometry, NetworkLinkTypeGUID = l.NetworkLinkTypeGUID, TOID = l.TOID }).FirstOrDefault(); if (networkLink != null) { SqlGeometry accessLinkLine = operationalObjectPoint.ToSqlGeometry().ShortestLineTo(networkLink.LinkGeometry.ToSqlGeometry()); if (!accessLinkLine.IsNull) { DbGeometry accessLinkDbGeometry = accessLinkLine.ToDbGeometry(); // find any road or path segment intersects with the planned access link. var intersectionCountForRoadOrPath = DataContext.NetworkLinks.AsNoTracking() .Count(m => m.LinkGeometry.Intersects(accessLinkDbGeometry) && (m.NetworkLinkTypeGUID == networkRoadLinkType || m.NetworkLinkTypeGUID == networkPathLinkType)); if (intersectionCountForRoadOrPath == 0) { networkIntersectionPoint = accessLinkLine.STEndPoint(); } } } } loggingHelper.LogMethodExit(methodName, priority, exitEventId); return(new Tuple <NetworkLinkDataDTO, SqlGeometry>(networkLink, networkIntersectionPoint)); } }