diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Cmd.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Cmd.cs index 16b48dc..edbd4e4 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Cmd.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Cmd.cs @@ -1,4 +1,8 @@ -using GISBlox.Services.CLI.Commands.Auth; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using GISBlox.Services.CLI.Commands.Auth; using GISBlox.Services.CLI.Commands.Convert; using GISBlox.Services.CLI.Commands.Project; using McMaster.Extensions.CommandLineUtils; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/CmdBase.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/CmdBase.cs index 26f41c7..6865cd5 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/CmdBase.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/CmdBase.cs @@ -1,4 +1,8 @@ -using GISBlox.Services.CLI.Utils; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using GISBlox.Services.CLI.Utils; using GISBlox.Services.SDK; using McMaster.Extensions.CommandLineUtils; using System; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/LoginCmd.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/LoginCmd.cs index a1cf1be..bb0907d 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/LoginCmd.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/LoginCmd.cs @@ -1,4 +1,8 @@ -using GISBlox.Services.CLI.Utils; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using GISBlox.Services.CLI.Utils; using McMaster.Extensions.CommandLineUtils; using System; using System.Threading.Tasks; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/LogoutCmd.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/LogoutCmd.cs index ff13e04..344bdfd 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/LogoutCmd.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/LogoutCmd.cs @@ -1,4 +1,8 @@ -using McMaster.Extensions.CommandLineUtils; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using McMaster.Extensions.CommandLineUtils; using System; using System.Threading.Tasks; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/StatusCmd.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/StatusCmd.cs index bdb92b3..00ad4c1 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/StatusCmd.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Auth/StatusCmd.cs @@ -1,4 +1,8 @@ -using McMaster.Extensions.CommandLineUtils; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using McMaster.Extensions.CommandLineUtils; using System; using System.Linq; using System.Threading.Tasks; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Convert/ConvertCmd.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Convert/ConvertCmd.cs index 1561323..40934c8 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Convert/ConvertCmd.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Convert/ConvertCmd.cs @@ -1,4 +1,8 @@ -using GISBlox.Services.SDK.Models; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using GISBlox.Services.SDK.Models; using McMaster.Extensions.CommandLineUtils; using System; using System.Threading.Tasks; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Project/ToCoordinateCmd.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Project/ToCoordinateCmd.cs index 39e3883..ed332c2 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Project/ToCoordinateCmd.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Project/ToCoordinateCmd.cs @@ -1,8 +1,13 @@ -using GISBlox.Services.CLI.Utils; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using GISBlox.Services.CLI.Utils; using GISBlox.Services.SDK.Models; using McMaster.Extensions.CommandLineUtils; using System; using System.Collections.Generic; +using System.Globalization; using System.Threading.Tasks; namespace GISBlox.Services.CLI.Commands.Project @@ -61,12 +66,12 @@ protected override async Task OnExecute(CommandLineApplication app) if (IncludeSource) { Location location = await GISBloxClient.Projection.ToWGS84Complete(p, Decimals > 0 ? Decimals : -1); - OutputToConsole($"X: { location.X } Y: { location.Y } Lat: { location.Lat.ToString(System.Globalization.CultureInfo.InvariantCulture) } Lon: { location.Lon.ToString(System.Globalization.CultureInfo.InvariantCulture) }", ConsoleColor.Green); + OutputToConsole(PositionParser.LocationToString(location, ";", false, XYFormat ? CoordinateOrderEnum.LatLon : CoordinateOrderEnum.LonLat, CultureInfo.CurrentCulture), ConsoleColor.Green); } else { - Coordinate coordinate = await GISBloxClient.Projection.ToWGS84(p, Decimals > 0 ? Decimals : -1); - OutputToConsole($"Lat: { coordinate.Lat.ToString(System.Globalization.CultureInfo.InvariantCulture) } Lon: { coordinate.Lon.ToString(System.Globalization.CultureInfo.InvariantCulture) }", ConsoleColor.Green); + Coordinate coordinate = await GISBloxClient.Projection.ToWGS84(p, Decimals > 0 ? Decimals : -1); + OutputToConsole(PositionParser.CoordinateToString(coordinate, ";", XYFormat ? CoordinateOrderEnum.LatLon : CoordinateOrderEnum.LonLat, CultureInfo.CurrentCulture), ConsoleColor.Green); } return 0; } @@ -81,12 +86,12 @@ protected override async Task OnExecute(CommandLineApplication app) if (IncludeSource) { List locations = await GISBloxClient.Projection.ToWGS84Complete(rdPoints, Decimals > 0 ? Decimals : -1); - await IO.SaveToCSVFile(OutputFile, Separator, locations); + await IO.SaveToCSVFile(OutputFile, ";", locations, false, XYFormat ? CoordinateOrderEnum.LatLon : CoordinateOrderEnum.LonLat, CultureInfo.CurrentCulture); } else { List coordinates = await GISBloxClient.Projection.ToWGS84(rdPoints, Decimals > 0 ? Decimals : -1); - await IO.SaveToCSVFile(OutputFile, Separator, rdPoints); + await IO.SaveToCSVFile(OutputFile, ";", coordinates, XYFormat ? CoordinateOrderEnum.LatLon : CoordinateOrderEnum.LonLat, CultureInfo.CurrentCulture); } OutputToConsole($"Output saved to file '{ OutputFile }'", ConsoleColor.Green); return 0; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Project/ToRDNewCmd.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Project/ToRDNewCmd.cs index df3dcfc..cbb3e11 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Project/ToRDNewCmd.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Commands/Project/ToRDNewCmd.cs @@ -1,8 +1,13 @@ -using GISBlox.Services.CLI.Utils; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using GISBlox.Services.CLI.Utils; using GISBlox.Services.SDK.Models; using McMaster.Extensions.CommandLineUtils; using System; using System.Collections.Generic; +using System.Globalization; using System.Threading.Tasks; namespace GISBlox.Services.CLI.Commands.Project @@ -58,12 +63,12 @@ protected override async Task OnExecute(CommandLineApplication app) if (IncludeSource) { Location location = await GISBloxClient.Projection.ToRDSComplete(c); - OutputToConsole($"Lat: { location.Lat.ToString(System.Globalization.CultureInfo.InvariantCulture) } Lon: { location.Lon.ToString(System.Globalization.CultureInfo.InvariantCulture) } X: { location.X } Y: { location.Y }", ConsoleColor.Green); + OutputToConsole(PositionParser.LocationToString(location, ";", true, LatLonFormat ? CoordinateOrderEnum.LatLon : CoordinateOrderEnum.LonLat, CultureInfo.CurrentCulture), ConsoleColor.Green); } else { RDPoint rdPoint = await GISBloxClient.Projection.ToRDS(c); - OutputToConsole($"X: { rdPoint.X } Y: { rdPoint.Y }", ConsoleColor.Green); + OutputToConsole(PositionParser.RDPointToString(rdPoint, ";", LatLonFormat ? RDPointOrderEnum.XY : RDPointOrderEnum.YX, CultureInfo.CurrentCulture), ConsoleColor.Green); } return 0; } @@ -77,13 +82,13 @@ protected override async Task OnExecute(CommandLineApplication app) OutputToConsole("Writing output..."); if (IncludeSource) { - List locations = await GISBloxClient.Projection.ToRDSComplete(coordinates); - await IO.SaveToCSVFile(OutputFile, Separator, locations); + List locations = await GISBloxClient.Projection.ToRDSComplete(coordinates); + await IO.SaveToCSVFile(OutputFile, ";", locations, true, LatLonFormat ? CoordinateOrderEnum.LatLon : CoordinateOrderEnum.LonLat, CultureInfo.CurrentCulture); } else { List rdPoints = await GISBloxClient.Projection.ToRDS(coordinates); - await IO.SaveToCSVFile(OutputFile, Separator, rdPoints); + await IO.SaveToCSVFile(OutputFile, ";", rdPoints, LatLonFormat ? RDPointOrderEnum.XY : RDPointOrderEnum.YX, CultureInfo.CurrentCulture); } OutputToConsole($"Output saved to file '{ OutputFile }'", ConsoleColor.Green); return 0; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Program.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Program.cs index 653d6f3..b2ba0f3 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Program.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Program.cs @@ -1,4 +1,8 @@ -using Microsoft.Extensions.Configuration; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using System; using System.IO; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Properties/launchSettings.json b/GISBlox.Services.CLI/GISBlox.Services.CLI/Properties/launchSettings.json index 4973112..c235127 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Properties/launchSettings.json +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "GISBlox.Services.CLI": { "commandName": "Project", - "commandLineArgs": "project to-wgs84 -i \"C:\\Users\\thirt\\OneDrive\\Desktop\\test-to-wgs84.txt\" -o \"C:\\Users\\thirt\\OneDrive\\Desktop\\testout-to-wgs84.csv\" -x true -h false -s \";\" -is -d 2" + "commandLineArgs": "project to-rds -i \"C:\\Users\\thirt\\OneDrive\\Desktop\\testdata.txt\" -o \"C:\\Users\\thirt\\OneDrive\\Desktop\\testout.txt\" -l true -h true -s \";\" -is" } } } \ No newline at end of file diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/UserProfile.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/UserProfile.cs index c5f85e4..2e944ac 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/UserProfile.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/UserProfile.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ namespace GISBlox.Services.CLI { diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/Enums.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/Enums.cs index 81664f5..33d6ded 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/Enums.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/Enums.cs @@ -1,4 +1,8 @@ -namespace GISBlox.Services.CLI.Utils +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +namespace GISBlox.Services.CLI.Utils { internal enum CoordinateOrderEnum { LatLon, LonLat, Invariant }; diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/IO.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/IO.cs index f421da6..4904b34 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/IO.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/IO.cs @@ -1,4 +1,8 @@ -using BartelsOnline.Office.IO.Excel; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using BartelsOnline.Office.IO.Excel; using BartelsOnline.Office.IO.Excel.Models; using GISBlox.Services.SDK.Models; using System; @@ -16,18 +20,18 @@ internal class IO /// Loads coordinates from a file. /// /// The fully-qualified file name. - /// The character that was used to separate the coordinates in the file. + /// The character that was used to separate the coordinates in the file. /// Determines whether to skip the first line in the file. Ignored if the input file is an Excel workbook. /// Specifies whether the coordinates in the file are stored in lat/lon or lon/lat order. /// The Excel range that contains the coordinates to project (if applicable). /// A List with Coordinate types. - public static async Task> LoadCoordinatesFromFile(string fileName, string columnSeparator, bool firstLineContainsHeaders, CoordinateOrderEnum coordinateOrder, string inputRange) + public static async Task> LoadCoordinatesFromFile(string fileName, string separator, bool firstLineContainsHeaders, CoordinateOrderEnum coordinateOrder, string inputRange) { FileFormatEnum format = ParseFileFormat(fileName); switch (format) { case FileFormatEnum.CSV: - return await LoadCoordinatesFromCSVFile(fileName, columnSeparator, firstLineContainsHeaders, coordinateOrder); + return await LoadCoordinatesFromCSVFile(fileName, separator, firstLineContainsHeaders, coordinateOrder); case FileFormatEnum.XLS: return await LoadCoordinatesFromXLSFile(fileName, inputRange, coordinateOrder); default: @@ -39,15 +43,15 @@ public static async Task> LoadCoordinatesFromFile(string fileNa /// Loads coordinates from a file. /// /// The fully-qualified file name. - /// The character that was used to separate the coordinates in the file. + /// The character that was used to separate the coordinates in the file. /// Determines whether to skip the first line in the file. /// Specifies whether the coordinates in the file are stored in lat/lon or lon/lat order. /// A List with Coordinate types. - private static async Task> LoadCoordinatesFromCSVFile(string fileName, string columnSeparator, bool firstLineContainsHeaders, CoordinateOrderEnum coordinateOrder) + private static async Task> LoadCoordinatesFromCSVFile(string fileName, string separator, bool firstLineContainsHeaders, CoordinateOrderEnum coordinateOrder) { - if (string.IsNullOrEmpty(columnSeparator)) + if (string.IsNullOrEmpty(separator)) { - throw new ArgumentNullException(nameof(columnSeparator)); + throw new ArgumentNullException(nameof(separator)); } List coordinates = new(); @@ -62,7 +66,7 @@ private static async Task> LoadCoordinatesFromCSVFile(string fi string rowData = await sr.ReadLineAsync(); if (!string.IsNullOrEmpty(rowData)) { - coordinates.Add(PositionParser.CoordinateFromString(rowData, columnSeparator, coordinateOrder)); + coordinates.Add(PositionParser.CoordinateFromString(rowData, separator, coordinateOrder)); } } } @@ -94,18 +98,18 @@ private static async Task> LoadCoordinatesFromXLSFile(string fi /// Loads RDNew locations from a file. /// /// The fully-qualified file name. - /// The character that was used to separate the coordinates in the file. + /// The character that was used to separate the coordinates in the file. /// Determines whether to skip the first line in the file. /// Specifies whether the locations in the file are stored in X-Y or Y-X order. /// The Excel range that contains the coordinates to project (if applicable). /// A List with RDPoint types. - public static async Task> LoadRDPointsFromFile(string fileName, string columnSeparator, bool firstLineContainsHeaders, RDPointOrderEnum rdPointOrder, string inputRange) + public static async Task> LoadRDPointsFromFile(string fileName, string separator, bool firstLineContainsHeaders, RDPointOrderEnum rdPointOrder, string inputRange) { FileFormatEnum format = ParseFileFormat(fileName); switch (format) { case FileFormatEnum.CSV: - return await LoadRDPointsFromCSVFile(fileName, columnSeparator, firstLineContainsHeaders, rdPointOrder); + return await LoadRDPointsFromCSVFile(fileName, separator, firstLineContainsHeaders, rdPointOrder); case FileFormatEnum.XLS: return await LoadRDPointsFromXLSFile(fileName, inputRange, rdPointOrder); default: @@ -117,15 +121,15 @@ public static async Task> LoadRDPointsFromFile(string fileName, st /// Loads RDNew locations from a file. /// /// The fully-qualified file name. - /// The character that was used to separate the coordinates in the file. + /// The character that was used to separate the coordinates in the file. /// Determines whether to skip the first line in the file. /// Specifies whether the locations in the file are stored in X-Y or Y-X order. /// A List with RDPoint types. - private static async Task> LoadRDPointsFromCSVFile(string fileName, string columnSeparator, bool firstLineContainsHeaders, RDPointOrderEnum rdPointOrder) + private static async Task> LoadRDPointsFromCSVFile(string fileName, string separator, bool firstLineContainsHeaders, RDPointOrderEnum rdPointOrder) { - if (string.IsNullOrEmpty(columnSeparator)) + if (string.IsNullOrEmpty(separator)) { - throw new ArgumentNullException(nameof(columnSeparator)); + throw new ArgumentNullException(nameof(separator)); } List points = new(); @@ -140,7 +144,7 @@ private static async Task> LoadRDPointsFromCSVFile(string fileName string rowData = await sr.ReadLineAsync(); if (!string.IsNullOrEmpty(rowData)) { - points.Add(PositionParser.RDPointFromString(rowData, columnSeparator, rdPointOrder)); + points.Add(PositionParser.RDPointFromString(rowData, separator, rdPointOrder)); } } } @@ -176,18 +180,20 @@ private static async Task> LoadRDPointsFromXLSFile(string fileName /// Saves coordinates to a file. /// /// The fully-qualified file name. - /// The character that separates the coordinates in the file. + /// The character that separates the coordinates in the file. /// A List with Coordinate types. + /// The order in which to save the coordinate pairs. + /// Culture-specific formatting options /// - public static async Task SaveToCSVFile(string fileName, string columnSeparator, List coordinates) + public static async Task SaveToCSVFile(string fileName, string separator, List coordinates, CoordinateOrderEnum coordinateOrder, IFormatProvider formatProvider) { - if (string.IsNullOrEmpty(columnSeparator)) columnSeparator = ";"; + if (string.IsNullOrEmpty(separator)) separator = ";"; using (StreamWriter sw = new(CorrectOutputFileType(fileName))) { foreach (var coordinate in coordinates) { - await sw.WriteLineAsync($"{coordinate.Lat.ToString(System.Globalization.CultureInfo.InvariantCulture)}{columnSeparator}{coordinate.Lon.ToString(System.Globalization.CultureInfo.InvariantCulture)}"); + await sw.WriteLineAsync(PositionParser.CoordinateToString(coordinate, separator, coordinateOrder, formatProvider)); } } } @@ -196,18 +202,18 @@ public static async Task SaveToCSVFile(string fileName, string columnSeparator, /// Saves RDNew locations to a file. /// /// The fully-qualified file name. - /// The character that separates the coordinates in the file. + /// The character that separates the locations in the file. /// A List with RDPoint types. /// - public static async Task SaveToCSVFile(string fileName, string columnSeparator, List points) + public static async Task SaveToCSVFile(string fileName, string separator, List points, RDPointOrderEnum rdPointOrder, IFormatProvider formatProvider) { - if (string.IsNullOrEmpty(columnSeparator)) columnSeparator = ";"; + if (string.IsNullOrEmpty(separator)) separator = ";"; using (StreamWriter sw = new(CorrectOutputFileType(fileName))) { foreach (var point in points) { - await sw.WriteLineAsync($"{point.X}{columnSeparator}{point.Y}"); + await sw.WriteLineAsync(PositionParser.RDPointToString(point, separator, rdPointOrder, formatProvider)); } } } @@ -216,18 +222,21 @@ public static async Task SaveToCSVFile(string fileName, string columnSeparator, /// Save Location types to a file. /// /// The fully-qualified file name. - /// The character that separates the coordinates in the file. + /// The character that separates the coordinates in the file. /// A List with Location types. + /// True to output the coordinate of the location first, False to output the RDPoint first. + /// The order in which to save the coordinate pairs. + /// Culture-specific formatting options /// - public static async Task SaveToCSVFile(string fileName, string columnSeparator, List locations) + public static async Task SaveToCSVFile(string fileName, string separator, List locations, bool coordinateFirst, CoordinateOrderEnum coordinateOrder, IFormatProvider formatProvider) { - if (string.IsNullOrEmpty(columnSeparator)) columnSeparator = ";"; + if (string.IsNullOrEmpty(separator)) separator = ";"; using (StreamWriter sw = new(CorrectOutputFileType(fileName))) { foreach (var location in locations) - { - await sw.WriteLineAsync($"{location.X}{columnSeparator}{location.Y}{columnSeparator}{location.Lat.ToString(System.Globalization.CultureInfo.InvariantCulture)}{columnSeparator}{location.Lon.ToString(System.Globalization.CultureInfo.InvariantCulture)}"); + { + await sw.WriteLineAsync(PositionParser.LocationToString(location, separator, coordinateFirst, coordinateOrder, formatProvider)); } } } diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/PositionParser.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/PositionParser.cs index 0b3b655..6f04726 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/PositionParser.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/PositionParser.cs @@ -1,5 +1,10 @@ -using GISBlox.Services.SDK.Models; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using GISBlox.Services.SDK.Models; using System; +using System.Globalization; namespace GISBlox.Services.CLI.Utils { @@ -44,6 +49,30 @@ public static Coordinate CoordinateFromPoints(string coordinatePointA, string co return (coordinateOrder == CoordinateOrderEnum.LatLon) ? new Coordinate(a, b) : new Coordinate(b, a); } + /// + /// Converts a Coordinate type into a string. + /// + /// A Coordinate type. + /// The character to separate the coordinates. + /// Specifies whether the coordinate is in lat/lon or lon/lat order. + /// Culture-specific formatting options. + /// A string + public static string CoordinateToString(Coordinate c, string separator, CoordinateOrderEnum coordinateOrder, IFormatProvider formatProvider) + { + if (c == null) + { + throw new ArgumentNullException(nameof(c)); + } + if (coordinateOrder == CoordinateOrderEnum.LatLon) + { + return $"{ c.Lat.ToString(formatProvider) }{ separator }{ c.Lon.ToString(formatProvider) }"; + } + else + { + return $"{ c.Lon.ToString(formatProvider) }{ separator }{ c.Lat.ToString(formatProvider) }"; + } + } + /// /// Converts an RD location string into a RDPoint type. /// @@ -83,6 +112,30 @@ public static RDPoint RDPointFromPoints(string rdPointA, string rdPointB, RDPoin return (rdPointOrder == RDPointOrderEnum.XY) ? new RDPoint(a, b) : new RDPoint(b, a); } + /// + /// Converts an RDPoint type into a string. + /// + /// An RDPoint type. + /// The character to separate the location pairs. + /// Specifies whether the location points are in X/Y or Y/X order. + /// Culture-specific formatting options. + /// A string + public static string RDPointToString(RDPoint rdPoint, string separator, RDPointOrderEnum rdPointOrder, IFormatProvider formatProvider) + { + if (rdPoint == null) + { + throw new ArgumentNullException(nameof(rdPoint)); + } + if (rdPointOrder == RDPointOrderEnum.XY) + { + return $"{ rdPoint.X.ToString(formatProvider) }{ separator }{ rdPoint.Y.ToString(formatProvider) }"; + } + else + { + return $"{ rdPoint.Y.ToString(formatProvider) }{ separator }{ rdPoint.X.ToString(formatProvider) }"; + } + } + /// /// Splits the specified position into two strings. /// @@ -106,7 +159,7 @@ private static string[] GetCoordinatePair(string position, string separator) /// A double type. private static double ParseCoordinatePoint(string point) { - if (!double.TryParse(point, System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out double value)) + if (!double.TryParse(point, NumberStyles.Number | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double value)) { throw new ArithmeticException($"Invalid coordinate: point '{ point }' is not of type 'double'."); } @@ -120,11 +173,50 @@ private static double ParseCoordinatePoint(string point) /// An int type. private static int ParseRDPoint(string point) { - if (!int.TryParse(point, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out int value)) + if (!int.TryParse(point, NumberStyles.Number, CultureInfo.InvariantCulture, out int value)) { throw new ArithmeticException($"Invalid RDPoint: point '{ point }' is not of type 'int'."); } return value; } + + /// + /// Converts a Location type into a string. + /// + /// A Location type + /// The character to separate the locations. + /// True to output the coordinate of the location first, False to output the RDPoint first. + /// Specifies whether the location is in lat/lon/X/Y or lon/lat/Y/X order. + /// Culture-specific formatting options. + /// + public static string LocationToString(Location l, string separator, bool coordinateFirst, CoordinateOrderEnum coordinateOrder, IFormatProvider formatProvider) + { + if (l == null) + { + throw new ArgumentNullException(nameof(l)); + } + if (coordinateOrder == CoordinateOrderEnum.LatLon) + { + if (coordinateFirst) + { + return $"{ l.Lat.ToString(formatProvider) }{ separator }{ l.Lon.ToString(formatProvider) }{ separator }{ l.X.ToString(formatProvider) }{ separator }{ l.Y.ToString(formatProvider) }"; + } + else + { + return $"{ l.X.ToString(formatProvider) }{ separator }{ l.Y.ToString(formatProvider) }{ separator }{ l.Lat.ToString(formatProvider) }{ separator }{ l.Lon.ToString(formatProvider) }"; + } + } + else + { + if (coordinateFirst) + { + return $"{ l.Lon.ToString(formatProvider) }{ separator }{ l.Lat.ToString(formatProvider) }{ separator }{ l.Y.ToString(formatProvider) }{ separator }{ l.X.ToString(formatProvider) }"; + } + else + { + return $"{ l.Y.ToString(formatProvider) }{ separator }{ l.X.ToString(formatProvider) }{ separator }{ l.Lon.ToString(formatProvider) }{ separator }{ l.Lat.ToString(formatProvider) }"; + } + } + } } } diff --git a/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/Security.cs b/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/Security.cs index b468125..df861a2 100644 --- a/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/Security.cs +++ b/GISBlox.Services.CLI/GISBlox.Services.CLI/Utils/Security.cs @@ -1,4 +1,8 @@ -using System; +// ------------------------------------------------------------ +// Copyright (c) Bartels Online. All rights reserved. +// ------------------------------------------------------------ + +using System; using System.IO; using System.Runtime.InteropServices; using System.Security;