public async Task Should_return_centerline_geocoder_only() { var request = new LocatorsForReverseLookup.Command(); var options = new Mock <IOptions <GisServerConfiguration> >(); options.Setup(x => x.Value).Returns(new GisServerConfiguration { Host = "test", Port = "1", Protocol = "proto" }); var result = await handler.Handle(request, new CancellationToken()); result.ShouldHaveSingleItem(); var locator = result.First(); locator.Url.ShouldBe("proto://test:1/arcgis/rest/services/Geolocators/Roads_AddressSystem_STREET/GeocodeServer/reverseGeocode?location={0},{1}&distance={2}&outSR={3}&f=json"); locator.Name.ShouldBe("Centerlines.StatewideRoads"); }
public async Task <ObjectResult> Reverse(double x, double y, [FromQuery] ReverseGeocodingOptions options) { var inputLocation = new Point(x, y); if (options.SpatialReference != 26912) { var reprojectCommand = new Reproject.Command(new PointReprojectOptions(options.SpatialReference, 26912, new[] { x, y })); var pointReprojectResponse = await _mediator.Send(reprojectCommand); if (!pointReprojectResponse.IsSuccessful || !pointReprojectResponse.Geometries.Any()) { _log.Fatal("Could not reproject point for {x},{y} {wkid}", x, y, options); return(new ObjectResult(new ApiResponseContainer { Message = "There was a problem reprojecting your input location", Status = (int)HttpStatusCode.InternalServerError }) { StatusCode = (int)HttpStatusCode.InternalServerError }); } var points = pointReprojectResponse.Geometries.FirstOrDefault(); if (points != null) { x = points.X; y = points.Y; } } var locatorLookup = new LocatorsForReverseLookup.Command(); var locators = await _mediator.Send(locatorLookup); if (locators == null || !locators.Any()) { _log.Debug("No locators found for address reversal"); return(NotFound(new ApiResponseContainer { Message = $"No address candidates found within {options.Distance} meters of {x}, {y}.", Status = (int)HttpStatusCode.NotFound })); } // there's only one var locator = locators.First(); locator.Url = string.Format(locator.Url, x, y, options.Distance, options.SpatialReference); var reverseGeocodeCommand = new ReverseGeocode.Command(locator); try { var response = await _mediator.Send(reverseGeocodeCommand); if (response == null) { return(NotFound(new ApiResponseContainer { Message = $"No address candidates found within {options.Distance} meters of {x}, {y}.", Status = (int)HttpStatusCode.NotFound })); } var result = response.ToResponseObject(inputLocation); return(Ok(new ApiResponseContainer <ReverseGeocodeApiResponse> { Result = result, Status = (int)HttpStatusCode.OK })); } catch (Exception ex) { _log.Fatal(ex, "Error reverse geocoding {locator}", locator.Url); return(new ObjectResult(new ApiResponseContainer { Message = "There was a problem handling your request", Status = (int)HttpStatusCode.InternalServerError }) { StatusCode = (int)HttpStatusCode.InternalServerError }); } }