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); }
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>(); } } } }