Esempio n. 1
0
        public void Setup(ObservableCollection <Nation> nations)
        {
            Nations = nations;
            WorldCountries.Clear();
            CountryGeographies.Clear();
            foreach (Nation nation in Nations)
            {
                if (string.IsNullOrEmpty(nation.Country))
                {
                    nation.Country = nation.Name;
                }

                WorldCountries.Add(nation);
                CountryGeographies.Add(nation.Geography);
            }
        }
Esempio n. 2
0
        public static WorldCountries ProcessWorldCountries(ShapefileConverter shapefile)
        {
            var countries = new WorldCountries();

            foreach (ShapefileRecord record in shapefile)
            {
                var item = new WorldCountry();
                if (record.Fields != null)
                {
                    // get geo-shape from shape file (SHP)
                    item.LoadPoints(record.Points);
                    //location.Longitude = record.Points[0][0].X;
                    //location.Latitude = record.Points[0][0].Y;

                    // get data about a country from old database file (DBF)
                    if (record.Fields.ContainsKey("CODE"))
                    {
                        item.CountryCode = (string)(record.Fields["CODE"]);
                    }
                    if (record.Fields.ContainsKey("CNTRY_NAME"))
                    {
                        item.CountryName = (string)(record.Fields["CNTRY_NAME"]);
                    }
                    if (record.Fields.ContainsKey("POP_CNTRY"))
                    {
                        item.Population = (double)(record.Fields["POP_CNTRY"]);
                    }

                    // get data about a country from new database file (DBF)
                    if (record.Fields.ContainsKey("ISO_2_CODE"))
                    {
                        item.CountryCode = (string)(record.Fields["ISO_2_CODE"]);
                    }
                    if (record.Fields.ContainsKey("NAME"))
                    {
                        item.CountryName = (string)(record.Fields["NAME"]);
                    }
                    if (record.Fields.ContainsKey("REGION"))
                    {
                        item.Region = (string)(record.Fields["REGION"]);
                    }
                    if (record.Fields.ContainsKey("POP2005"))
                    {
                        item.Population = (double)(record.Fields["POP2005"]);
                    }
                    if (record.Fields.ContainsKey("AREA"))
                    {
                        item.Area = (double)(record.Fields["AREA"]);
                    }

                    if (item.Population < 0)
                    {
                        item.Population = 0;
                    }
                    if (item.Area < 0)
                    {
                        item.Area = 0;
                    }

                    if (item.CountryName == "US" || item.CountryName == "USA")
                    {
                        item.CountryName = "United States";
                    }
                    if (item.CountryName == "UK" || item.CountryName == "GB")
                    {
                        item.CountryName = "United Kingdom";
                    }

                    item.Label = "Country: " + item.CountryName + ", " + item.Region
                                 + Environment.NewLine + "Population: " + String.Format("{0:#,##0,,.0 M}", item.Population)
                                 + Environment.NewLine + "Area: " + String.Format("{0:#,##0,.0 K}", item.Area);

                    // update countries stats
                    countries.Population.Update(item.Population);
                    countries.Area.Update(item.Area);

                    // add an item to data collection
                    countries.Add(item);
                }
            }
            countries.Sort((x, y) => - x.Population.CompareTo(y.Population));
            return(countries);
        }