Hi,
These are my conversions till now.
Do you recommended to add more option according to sample data or you have list of option to
add?
Thanks,
/// <summary>
/// Construct converter-specific options for Aspose conversions.
/// <summary>
/// Construct converter-specific options for Aspose conversions.
/// </summary>
/// <param name="sourceFormat">Source format option (e.g. "Gml").</param>
/// <param name="targetFormat">Target format option (not currently used but present for future use).</param>
/// <returns>A populated <see cref="ConversionOptions"/> instance with format-specific settings applied.</returns>
/// <summary>
/// Build a new, pure <see cref="ConversionOptions"/> instance and populate driver-specific reader or writer
/// options required by certain source or destination formats. The method performs case-insensitive
/// checks and sets only the options necessary for correct processing (no I/O or driver instantiation).
/// Current mappings include:
/// - source "Gml": sets <see cref="ConversionOptions.SourceDriverOptions"/> to <see cref="GmlOptions"/> with <see cref="GmlOptions.RestoreSchema"/> = true.
/// - target "GeoPackage": sets <see cref="ConversionOptions.DestinationDriverOptions"/> to <see cref="GeoPackageOptions"/>.
/// - target "Gpx": sets <see cref="ConversionOptions.DestinationDriverOptions"/> to <see cref="GpxOptions"/> with <c>WritePolygonsAsLines = true</c>.
/// - target "MapInfoTab" and "Shapefile": set destination options that ignore invalid/oversized DBF values.
/// Returns an empty-but-populated <see cref="ConversionOptions"/> when no special handling is required.
/// </summary>
/// <remarks>
/// <para>
/// Builds and returns a new <see cref="ConversionOptions"/> instance populated with
/// driver-specific reader/writer options required by certain formats. The method is
/// intentionally pure and performs no I/O — it returns a lightweight options carrier
/// that callers pass to Aspose driver operations.
/// </para>
/// <para>
/// Current behavior (case-insensitive comparisons):
/// - When <paramref name="sourceFormat"/> equals "Gml": sets <see cref="ConversionOptions.SourceDriverOptions"/>
/// to a <see cref="GmlOptions"/> instance with <see cref="GmlOptions.RestoreSchema"/> = <c>true</c>.
/// This helps handle GML inputs that may be missing attribute collection schema information.
/// - When <paramref name="targetFormat"/> equals "GeoPackage": sets
/// <see cref="ConversionOptions.DestinationDriverOptions"/> to a new <see cref="GeoPackageOptions"/>.
/// - When <paramref name="targetFormat"/> equals "Gpx": sets
/// <see cref="ConversionOptions.DestinationDriverOptions"/> to a new <see cref="GpxOptions"/>
/// with <c>WritePolygonsAsLines = true</c> to avoid unsupported polygon geometries in GPX.
/// </para>
/// <para>
/// /// Notes and extension points:
/// - The method returns a new <see cref="ConversionOptions"/> even when no specific options are applied.
/// - Add or adjust format-specific handling here when new driver options are required.
/// - Comparisons are case-insensitive to simplify caller usage.
/// - Keep this method focused on option composition only; actual driver invocation and I/O remain the
/// responsibility of converter implementations.
/// </remarks>
public static ConversionOptions BuildConversionOptions(string sourceFormat, string targetFormat)
{
var options = new ConversionOptions();
// Handle source-specific options
// Gml handling
// The input file/s can be with or without attribute collection schema.
// To handle both cases we need to set gmlOptions.RestoreSchema = true (it is false by default)
// for the source driver.
if (sourceFormat.Equals("Gml", StringComparison.OrdinalIgnoreCase))
{
options.SourceDriverOptions = new GmlOptions { RestoreSchema = true };
}
// GeoPackage handling
// GeoPackage requires explicit destination driver options to be set for proper conversion
else if (targetFormat.Equals("GeoPackage", StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new GeoPackageOptions();
}
// Gpx handling
// Using of “WritePolygonsAsLines” Option for destination Gpx format.
// GpxDriver doesn't support 'Polygon' and 'MultiPolygon' geometry type by design.
// But you can use option WritePolygonsAsLines = true for conversions to avoid this.
else if (targetFormat.Equals("Gpx", StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new GpxOptions() { WritePolygonsAsLines = true };
}
// MapInfoTab handling
// When this flag is set to true, the driver skips any feature whose attribute value exceeds
// the DBF field limit(254 characters).The offending records are not written to the output file,
// so they will be missing in the resulting MapInfoTab or Shapefile.You can verify the effect by opening the converted file in QGIS –
// the features with oversized attributes simply won’t appear.
else if (targetFormat.Equals("MapInfoTab", StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new MapInfoTabOptions() { IsIgnoreWrongData = true };
}
// Shapefile handling
// When this flag is set to true, the driver skips any feature whose attribute value exceeds
// the DBF field limit(254 characters).The offending records are not written to the output file,
// so they will be missing in the resulting MapInfoTab or Shapefile.You can verify the effect by opening the converted file in QGIS –
// the features with oversized attributes simply won’t appear.
else if (targetFormat.Equals("Shapefile", StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new ShapefileOptions() { IsIgnoreWrongData = true };
}
// Add more format-specific handling as needed
return options;
}