|
1 | 1 | using BDMS.Models;
|
2 |
| -using CsvHelper; |
3 |
| -using CsvHelper.Configuration; |
4 |
| -using Humanizer; |
5 | 2 | using NetTopologySuite.Mathematics;
|
6 | 3 | using NetTopologySuite.Utilities;
|
7 |
| -using System.Globalization; |
8 | 4 |
|
9 |
| -namespace BDMS.BoreholeGeometry; |
| 5 | +namespace BDMS; |
10 | 6 |
|
11 |
| -public static class Helper |
| 7 | +public static class BoreholeGeometryExtensions |
12 | 8 | {
|
13 |
| - internal static readonly CsvConfiguration CsvConfig = new(new CultureInfo("de-CH")) |
14 |
| - { |
15 |
| - Delimiter = ";", |
16 |
| - IgnoreReferences = true, |
17 |
| - PrepareHeaderForMatch = args => args.Header.Humanize(LetterCasing.Title), |
18 |
| - MissingFieldFound = null, |
19 |
| - }; |
20 |
| - |
21 | 9 | /// <summary>
|
22 |
| - /// Get the CSV header <see cref="CsvHelper"/> expects to read a class <typeparamref name="T"/>. |
23 |
| - /// Uses the map generated by <see cref="CsvHelper.CsvContext.AutoMap{T}()"/>. |
24 |
| - /// If a property has multiple possible column names only the first is considered. |
| 10 | + /// Get the TVD of <paramref name="depthMD"/> according to the <paramref name="geometry"/> if the geometry exists. |
25 | 11 | /// </summary>
|
26 |
| - /// <typeparam name="T">The class to get the header for.</typeparam> |
27 |
| - internal static string GetCSVHeader<T>() |
| 12 | + /// <param name="geometry">The list of <see cref="BoreholeGeometryElement"/> representing the borehole's path geometry.</param> |
| 13 | + /// <param name="depthMD">The measured depth (MD) at which to calculate the TVD.</param> |
| 14 | + /// <returns>The TVD at <paramref name="depthMD"/> if the geometry exists; otherwise <see langword="null"/>.</returns> |
| 15 | + internal static double? GetTVDIfGeometryExists(this List<BoreholeGeometryElement> geometry, double? depthMD) |
28 | 16 | {
|
29 |
| - var context = new CsvContext(CsvConfig); |
30 |
| - var map = context.AutoMap<T>(); |
31 |
| - return string.Join("; ", map.MemberMaps |
32 |
| - .Select(m => |
| 17 | + if (geometry == null || geometry.Count < 2) |
| 18 | + { |
| 19 | + if (depthMD != null && depthMD >= 0) |
33 | 20 | {
|
34 |
| - var name = m.Data.Names.FirstOrDefault(m.Data.Member.Name); |
35 |
| - return m.Data.IsOptional ? $"[{name}]" : name; |
36 |
| - })); |
37 |
| - } |
| 21 | + // Return the depthMD unchanged as if the borehole is perfectly vertical and infinitely long. |
| 22 | + return depthMD; |
| 23 | + } |
| 24 | + } |
| 25 | + else if (depthMD != null) |
| 26 | + { |
| 27 | + try |
| 28 | + { |
| 29 | + return geometry.GetDepthTVD(depthMD.Value); |
| 30 | + } |
| 31 | + catch (ArgumentOutOfRangeException) |
| 32 | + { |
| 33 | + // Exception is ignored so that the method returns null in case the input was invalid. |
| 34 | + } |
| 35 | + } |
38 | 36 |
|
39 |
| - private static readonly IComparer<BoreholeGeometryElement> geometryMDComparer = Comparer<BoreholeGeometryElement>.Create((a, b) => a.MD.CompareTo(b.MD)); |
| 37 | + return null; |
| 38 | + } |
40 | 39 |
|
41 | 40 | /// <summary>
|
42 | 41 | /// Get the TVD of <paramref name="depthMD"/> according to the <paramref name="geometry"/>.
|
@@ -130,6 +129,8 @@ private static double InterpolateDepthTVD(List<BoreholeGeometryElement> geometry
|
130 | 129 | }
|
131 | 130 | }
|
132 | 131 |
|
| 132 | + private static readonly IComparer<BoreholeGeometryElement> geometryMDComparer = Comparer<BoreholeGeometryElement>.Create((a, b) => a.MD.CompareTo(b.MD)); |
| 133 | + |
133 | 134 | internal static Vector3D ToVector3D(this BoreholeGeometryElement element)
|
134 | 135 | => new Vector3D(element.X, element.Y, element.Z);
|
135 | 136 |
|
|
0 commit comments