private void RollDownTimeZones()
        {
            if (TimeZones.Count > 0 && ChildNodes.Count > 0)
            {
                foreach (var hashChar in GeohashTree.Base32)
                {
                    if (!ChildNodes.TryGetValue(hashChar, out var childNode))
                    {
                        childNode = ChildNodes[hashChar] = new TimeZoneTreeNode();
                    }

                    foreach (var timeZone in TimeZones)
                    {
                        childNode.TimeZones.Add(timeZone);
                    }
                }

                TimeZones.Clear();
            }

            foreach (var childNode in ChildNodes)
            {
                childNode.Value.RollDownTimeZones();
            }
        }
Exemplo n.º 2
0
        private void RollDownTimeZones()
        {
            if (TimeZones.Count > 0 && ChildNodes.Count > 0)
            {
                foreach (var hashChar in GeohashTree.Base32)
                {
                    TimeZoneTreeNode childNode;
                    if (!ChildNodes.TryGetValue(hashChar, out childNode))
                    {
                        childNode = ChildNodes[hashChar] = new TimeZoneTreeNode();
                    }

                    foreach (var timeZone in TimeZones)
                    {
                        childNode.TimeZones.Add(timeZone);
                    }
                }

                TimeZones.Clear();
            }

            foreach (var childNode in ChildNodes)
            {
                childNode.Value.RollDownTimeZones();
            }
        }
Exemplo n.º 3
0
        private static void WriteTreeNode(StreamWriter writer, TimeZoneTreeNode node, string geohash = "")
        {
            foreach (var childNode in node.ChildNodes.OrderBy(x => x.Key))
            {
                var childHash = geohash + childNode.Key;

                if (childNode.Value.TimeZones.Count > 0)
                {
                    var groupedTimeZones = childNode.Value.TimeZones.GroupBy(x => x.TzName).ToList();

                    if (groupedTimeZones.Count > 1)
                    {
                        var env = GeohashTree.GetTreeNode(childHash).Geometry;

                        var tzs = groupedTimeZones.Select(x => new
                        {
                            TimeZone = x.Key,
                            Area     = x.Sum(c =>
                            {
                                var intersection = c.Geometry.Intersection(env);
                                return(intersection.Area / env.Area);
                            })
                        })
                                  .OrderByDescending(x => x.Area);

                        foreach (var timeZone in tzs)
                        {
                            WriteGeohash(writer, timeZone.TimeZone, childHash);
                        }
                    }
                    else
                    {
                        foreach (var timeZone in groupedTimeZones)
                        {
                            WriteGeohash(writer, timeZone.Key, childHash);
                        }
                    }
                }
                else if (childNode.Value.ChildNodes.Count > 0)
                {
                    WriteTreeNode(writer, childNode.Value, childHash);
                }
            }
        }
Exemplo n.º 4
0
        private static void WriteTreeNode(StreamWriter writer, TimeZoneTreeNode node, string geohash = "")
        {
            foreach (var childNode in node.ChildNodes.OrderBy(x => x.Key))
            {
                var childHash = geohash + childNode.Key;

                if (childNode.Value.TimeZones.Count > 0)
                {
                    var groupedTimeZones = childNode.Value.TimeZones.GroupBy(x => x.TzName).ToList();

                    if (groupedTimeZones.Count > 1)
                    {
                        var env = GeohashTree.GetTreeNode(childHash).Geometry;

                        var tzs = groupedTimeZones.Select(x => new
                        {
                            TimeZone = x.Key,
                            Area = x.Sum(c =>
                            {
                                var intersection = c.Geometry.Intersection(env);
                                return intersection.Area / env.Area;
                            })
                        })
                            .OrderByDescending(x => x.Area);

                        foreach (var timeZone in tzs)
                        {
                            WriteGeohash(writer, timeZone.TimeZone, childHash);
                        }
                    }
                    else
                    {
                        foreach (var timeZone in groupedTimeZones)
                        {
                            WriteGeohash(writer, timeZone.Key, childHash);
                        }
                    }
                }
                else if (childNode.Value.ChildNodes.Count > 0)
                {
                    WriteTreeNode(writer, childNode.Value, childHash);
                }
            }
        }