예제 #1
0
        static void Main(string[] args)
        {
            City   Stockholm = new City();
            Contry Sverige   = new Contry();

            Sverige.capital = Stockholm;

            Console.ReadKey();
        }
예제 #2
0
        private static void AddSingleRegionContry(JToken token, Contry contry, JToken regionsToken, List <Point> regionGeo)
        {
            foreach (JToken pointToken in regionsToken)
            {
                regionGeo.Add(new Point((float)pointToken[0], (float)pointToken[1]));
            }
            Point center = ComputeCenter(regionGeo);
            var   region = new Region(regionGeo, center).Init(Convert.ToInt32(token["properties"]["pop_est"]));

            contry.AddRegion(region);
        }
예제 #3
0
        public static void InitDB(IServiceProvider service)
        {
            using IServiceScope serviceScope = service.CreateScope();
            var        scopeServiceProvider = service.CreateScope().ServiceProvider;
            EcoContext context = scopeServiceProvider.GetService <EcoContext>();

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();
            context.SaveChanges();

            var contries = new List <Contry>();

            Console.WriteLine("Hello World!");
            using (StreamReader file = File.OpenText(@"ClientApp\src\custom.geo.json"))
            {
                var random = new Random();
                using var reader = new JsonTextReader(file);
                var o2 = (JObject)JToken.ReadFrom(reader);
                o2.GetValue("features");
                foreach (JToken token in o2.GetValue("features"))
                {
                    string contryName = token["properties"]["admin"].ToString();
                    var    contry     = new Contry(contryName);
                    RegionCompute(random, token, contry);
                    context.Contry.Add(contry);
                    contries.Add(contry);
                }
            }
            context.SaveChanges();

            for (int i = 0; i < contries.Count; i++)
            {
                foreach (Region region1 in contries[i].Regions)
                {
                    for (int j = i + 1; j < contries.Count; j++)
                    {
                        foreach (Region region2 in contries[j].Regions)
                        {
                            bool intersect = 5 > Math.Sqrt(Math.Pow(region1.CenterX - region2.CenterX, 2) + Math.Pow(region1.CenterY - region2.CenterY, 2));
                            //PointCollectionsOverlap_Fast(new PointCollection(region1.GetPolygon()), new PointCollection(region2.GetPolygon()));

                            if (intersect)
                            {
                                region1.ConnectNeighbour(region2);
                            }
                        }
                    }
                }
            }
            context.SaveChanges();
        }
예제 #4
0
        private static void RegionCompute(Random random, JToken token, Contry contry)
        {
            bool first = true;

            foreach (JToken regionsToken in token["geometry"]["coordinates"])
            {
                var regionGeo = new List <Point>();
                if (regionsToken[0][0].Type is JTokenType.Float)
                {
                    AddSingleRegionContry(token, contry, regionsToken, regionGeo);
                }
                else
                {
                    foreach (JToken regionToken in regionsToken)
                    {
                        foreach (JToken pointToken in regionToken)
                        {
                            regionGeo.Add(new Point((float)pointToken[0], (float)pointToken[1]));
                        }
                        Point  center = ComputeCenter(regionGeo);
                        Region region = null;
                        if (first == true)
                        {
                            first  = false;
                            region = new Region(regionGeo, center).Init(Convert.ToInt32(token["properties"]["pop_est"]));
                        }
                        else
                        {
                            region = new Region(regionGeo, center).Init(random.Next(1000));
                        }
                        contry.AddRegion(region);
                        regionGeo = new List <Point>();
                    }
                }
            }
        }