示例#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>
        /// Creates a response.
        /// </summary>
        /// <param name="candidates">All the candidates that matched the request.</param>
        /// <param name="geocodeSource">The source that is creating this response.</param>
        /// <param name="strictAddressMatch">A flag indicating whether all of the parts of the address
        ///                                  were used by the geocoder.  True if all parts of the input address
        ///                                  were passed to the geocoder, and false otherwise.</param>
        public GeocodeResponse(IEnumerable<GeocodeCandidate> candidates, GeocoderSource geocodeSource, bool strictAddressMatch)
        {
            GeocodeSource = geocodeSource;

            Candidates = candidates != null ? new List<GeocodeCandidate>(candidates)
                : new List<GeocodeCandidate>();
            Candidates.Sort();

            StrictAddressMatch = strictAddressMatch;
        }
示例#3
0
        /// <summary>
        /// Creates a response.
        /// </summary>
        /// <param name="candidates">All the candidates that matched the request.</param>
        /// <param name="geocodeSource">The source that is creating this response.</param>
        /// <param name="strictAddressMatch">A flag indicating whether all of the parts of the address
        ///                                  were used by the geocoder.  True if all parts of the input address
        ///                                  were passed to the geocoder, and false otherwise.</param>
        public GeocodeResponse(IEnumerable <GeocodeCandidate> candidates, GeocoderSource geocodeSource, bool strictAddressMatch)
        {
            GeocodeSource = geocodeSource;

            Candidates = candidates != null ? new List <GeocodeCandidate>(candidates)
                : new List <GeocodeCandidate>();
            Candidates.Sort();

            StrictAddressMatch = strictAddressMatch;
        }
示例#4
0
        /// <summary>
        /// Constructs the geocoder, reading the list of sources from the specified
        /// section of the given config.
        /// </summary>
        /// <param name="config">Config object with the geocoder configuration.</param>
        /// <param name="sectionName">Section of the config that the geocoding sources are in.</param>
        public Geocoder(Config config, string sectionName) : base(config, sectionName)
        {
            IList <KeyValuePair <string, string> > sourceLines = config.GetParametersAsList(sectionName);

            foreach (KeyValuePair <string, string> sourceLine in sourceLines)
            {
                try
                {
                    // Key is the config section name for that geocoder source,
                    string sourceConfigSection = sourceLine.Key;
                    // value is the class name.
                    string typeName           = sourceLine.Value;
                    Type   geocoderSourceType = Type.GetType(typeName);
                    if (geocoderSourceType == null)
                    {
                        throw new ConfigurationErrorsException("GeocoderSourceClass '" + typeName +
                                                               "' was specified, but we were unable to get type info.  Are you missing a DLL?");
                    }

                    Type[]          constructorParamTypes = new[] { typeof(Config), typeof(string) };
                    ConstructorInfo constr = geocoderSourceType.GetConstructor(constructorParamTypes);
                    if (constr == null)
                    {
                        throw new ConfigurationErrorsException("GeocoderSourceClass '" + typeName +
                                                               "' was specified, but we were unable to get constructor info.");
                    }

                    GeocoderSource source = (GeocoderSource)constr.Invoke(new object[] { config, sourceConfigSection });
                    _geocoderSources.Add(source);
                }
                catch (Exception e)
                {
                    throw new LoggingException("Unable to load geocoder source '" +
                                               sourceLine.Key + "', '" + sourceLine.Value + "'.", e);
                }
            }
            if (_geocoderSources.Count == 0)
            {
                throw new LoggingException("No geocoding sources specified in section " + sectionName +
                                           ", unable to construct geocoder.");
            }
        }
示例#5
0
 /// <summary>
 /// Creates a response.
 /// </summary>
 /// <param name="candidates">All the candidates that matched the request.</param>
 /// <param name="geocodeSource">The source that is creating this response.</param>
 public GeocodeResponse(IEnumerable<GeocodeCandidate> candidates, GeocoderSource geocodeSource)
     : this(candidates, geocodeSource, true)
 {
 }
示例#6
0
 /// <summary>
 /// Creates a response.
 /// </summary>
 /// <param name="candidates">All the candidates that matched the request.</param>
 /// <param name="geocodeSource">The source that is creating this response.</param>
 public GeocodeResponse(IEnumerable <GeocodeCandidate> candidates, GeocoderSource geocodeSource)
     : this(candidates, geocodeSource, true)
 {
 }
示例#7
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;
                    }
                }
            }
        }