Esempio n. 1
0
        public static void CreateGeohashData(ConsoleOutput console, TimeZoneShapeFileReader inputShapefile, string outputPath)
        {
            var features = inputShapefile.ReadShapeFile().AsParallel()
                           .Select(x =>
            {
                x.Geometry = x.Geometry.Simplify();
                return(x);
            })
                           .ToList();

            PreLoadTimeZones(features);

            console.WriteMessage("Polygons loaded and simplified");

            var geohashes = features.AsParallel()
                            .Select(x => new
            {
                TimeZone  = x,
                Geohashes = GeohashTree.GetGeohashes(x.Geometry)
            })
                            .ToList();

            console.WriteMessage("Geohashes generated for polygons");

            foreach (var hash in geohashes)
            {
                foreach (var g in hash.Geohashes)
                {
                    AddResult(g, hash.TimeZone);
                }
            }

            console.WriteMessage("Geohash tree built");

            WorldBoundsTreeNode.PrepareForOutput();

            console.WriteMessage("Geohash tree preparing for output");

            WriteGeohashDataFile(outputPath);
            console.WriteMessage("Data file written");

            WriteLookup(outputPath);
            console.WriteMessage("Lookup file written");
        }
Esempio n. 2
0
        public static void CreateGeohashData(ConsoleOutput console, TimeZoneShapeFileReader inputShapefile, string outputPath)
        {
            var features = inputShapefile.ReadShapeFile().AsParallel()
                .Select(x =>
                {
                    x.Geometry = x.Geometry.Simplify();
                    return x;
                })
                .ToList();

            PreLoadTimeZones(features);

            console.WriteMessage("Polygons loaded and simplified");

            var geohashes = features.AsParallel()
                .Select(x => new
                {
                    TimeZone = x,
                    Geohashes = GeohashTree.GetGeohashes(x.Geometry)
                })
                .ToList();

            console.WriteMessage("Geohashes generated for polygons");

            foreach (var hash in geohashes)
                foreach (var g in hash.Geohashes)
                    AddResult(g, hash.TimeZone);

            console.WriteMessage("Geohash tree built");

            WorldBoundsTreeNode.PrepareForOutput();

            console.WriteMessage("Geohash tree preparing for output");

            WriteGeohashDataFile(outputPath);
            console.WriteMessage("Data file written");

            WriteLookup(outputPath);
            console.WriteMessage("Lookup file written");
        }
Esempio n. 3
0
        public static void CreateGeohashData(ConsoleOutput console, TimeZoneShapeFileReader inputShapefile, string outputPath)
        {
            console.WriteMessage("Loading polygons...");

            var features = inputShapefile.ReadShapeFile()
                           .SelectMany(x =>
            {
                // Expand MultiPolygons to individual Polygons
                var mp = x.Geometry as MultiPolygon;
                return(mp != null
                        ? mp.Geometries.Select((y, i) => new TimeZoneFeature {
                    TzName = x.TzName, Geometry = y, MultiPolyIndex = i
                })
                        : new[] { x });
            })
                           .Where(x => x.Geometry.Area > 0)
                           .OrderBy(x => x.TzName).ThenBy(x => x.MultiPolyIndex)
                           .ToList();

            PreLoadTimeZones(features);

            console.WriteMessage("Polygons loaded.");

            var geohashes = features
                            .AsParallel()
                            .Select(x =>
            {
                var indexString = x.MultiPolyIndex >= 0 ? $"[{x.MultiPolyIndex}]" : "";
                console.WriteMessage($"Generating geohash for {x.TzName}" + indexString);
                return(new
                {
                    TimeZone = x,
                    Geohashes = GeohashTree.GetGeohashes(x.Geometry)
                });
            })
                            .ToList();

            console.WriteMessage("Geohashes generated for polygons.");

            foreach (var hash in geohashes)
            {
                foreach (var g in hash.Geohashes)
                {
                    AddResult(g, hash.TimeZone);
                }
            }

            console.WriteMessage("Geohash tree built.");

            WorldBoundsTreeNode.PrepareForOutput();

            console.WriteMessage("Geohash tree preparing for output.");

            WriteGeohashDataFile(outputPath);
            console.WriteMessage("Data file written.");

            WriteLookup(outputPath);
            console.WriteMessage("Lookup file written.");

            console.WriteMessage("Done!");
        }