public async Task <Candidate> Execute() { if (!GeocodedAddress.Zip5.HasValue) { return(null); } _drivecCache.UspsDeliveryPoints.TryGetValue(GeocodedAddress.Zip5.Value.ToString(), out List <GridLinkable> items); if (items == null || !items.Any()) { return(null); } if (!(items.FirstOrDefault() is UspsDeliveryPointLink deliveryPoint)) { return(null); } var result = new Candidate { Address = deliveryPoint.MatchAddress, AddressGrid = deliveryPoint.Grid, Locator = "USPS Delivery Points", Score = 100, Location = new Point(deliveryPoint.X, deliveryPoint.Y) }; if (_options.SpatialReference == 26912) { return(result); } _reproject.Initialize(new ReprojectPointsCommand.PointProjectQueryArgs(26912, _options.SpatialReference, new List <double> { deliveryPoint.X, deliveryPoint.Y })); var pointReprojectResponse = await _reproject.Execute(); if (!pointReprojectResponse.IsSuccessful || !pointReprojectResponse.Geometries.Any()) { return(null); } var points = pointReprojectResponse.Geometries.FirstOrDefault(); if (points != null) { result.Location = new Point(points.X, points.Y); } return(result); }
public async Task <Candidate> Execute() { if (!_geocodedAddress.Zip5.HasValue) { return(null); } if (_driveCache.PoBoxes is null) { return(null); } if (!_driveCache.PoBoxes.ContainsKey(_geocodedAddress.Zip5.Value)) { return(null); } Candidate candidate; var key = _geocodedAddress.Zip5.Value * 10000 + _geocodedAddress.PoBox; if (_driveCache.PoBoxZipCodesWithExclusions.Any(x => x == _geocodedAddress.Zip5) && _driveCache.PoBoxExclusions.ContainsKey(key)) { var exclusion = _driveCache.PoBoxExclusions[key]; candidate = new Candidate { Address = _geocodedAddress.StandardizedAddress, Locator = "Post Office Point Exclusions", Score = 100, Location = new Point(exclusion.X, exclusion.Y), AddressGrid = _geocodedAddress?.AddressGrids?.FirstOrDefault()?.Grid }; } else if (_driveCache.PoBoxes.ContainsKey(_geocodedAddress.Zip5.Value)) { var result = _driveCache.PoBoxes[_geocodedAddress.Zip5.Value]; candidate = new Candidate { Address = _geocodedAddress.StandardizedAddress, Locator = "Post Office Point", Score = 100, Location = new Point(result.X, result.Y), AddressGrid = _geocodedAddress.AddressGrids.FirstOrDefault()?.Grid }; } else { return(null); } if (_options.SpatialReference == 26912) { return(candidate); } _repojectPoints.Initialize(new ReprojectPointsCommand.PointProjectQueryArgs(26912, _options.SpatialReference, new List <double> { candidate.Location.X, candidate.Location.Y })); var pointReprojectResponse = await _repojectPoints.Execute(); if (!pointReprojectResponse.IsSuccessful || !pointReprojectResponse.Geometries.Any()) { return(null); } var points = pointReprojectResponse.Geometries.FirstOrDefault(); if (points != null) { candidate.Location = new Point(points.X, points.Y); } return(candidate); }