// Copyright (C) Stichting Deltares 2024. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Globalization; using System.IO; using Deltares.Dam.Data; namespace GeoXY2LatLong { class Program { static void Main(string[] args) { var arguments = new CommandLineArgumentParser(args); var sourceFile = ""; var destFile = "output.csv"; var xpos = 3; var ypos = 4; if (arguments.Contains("help") || arguments.Contains("?")) { Console.WriteLine("GeoXY to lat long converter"); Console.WriteLine("Usage: geoxy2latlong.exe /sourceFile:locations.csv /outFile:locations_pluslatlong.csv /skipFirstLine /xpos:3 /ypos:4"); return; } if (arguments.Contains("sourceFile") || arguments.Contains("s")) { sourceFile = arguments["sourceFile"] ?? arguments["s"]; if (!sourceFile.EndsWith("csv")) { throw new ArgumentException("The file is not supported"); } } if (arguments.Contains("outFile") || arguments.Contains("o")) { destFile = arguments["outFile"] ?? arguments["d"]; if (destFile == sourceFile) { throw new ArgumentException("The output file name cannot be the same as the source file name"); } } bool skipFirstLine = arguments.Contains("skipFirstLine") || arguments.Contains("sfl"); if (arguments.Contains("xpos")) { xpos = int.Parse(arguments["xpos"]); } if (arguments.Contains("ypos")) { ypos = int.Parse(arguments["ypos"]); } string[] lines = File.ReadAllLines(sourceFile); using (var sw = new StreamWriter(destFile, false)) { int start = skipFirstLine ? 1 : 0; for (int i = start; i < lines.Length; i++) { var values = new List(lines[i].Split(';')); double x = double.Parse(values[xpos], NumberStyles.Any, CultureInfo.InvariantCulture); double y = double.Parse(values[ypos], NumberStyles.Any, CultureInfo.InvariantCulture); GeometryPoint point = RdLatLngConverter.RdToLatLng(x, y); values.Add(point.X.ToString()); values.Add(point.Y.ToString()); string newLine = string.Join(";", values.ToArray()); Console.WriteLine(newLine); sw.WriteLine(newLine); } } } } }