Пример #1
0
        /// <summary>
        /// Given a list of requests, and a matching list of responses,
        /// this function reprojects the responses to match the request coordinate system
        /// </summary>
        /// <param name="gs">The GeocoderSource that was used</param>
        /// <param name="processedRequests">The initial list of requests</param>
        /// <param name="responses">The corresponding list of responses</param>
        protected void ReprojectResponses(GeocoderSource gs, IList <GeocodeRequest> processedRequests, IList <GeocodeResponse> responses)
        {
            // If a specific coordinate system was requested,
            // reproject from the goeocoder coordinate system to the
            // requested coordinate system.  We also need to identify
            // what CS we are returning in as well.
            if (processedRequests.Count != responses.Count)
            {
                return;
            }

            for (int i = 0, max = processedRequests.Count; i < max; i++)
            {
                GeocodeRequest  request  = processedRequests[i];
                GeocodeResponse response = responses[i];

                if (response.Candidates.Count == 0)
                {
                    continue;
                }

                _coordinateSystem = gs.CoordinateSystem;
                if (request.CoordinateSystem != null)
                {
                    foreach (GeocodeCandidate candidate in response.Candidates)
                    {
                        IPoint p = Reprojector.Reproject(gs.CoordinateSystem, request.CoordinateSystem,
                                                         candidate.Longitude,
                                                         candidate.Latitude);
                        candidate.Longitude = p.X;
                        candidate.Latitude  = p.Y;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Geocodes the given input and returns a response.
        /// </summary>
        /// <param name="geocodeRequest">The request to geocode.</param>
        /// <returns>The response to the request, will not be null even if there are no
        ///          matches; rather it will have an empty list of candidates.</returns>
        public GeocodeResponse Geocode(GeocodeRequest geocodeRequest)
        {
            GeocodeRequest  processedRequest = ProcessRequest(geocodeRequest);
            GeocodeResponse response         = InternalGeocode(processedRequest);

            ProcessResponse(response);
            return(response);
        }
Пример #3
0
        /// <summary>
        /// Takes a geocoding request, and runs it through all of the RequestProcessors.
        /// </summary>
        /// <param name="geocodeRequest"></param>
        private GeocodeRequest ProcessRequest(GeocodeRequest geocodeRequest)
        {
            GeocodeRequest modifiedRequest = new GeocodeRequest(geocodeRequest);

            foreach (IRequestProcessor rp in _processors[typeof(IRequestProcessor)])
            {
                modifiedRequest = rp.ProcessRequest(modifiedRequest);
            }

            return(modifiedRequest);
        }
Пример #4
0
        /// <summary>
        /// Geocodes more than one input at a time.
        /// </summary>
        /// <param name="gReqs">A group of requests to geocode.</param>
        /// <returns>A group of results, one for each request,
        ///          in the same order as the requests.</returns>
        public IList <GeocodeResponse> Geocode(IEnumerable <GeocodeRequest> gReqs)
        {
            List <GeocodeRequest> processedRequests = new List <GeocodeRequest>();

            // pre-process
            foreach (GeocodeRequest gReq in gReqs)
            {
                GeocodeRequest processedRequest = ProcessRequest(gReq);
                processedRequests.Add(processedRequest);
            }

            // geocode
            IList <GeocodeResponse> responses = InternalBatchGeocode(processedRequests);

            // post-process
            foreach (GeocodeResponse resp in responses)
            {
                ProcessResponse(resp);
            }

            return(responses);
        }
Пример #5
0
        /// <summary>
        /// Geocodes the given input and returns a response.
        /// </summary>
        /// <param name="request">The request to geocode.</param>
        /// <returns>The response to the request, will not be null even if there are no
        ///          matches.</returns>
        protected override GeocodeResponse InternalGeocode(GeocodeRequest request)
        {
            GeocodeResponse gRes = null;

            foreach (GeocoderSource gs in _geocoderSources)
            {
                gRes = gs.Geocode(request);
                if (gRes.Candidates.Count > 0)
                {
                    // If a specific coordinate system was requested,
                    // reproject from the goeocoder coordinate system to the
                    // requested coordinate system.  We also need to identify
                    // what CS we are returning in as well.
                    _coordinateSystem = gs.CoordinateSystem;
                    if (request.CoordinateSystem != null)
                    {
                        foreach (GeocodeCandidate candidate in gRes.Candidates)
                        {
                            IPoint p = Reprojector.Reproject(gs.CoordinateSystem, request.CoordinateSystem,
                                                             candidate.Longitude,
                                                             candidate.Latitude);

                            candidate.Longitude = p.X;
                            candidate.Latitude  = p.Y;
                        }
                    }
                    break;
                }
            }
            if (gRes == null)
            {
                throw new LoggingException(
                          "Internal state error, should never have a null object at this point. Num sources: " +
                          _geocoderSources.Count);
            }
            return(gRes);
        }
Пример #6
0
        /// <summary>
        /// Takes a geocoding request, and runs it through all of the RequestProcessors.
        /// </summary>
        /// <param name="geocodeRequest"></param>
        private GeocodeRequest ProcessRequest(GeocodeRequest geocodeRequest)
        {
            GeocodeRequest modifiedRequest = new GeocodeRequest(geocodeRequest);
            foreach (IRequestProcessor rp in _processors[typeof(IRequestProcessor)])
            {
                modifiedRequest = rp.ProcessRequest(modifiedRequest);
            }

            return modifiedRequest;
        }
Пример #7
0
 /// <summary>
 /// This is where actual source-specific geocoding happens.  It is called internal because
 /// clients use <code>Geocode</code> which sandwiches this call between pre- and post-processing.
 /// </summary>
 /// <param name="request">The request to be geocoded.</param>
 /// <returns>A <code>GeocodeResponse</code> describing the results of the geocode.</returns>
 protected abstract GeocodeResponse InternalGeocode(GeocodeRequest request);
Пример #8
0
 /// <summary>
 /// Geocodes the given input and returns a response.
 /// </summary>
 /// <param name="geocodeRequest">The request to geocode.</param>
 /// <returns>The response to the request, will not be null even if there are no
 ///          matches; rather it will have an empty list of candidates.</returns>
 public GeocodeResponse Geocode(GeocodeRequest geocodeRequest)
 {
     GeocodeRequest processedRequest = ProcessRequest(geocodeRequest);
     GeocodeResponse response = InternalGeocode(processedRequest);
     ProcessResponse(response);
     return response;
 }
Пример #9
0
 /// <summary>
 /// Clone an existing geocode request.
 /// </summary>
 /// <param name="original"></param>
 public GeocodeRequest(GeocodeRequest original)
     : base(original)
 {
     TextString       = original.TextString;
     CoordinateSystem = original.CoordinateSystem;
 }
Пример #10
0
 /// <summary>
 /// This is where actual source-specific geocoding happens.  It is called internal because
 /// clients use <code>Geocode</code> which sandwiches this call between pre- and post-processing.
 /// </summary>
 /// <param name="request">The request to be geocoded.</param>
 /// <returns>A <code>GeocodeResponse</code> describing the results of the geocode.</returns>
 protected abstract GeocodeResponse InternalGeocode(GeocodeRequest request);
Пример #11
0
        /// <summary>
        /// Geocodes the given input and returns a response.
        /// </summary>
        /// <param name="request">The request to geocode.</param>
        /// <returns>The response to the request, will not be null even if there are no
        ///          matches.</returns>
        protected override GeocodeResponse InternalGeocode(GeocodeRequest request)
        {
            GeocodeResponse gRes = null;
            foreach (GeocoderSource gs in _geocoderSources)
            {
                gRes = gs.Geocode(request);
                if (gRes.Candidates.Count > 0)
                {
                    // If a specific coordinate system was requested,
                    // reproject from the goeocoder coordinate system to the
                    // requested coordinate system.  We also need to identify
                    // what CS we are returning in as well.
                    _coordinateSystem = gs.CoordinateSystem;
                    if (request.CoordinateSystem != null)
                    {
                        foreach (GeocodeCandidate candidate in gRes.Candidates)
                        {
                            IPoint p = Reprojector.Reproject(gs.CoordinateSystem, request.CoordinateSystem,
                                                             candidate.Longitude,
                                                             candidate.Latitude);

                            candidate.Longitude = p.X;
                            candidate.Latitude = p.Y;
                        }
                    }
                    break;
                }
            }
            if (gRes == null)
            {
                throw new LoggingException(
                    "Internal state error, should never have a null object at this point. Num sources: " +
                    _geocoderSources.Count);
            }
            return gRes;
        }
Пример #12
0
 /// <summary>
 /// Clone an existing geocode request.
 /// </summary>
 /// <param name="original"></param>
 public GeocodeRequest(GeocodeRequest original)
     : base(original)
 {
     TextString = original.TextString;
     CoordinateSystem = original.CoordinateSystem;
 }