Пример #1
0
        private void AddCodes(CodedLocation codedLocation)
        {
            // add the codes to the input data
            InputColumnHeaders columnHeaders = geoCoder.LocationCodeColumnHeaders();
            if (codedLocation.GeoCode1 != null)
            {
                dataGridView1.Rows[selectedRowIndex].Cells[columnHeaders.Level1]
                    .Value =
                    codedLocation.GeoCode1.Code;
            }

            if (codedLocation.GeoCode2 != null)
            {
                dataGridView1.Rows[selectedRowIndex].Cells[columnHeaders.Level2]
                    .Value =
                    codedLocation.GeoCode2.Code;
            }

            if (codedLocation.GeoCode3 != null)
            {
                dataGridView1.Rows[selectedRowIndex].Cells[columnHeaders.Level3]
                    .Value =
                    codedLocation.GeoCode3.Code;
            }

            // add the names used to generate those codes as information for the user.
            AddUsedMatchNames(codedLocation);
        }
Пример #2
0
 private void GetLevel2Code(CodedLocation location, bool useCache)
 {
     Level2UsingGazetteer(location);
     if (location.GeoCode2 == null)
     {
         Level2UsingMatchedName(location, useCache);
     }
 }
Пример #3
0
        /// <summary>
        /// Gets the location codes.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="useMatchedNamesCache">If true, uses the cache of matched names</param>
        /// <returns>The location with the codes</returns>
        public CodedLocation GetCodes(
            Location location,
            bool useMatchedNamesCache = false)
        {
            CodedLocation codedLocation = new CodedLocation(location);
            GetLevel1Code(codedLocation, useMatchedNamesCache);

            if (codedLocation.GeoCode1 != null)
            {
                GetLevel2Code(codedLocation, useMatchedNamesCache);
                if (codedLocation.GeoCode2 != null)
                {
                    GetLevel3Code(codedLocation, useMatchedNamesCache);
                }
            }

            return codedLocation;
        }
Пример #4
0
        private Level3Match SavedLevel3Match(CodedLocation location)
        {
            IEnumerable<Level3Match> matches =
                matchProvider.GetMatches(
                    location.Name3,
                    location.GeoCode1.Name,
                    location.GeoCode2.Name).ToList();
            int count = matches.Count();

            if (count > 1)
            {
                // there must only be a max of one saved match for any given input.
                var msg = string.Format(
                    "[{0}] matched names found for the input [{1}] [{2}],[{3}]",
                    count,
                    location.GeoCode1.Name,
                    location.GeoCode2.Name,
                    location.Name3);
                throw new InvalidOperationException(msg);
            }
            Level3Match match = matches.FirstOrDefault();
            return match;
        }
Пример #5
0
        private void Level3UsingMatchedName(CodedLocation location, bool useCache)
        {
            if (string.IsNullOrEmpty(location.Name3))
            {
                return;
            }

            // get the matched name and try again
            Level3Match match;
            if (useCache)
            {
                match = matchedNamesCache.Level3Match(
                    location.GeoCode1.Name,
                    location.GeoCode2.Name,
                    location.Name3);
            }
            else
            {
                match = SavedLevel3Match(location);
            }

            if (match != null)
            {
                // try with the matched name
                location.Name3 = match.Level3;
                Level3UsingGazetteer(location);
            }
        }
Пример #6
0
        private void Level3UsingGazetteer(CodedLocation location)
        {
            if (string.IsNullOrEmpty(location.Name3))
            {
                return;
            }

            location.GeoCode3 = dictionary.GetLevel3Code(
                location.GeoCode1.Name,
                location.GeoCode2.Name,
                location.Name3);
        }
Пример #7
0
        private void Level1UsingGazetteer(CodedLocation location)
        {
            if (string.IsNullOrEmpty(location.Name1))
            {
                return;
            }

            location.GeoCode1 = dictionary.GetLevel1Code(
                location.Name1);
        }
Пример #8
0
        private static void AddUsedMatchNames(
            CodedLocation codedLocation,
            DataRow dataRow)
        {
            // add the actual name used to get the code if different to that on the input

            if (codedLocation.IsName1Different())
            {
                dataRow[Level1MatchedColumnName] = codedLocation.GeoCode1.Name;
            }

            if (codedLocation.IsName2Different())
            {
                dataRow[Level2MatchedColumnName] = codedLocation.GeoCode2.Name;
            }

            if (codedLocation.IsName3Different())
            {
                dataRow[Level3MatchedColumnName] = codedLocation.GeoCode3.Name;
            }
        }
Пример #9
0
        private static void AddCodes(CodedLocation codedLocation, DataRow dataRow)
        {
            if (codedLocation.GeoCode1 != null)
            {
                dataRow[Level1CodeColumnName] = codedLocation.GeoCode1.Code;
            }

            if (codedLocation.GeoCode2 != null)
            {
                dataRow[Level2CodeColumnName] = codedLocation.GeoCode2.Code;
            }

            if (codedLocation.GeoCode3 != null)
            {
                dataRow[Level3CodeColumnName] = codedLocation.GeoCode3.Code;
            }

            // add the names used to generate those codes as information for the user.
            AddUsedMatchNames(codedLocation, dataRow);
        }
Пример #10
0
        private void AddUsedMatchNames(CodedLocation codedLocation)
        {
            InputColumnHeaders columnHeaders = geoCoder.MatchedNameColumnHeaders();
            // add the actual name used to get the code if different to that on the input
            if (codedLocation.IsName1Different())
            {
                dataGridView1.Rows[selectedRowIndex].Cells[columnHeaders.Level1]
                    .Value
                    = codedLocation.GeoCode1.Name;
            }

            if (codedLocation.IsName2Different())
            {
                dataGridView1.Rows[selectedRowIndex].Cells[columnHeaders.Level2]
                    .Value
                    = codedLocation.GeoCode2.Name;
            }

            if (codedLocation.IsName3Different())
            {
                dataGridView1.Rows[selectedRowIndex].Cells[columnHeaders.Level3]
                    .Value
                    = codedLocation.GeoCode3.Name;
            }
        }