GIS Converter - ConverterUtils.BuildOutputPath not handle properly outFileExt
Hi Michel,
First thank you very much for your help.
In continue to : https://learn.microsoft.com/en-us/answers/questions/5658105/gis-convert-from-one-format-to-any-formats
1.Caller:Converters\UniversalGisConverter.cs
// Step 5: Build output path
var outputPath = ConverterUtils.BuildOutputPath(outputFolderPath, gisTargetFormatOption);
2.In ConverterUtils.cs there is problematic row, can you please fix it ? and also the caller.
var outFileExt = maybeOutFileExt ?? FileExtension.Shapefile;//IS it Ok, does can lead to bad conversion.
`/// <summary>`
/// Build a destination output file path using the output folder and a target format option.
/// </summary>
/// <param name="outputFolderPath">Destination folder where the output file will be placed.</param>
/// <param name="gisTargetFormatOption">Canonical target format option (e.g. "Shapefile").</param>
/// <returns>Full path to the intended output file. The file is not created by this method.</returns>
/// <remarks>
/// The method uses a UTC timestamp to produce a collision-resistant file name and attempts to map
/// the provided <paramref name="gisTargetFormatOption"/> to a file extension using
/// <see cref="FileExtensionHelpers.FromOption"/>. When the option cannot be mapped the method
/// falls back to the Shapefile extension and logs a warning.
/// </remarks>
internal static string BuildOutputPath(string outputFolderPath, string gisTargetFormatOption)
{
var timeStamp = DateTime.UtcNow.ToString("yyyyMMdd_HHmmss");
var maybeOutFileExt = FileExtensionHelpers.FromOption(gisTargetFormatOption);
var outFileExt = maybeOutFileExt ?? FileExtension.Shapefile;//IS it Ok, does can lead to bad conversion.
if (maybeOutFileExt == null)
Log.Warn($"BuildOutputPath: could not map option '{gisTargetFormatOption}' to a known FileExtension; falling back to '{outFileExt}'.");
var extDot = FileExtensionHelpers.ToDotExtension(outFileExt);
// Base candidate filename
var baseName = $"output_{timeStamp}";
var candidate = Path.Combine(outputFolderPath, baseName + extDot);
Log.Info($"BuildOutputPath: target output file will be '{candidate}'.");
return candidate;
}
3.The relevant files:
Code
Converters
Models
Thanks in advance,