Exemplo n.º 1
0
        public static OptStats OptimizeDatabase(Stream Input, Stream Output, List <GeoFeatureClass> FeatureClassFilter, List <string> CountryFilter)
        {
            long          RecordsIn             = 0;
            long          RecordsOut            = 0;
            string        CountryFilterCompiled = string.Join("|", CountryFilter.ToArray());
            StringBuilder sb = new StringBuilder();

            foreach (var f in FeatureClassFilter)
            {
                sb.Append(GeoName.ClassToCode(f));
            }

            string FeatureClassFilterCompiled = sb.ToString();

            using (StreamReader _in = new StreamReader(Input))
            {
                using (StreamWriter _out = new StreamWriter(Output))
                {
                    string Line;
                    while (!_in.EndOfStream && (Line = _in.ReadLine()) != null)
                    {
                        RecordsIn++;
                        if (FilterRecord(Line.Split('\t'), FeatureClassFilterCompiled, CountryFilterCompiled))
                        {
                            RecordsOut++;
                            _out.WriteLine(Line);
                        }
                    }
                }
            }

            return(new OptStats(RecordsIn, RecordsOut));
        }
Exemplo n.º 2
0
 /// <summary>
 /// All the geocoding data can be gotten from: http://download.geonames.org/export/dump/
 /// </summary>
 /// <param name="input"></param>
 public void SetPlaces(Stream input)
 {
     Places.Clear();
     using (StreamReader db = new StreamReader(input))
     {
         string line;
         while (!db.EndOfStream && (line = db.ReadLine()) != null)
         {
             if (line.StartsWith("#"))
             {
                 continue;
             }
             var place = new GeoName(line, CountryInfos);
             Places.Add(place);
         }
     }
 }
Exemplo n.º 3
0
        private void Initialize(Stream Input, bool MajorPlacesOnly)
        {
            List <GeoName> Places = new List <GeoName>();

            using (StreamReader db = new StreamReader(Input))
            {
                string Line;
                while (!db.EndOfStream && (Line = db.ReadLine()) != null)
                {
                    var Place = new GeoName(Line);
                    if (!MajorPlacesOnly || Place.FeatureClass != GeoFeatureClass.City)
                    {
                        Places.Add(Place);
                    }
                }
            }

            Tree = new KDTree <GeoName>(Places.ToArray());
        }
Exemplo n.º 4
0
        private void Initialize(Stream Input, bool MajorPlacesOnly)
        {
            List <GeoName> Places = new List <GeoName>();

            using (StreamReader db = new StreamReader(Input))
            {
                string Line;
                while (!db.EndOfStream && (Line = db.ReadLine()) != null)
                {
                    var Place = new GeoName(Line);
                    if (!MajorPlacesOnly || Place.FeatureClass != GeoFeatureClass.City)
                    {
                        Places.Add(Place);
                    }
                }
            }

            Names = new Dictionary <string, GeoName>();
            foreach (var p in Places)
            {
            }
        }