示例#1
0
        private static string DoCell(H3Index h3, H3ToGeoArguments argParser)
        {
            var sb = new StringBuilder();
            var gc = h3.ToGeoCoord();

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

                sb.Append(Kml.PtsHeader(name, desc));
                sb.Append(Kml.OutputPointKml(gc, h3.ToString()));
                sb.Append(Kml.PtsFooter());
            }
            else
            {
                sb.Append($"{gc.Latitude.RadiansToDegrees(),10:f8}, {gc.Longitude.RadiansToDegrees(),10:f8}");
            }

            return(sb.ToString());
        }
示例#2
0
        private static void ProcessFile(H3ToGeoArguments 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;
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            using var parser = new CommandLineParser.CommandLineParser();

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

            try
            {
                var argParser = new H3ToGeoArguments();
                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();
            }
        }
示例#4
0
        private static void ProcessIndex(H3ToGeoArguments argParser, CommandLineParser.CommandLineParser parser)
        {
            var h3 = new H3Index(argParser.Index);

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