Exemple #1
0
        private static string DoCell(H3Index h3, H3ToGeoBoundaryArguments argParser)
        {
            var sb = new StringBuilder();
            var gb = h3.ToGeoBoundary();

            if (argParser.Kml)
            {
                string name = string.IsNullOrEmpty(argParser.KmlName)
                                  ? "H3 Geometry"
                                  : argParser.KmlDescription;
                string desc = string.IsNullOrEmpty(argParser.KmlDescription)
                                  ? "Generated by h3ToGeoBoundary"
                                  : argParser.KmlDescription;

                sb.Append(Kml.PtsHeader(name, desc));
                sb.Append(Kml.OutputBoundaryKML(gb, h3.ToString()));
                sb.Append(Kml.PtsFooter());
            }
            else
            {
                sb.AppendLine(h3.ToString());
                sb.Append(Utility.GeoBoundaryPrintLines(gb));
            }

            return(sb.ToString());
        }
Exemple #2
0
        private static void ProcessFile(H3ToGeoBoundaryArguments argParser, CommandLineParser.CommandLineParser parser)
        {
            if (!File.Exists(argParser.InputFileName))
            {
                Console.WriteLine($"Unable to open {argParser.InputFileName}");
                parser.ShowUsage();
                return;
            }

            try
            {
                var lines = File.ReadLines(argParser.InputFileName);
                foreach (string line in lines)
                {
                    bool test = ulong.TryParse(line.Trim(), out ulong value);
                    if (!test)
                    {
                        continue;
                    }
                    var h3 = new H3Index(value);
                    Console.Write(DoCell(h3, argParser));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            using var parser = new CommandLineParser.CommandLineParser();

            args = args.Select(s => s.ToLower()).ToArray();

            try
            {
                var argParser = new H3ToGeoBoundaryArguments();
                parser.ExtractArgumentAttributes(argParser);
                parser.ParseCommandLine(args);

                if (string.IsNullOrEmpty(argParser.InputFileName) && argParser.Index == 0)
                {
                    Console.WriteLine("Need either a file or an H3Index to continue");
                    parser.ShowUsage();
                }
                else if (!string.IsNullOrEmpty(argParser.InputFileName) && argParser.Index != 0)
                {
                    Console.WriteLine("Cannot take both a file name and an index");
                    parser.ShowUsage();
                }

                if (string.IsNullOrEmpty(argParser.InputFileName))
                {
                    ProcessIndex(argParser, parser);
                }
                else
                {
                    ProcessFile(argParser, parser);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Unable to parse input.");
                parser.ShowUsage();
            }
        }
Exemple #4
0
        private static void ProcessIndex(H3ToGeoBoundaryArguments argParser, CommandLineParser.CommandLineParser parser)
        {
            var h3 = new H3Index(argParser.Index);

            Console.Write(DoCell(h3, argParser));
        }