Exemplo n.º 1
0
 public void AddCities()
 {
     Towns = new WebClient().DownloadString(
         "https://raw.githubusercontent.com/Gibbs/UK-Postcodes/master/postcodes.csv")
             .Split('\r', '\n')
             .Skip(1)
             .Where(s => s != "")
             .Select(s => s.Split(','))
             .Select(s => new Place(s[0].Trim('\"'), int.Parse(s[1].Trim('\"')), int.Parse(s[2].Trim('\"')), s[3].Trim('\"'), s[4].Trim('\"'), s[5].Trim('\"'), s[6].Trim('\"'), s[7].Trim('\"'), s[8].Trim('\"'))).GroupBy(x => x.town)
             .Select(grouping => grouping.First())
             .ToArray()
     ;
     _index = new SpatialIndex <Place>();
     _index.init();
     foreach (var place in Towns)
     {
         var point = place.MakePoint();
         _index.add(new Rectangle(point.x, point.y, point.x + 1, point.y + 1), place);
     }
 }