Optimize build conversion options

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;
    }

Hi Dani,

Thanks for sharing your current implementation. The options you’ve added already cover the most frequently needed scenarios. Below is a concise list of additional driver‑specific options that you may consider exposing, together with a small example of how to extend your method.

Commonly used driver options (Aspose.GIS .NET v 27.2)

Source / Target format Option class Typical use case
Gml (source) GmlOptions – AllowDuplicateFeatureIds, ValidateSchema Control duplicate IDs or schema validation
GeoJson (target) GeoJsonOptions – AllowNonStandardGeometries Permit non‑standard GeoJSON geometries
EsriJson (target) EsriJsonOptions – WriteZValues, WriteMValues Preserve Z/M values when writing
Kml (target) KmlOptions – WriteExtendedData Include extended data attributes
Shapefile (source) ShapefileOptions – IsReadOnly, Encoding Set file encoding or open read‑only
MapInfoTab (target) MapInfoTabOptions – IsWriteWkt, IsIgnoreWrongData Write WKT geometry, ignore invalid DBF fields
Csv (source/target) CsvOptions – Delimiter, HasHeader, Encoding Customize delimiter or header handling
Wkt (source/target) WktOptions – IsParseMultiGeometry Parse multi‑geometry WKT strings
Gdb (source) GeodatabaseOptions – IsReadOnly Open file‑geodatabase in read‑only mode

You can expose any of these options in your helper method by adding additional else if branches. Here is an updated example that demonstrates adding a few of them:

using Aspose.Gis;
using Aspose.Gis.Converters;
using Aspose.Gis.Gml;
using Aspose.Gis.Geodatabase;
using Aspose.Gis.GeoJson;
using Aspose.Gis.Shapefile;
using Aspose.Gis.Csv;

public static ConversionOptions BuildConversionOptions(string sourceFormat, string targetFormat)
{
    var options = new ConversionOptions();

    // Source options
    if (sourceFormat.Equals("Gml", StringComparison.OrdinalIgnoreCase))
    {
        options.SourceDriverOptions = new GmlOptions
        {
            RestoreSchema = true,
            AllowDuplicateFeatureIds = false,   // additional safety
            ValidateSchema = true
        };
    }
    else if (sourceFormat.Equals("Shapefile", StringComparison.OrdinalIgnoreCase))
    {
        options.SourceDriverOptions = new ShapefileOptions
        {
            Encoding = System.Text.Encoding.UTF8,
            IsReadOnly = false
        };
    }
    else if (sourceFormat.Equals("Csv", StringComparison.OrdinalIgnoreCase))
    {
        options.SourceDriverOptions = new CsvOptions
        {
            Delimiter = ',',
            HasHeader = true,
            Encoding = System.Text.Encoding.UTF8
        };
    }
    else if (sourceFormat.Equals("Geodatabase", StringComparison.OrdinalIgnoreCase))
    {
        options.SourceDriverOptions = new GeodatabaseOptions { IsReadOnly = true };
    }

    // Target options
    if (targetFormat.Equals("GeoPackage", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new GeoPackageOptions();
    }
    else if (targetFormat.Equals("Gpx", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new GpxOptions { WritePolygonsAsLines = true };
    }
    else if (targetFormat.Equals("MapInfoTab", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new MapInfoTabOptions { IsIgnoreWrongData = true };
    }
    else if (targetFormat.Equals("Shapefile", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new ShapefileOptions { IsIgnoreWrongData = true };
    }
    else if (targetFormat.Equals("GeoJson", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new GeoJsonOptions
        {
            AllowNonStandardGeometries = true
        };
    }
    else if (targetFormat.Equals("Csv", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new CsvOptions
        {
            Delimiter = ';',
            HasHeader = true,
            Encoding = System.Text.Encoding.UTF8
        };
    }

    return options;
}

Best practices

  1. Keep the method pure: Do not perform any I/O inside the builder; just return a fully populated ConversionOptions instance.
  2. Case‑insensitive checks (as you already do) simplify the API for callers.
  3. Expose only the options that truly affect the conversion – unnecessary settings can make the API harder to use.
  4. Document the supported formats in your library’s README or a separate cheat‑sheet so users know which strings to pass.
  5. Validate formats early (e.g., throw ArgumentException if an unsupported format is supplied) to give clear feedback.

For the complete reference of all driver options, see the official documentation: https://docs.aspose.com/gis/net/driver-options/

If you have specific sample data that requires handling of additional formats (e.g., EsriJson, Kml, Wkt), let me know and I can suggest the exact options to enable.

Hi Alexander,

Can you please answer?

1.Is this the additional list of options beyond mine?
2. What do you recommanded to do, to add option when I found specific sample that not passed? or somethinh else?
3.Do you have samples data for the additional options that I can test it and add it to my data?

Thank you in advance,

Hi, @danies8

These questions not connected with aspose.gis lib.

  1. as you wish
  2. I think depend on situation

Do you use options all the time or only when it need ?

The options that I used above was because of problems with sample data I found during my app and your suggestions.
These options that I used is for all conversions.
Is it OK? No?

This option you should use to finish conversion even if you lost some records or part of attributes value! Not all the time

1.My others option are ok, need to remove something?
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;
}
  1. **IsIgnoreWrongData**
    This option you should use to finish conversion even if you lost some records or part of attributes value! Not all the time
    To remove it ? I do not what the sample data have inside ?
    What you say? To give the conversion to failed and user will fixed it ?

3.Do you have samples data for the additional options that I can test it and add it to my data?
Not yet.

  1. So, when to use options?
    5.Your lib is not smart to use the option when it happened/needed ?

Waiting to your answer, it is very crucial issue,

Hi, @danies8
Why you wanna hardcode our options? It’s better to use it. User can adjustment his conversion. For your converter it will be also better.

Hi Alexander.

The user is not sophisticated, he put file and converts.
So I back to my questions:
1..My others option are ok, need to remove something?
2.**IsIgnoreWrongData ** to remove it, if yes if conversion failed
it will need to fix the input ? is it ?

Command line:
Console.WriteLine(“GIS Converter CLI Tool”);
Console.WriteLine(“----------------------”);
Console.WriteLine();
Console.WriteLine(“Usage:”);
Console.WriteLine(" GISConverter.Cli.exe gis_convert [Log <log_path> [level]]“);
Console.WriteLine();
Console.WriteLine(“Arguments:”);
Console.WriteLine(” - GIS input file (single file or archive)“);
Console.WriteLine(” Note: Paths with spaces can be unquoted, but quoting is recommended");
Console.WriteLine(" (e.g., "C:\My Input\input.zip")“);
Console.WriteLine(” Supported archive formats: 7Z, BZ2, GZ, RAR, TAR, TGZ, XZ, ZIP");
Console.WriteLine();
Console.WriteLine(" - Target GIS format. Use --help-formats for full list");
Console.WriteLine();
Console.WriteLine(" - Output folder where converted files will be saved");
Console.WriteLine(" The system creates output files inside this folder");
Console.WriteLine();
Console.WriteLine(" - Temporary folder used during processing");
Console.WriteLine();
Console.WriteLine(" [Log <log_path> [level]]“);
Console.WriteLine(” - Optional. To enable logging include ‘Log’ followed by log file path and log level");
Console.WriteLine(" Log levels: ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF");
Console.WriteLine(" Note: Paths with spaces can be unquoted, but quoting is recommended");
Console.WriteLine(" (e.g., Log "C:\My Logs\run.log" DEBUG)“);
Console.WriteLine();
Console.WriteLine(“Options:”);
Console.WriteLine(” help, --help, -h Show this help");
Console.WriteLine(" --help-formats Show detailed format descriptions");

ShowHelpFormats

///


/// Writes the detailed supported formats help to the console.
///

///
/// - This output is intended to be relatively static; tests and documentation refer to these descriptions.
/// - Keep the individual format blocks short and factual (purpose, required files).
/// - Avoid embedding environment-specific paths or examples that may not be portable.
///
static void ShowHelpFormats()
{
Console.WriteLine(“Supported GIS Formats”);
Console.WriteLine(“---------------------”);
Console.WriteLine();
Console.WriteLine(" - Available GIS target conversion format options:");
Console.WriteLine();

   Console.WriteLine("       ORG:");
   Console.WriteLine("                Converts the format of the input to itself");
   Console.WriteLine();

   Console.WriteLine("       Csv:");
   Console.WriteLine("                Purpose:Plain text format for tabular data.");
   Console.WriteLine("                Files needed: a single .csv file.");
   Console.WriteLine();

   Console.WriteLine("       EsriJson:");
   Console.WriteLine("                Purpose:a JSON format used by Esri ArcGis software to reprsent geographic features.");
   Console.WriteLine("                Similar to GeoJson but with Esri-specific attributes.");
   Console.WriteLine("                Files needed: a single .esrijson or .json file.");
   Console.WriteLine();

   Console.WriteLine("       Gdb:");
   Console.WriteLine("                Purpose:a folder-based database format from Esri storing multiple feature classes and tables.");
   Console.WriteLine("                Files needed: FileGdb can be represent as one table only.");
   Console.WriteLine("                In case of one table - .gdbtable and .gdbtablx as an archive file.");
   Console.WriteLine();

   Console.WriteLine("       GeoJson:");
   Console.WriteLine("                Purpose:a widely used open standard format for encoding variety of geographic data structures.");
   Console.WriteLine("                Files needed: a single .geojson or .json file.");
   Console.WriteLine();

   Console.WriteLine("       GeoJsonSeq:");
   Console.WriteLine("                Purpose:GeoJson sequence, where each line is an individual GeoJson feature(streaming format).");
   Console.WriteLine("                It’s json format with special structure.");
   Console.WriteLine("                Files needed: a single .json or .jsonl or .ndjson file.");
   Console.WriteLine();

   Console.WriteLine("       GeoPackage:");
   Console.WriteLine("                Purpose:SQLite-based OGC standard for vector and raster data - modern, compact, and widely support.");
   Console.WriteLine("                Files needed: a single .gpkg file.");
   Console.WriteLine();

   Console.WriteLine("       Gml:");
   Console.WriteLine("                Purpose:Xml based Geography markup Language, often used in government or standards-based data.");
   Console.WriteLine("                Files needed: a single .gml file or .gml file (sometimes with .xsd schema) as an archive file.");
   Console.WriteLine();

   Console.WriteLine("       Gpx:");
   Console.WriteLine("                Purpose:Xml schema for storing GPs track, waypoint and route data.");
   Console.WriteLine("                Files needed: a single .gpx file.");
   Console.WriteLine();

   Console.WriteLine("       Kml:");
   Console.WriteLine("                Purpose:XML based format used by Goggle Earth for geographic annotation and visualization.");
   Console.WriteLine("                Files needed: a single .kml file.");
   Console.WriteLine();

   Console.WriteLine("       Kmz:");
   Console.WriteLine("                Purpose:XML based format used by Goggle Earth for geographic annotation and visualization.");
   Console.WriteLine("                .kmz is a zipped of .kml.");
   Console.WriteLine("                Files needed: a single .kmz file.");
   Console.WriteLine();

   Console.WriteLine("       MapInfoInterchange:");
   Console.WriteLine("                Purpose:Text based format used by MapInfo system.");
   Console.WriteLine("                Files needed: .mif mandatory, .mid - contains attribue info and not mandatory.");
   Console.WriteLine("                If both files are supplied give it as an archive file, otherwise a single .mif file is needed.");
   Console.WriteLine();

   Console.WriteLine("       MapInfoTab:");
   Console.WriteLine("                Purpose:Native MapInfo vector format.");
   Console.WriteLine("                Files needed: an archive file that contains .tab, .dat, .map, .id.");
   Console.WriteLine("                tab — main file (links others).");
   Console.WriteLine();

   Console.WriteLine("       Osm:");
   Console.WriteLine("                Purpose:Xml format used by OpenStreetMap to store nodes, ways, and relations.");
   Console.WriteLine("                Files needed: a single .osm file.");
   Console.WriteLine();


   Console.WriteLine("       Shapefile:");
   Console.WriteLine("                Purpose:Traditional Esri vector format for storing geographic features.");
   Console.WriteLine("                Files needed:an archive file that contains .shp (geometry), .shx (shape index), .dbf (attribute table).");
   Console.WriteLine("                Optional:.prj, .cpg, .sbn, .sbx.");


   Console.WriteLine("       TopoJson:");
   Console.WriteLine("                Purpose:Extension of GeoJson that encodes topology, reducing redundancy and file size.");
   Console.WriteLine("                Files needed: a single .json or .topojson file.");
   Console.WriteLine();

}

Waiting to your answer.
Your quick answer will be appreciated.

Please pass every option and tell me please what is safe or not:
// 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;

}

Hi, @danies8

I have to finish my work for today.
I will back with answer on monday.

1 Like

Hi Alexander,

Here’s a clearer summary of the situation:

My converter is a command-line (CMD) application that runs automatically as part of our system. The end user is not expected to have any GIS knowledge—they simply upload a file and receive the result.

The user provides input as either a single file or an archive, along with the required command parameters: target format, a temporary folder path (used when extracting archives), and an optional log configuration.

Command format:
gis_convert <input> <format> <output> <temp> [Log <log_path> [level]]

The GIS lib exposes various options that apply to both source and destination formats.

My question is: what are the optimal options I should be using?

I’ve attached a list of the options currently in use. These were selected based on previous failed conversions and recommendations from other support tickets. However, I was not aware that some of these options might affect all conversions globally, not just specific cases.

My options list that I used:
1.Osm to all others formats excepts to itself to block, is it ?
2. RestoreSchema -to remove or leave it ?
.if (sourceFormat.Equals(“Gml”, StringComparison.OrdinalIgnoreCase))
{
options.SourceDriverOptions = new GmlOptions { RestoreSchema = true };
}
3.Ge0Package -to remove or leave it ?
else if (targetFormat.Equals(“GeoPackage”, StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new GeoPackageOptions();
}
4.Gpx-to remove or leave it ?
else if (targetFormat.Equals(“Gpx”, StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new GpxOptions() { WritePolygonsAsLines = true };
}
5.MapInfoTab --to remove or leave it ?
else if (targetFormat.Equals(“MapInfoTab”, StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new MapInfoTabOptions() { IsIgnoreWrongData = true };
}
6.Shapefile–to remove or leave it ?
else if (targetFormat.Equals(“Shapefile”, StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new ShapefileOptions() { IsIgnoreWrongData = true };
}

Thanks in advance,

Hi Dani,

I see you need guidance on which driver‑specific options should be enabled by default in your CLI converter and when it is safe to omit them.

Summary of the options you currently use

Option Format What it does When to keep
GmlOptions.RestoreSchema = true GML (source) Adds missing attribute schema so features without a collection schema are still read. Keep for any GML source – the overhead is negligible and it prevents “schema not found” errors.
GeoPackageOptions (empty) GeoPackage (target) Required by the GeoPackage driver to initialise the SQLite container. Keep for every GeoPackage conversion – the driver will throw otherwise.
GpxOptions.WritePolygonsAsLines = true GPX (target) GPX does not support polygons; this option writes them as line strings. Keep for GPX output when the source may contain polygons. If you are sure the source never has polygons you can omit it, but the extra cost is tiny.
MapInfoTabOptions.IsIgnoreWrongData = true MapInfoTab (target) Skips features whose DBF attribute exceeds the 254‑character limit. Use only when you prefer a successful conversion despite losing those records. If you need strict validation, set it to false (default) and let the conversion fail so the user can fix the data.
ShapefileOptions.IsIgnoreWrongData = true Shapefile (target) Same behaviour as MapInfoTab for DBF field length limits. Same recommendation as above.

Recommended pattern for a CLI tool

Expose the options as optional switches so the end‑user (or your automation) can decide whether to enable the “ignore wrong data” behaviour. The rest can stay enabled by default because they either fix known driver requirements or have virtually no cost.

using Aspose.Gis;
using Aspose.Gis.Converters;
using Aspose.Gis.Gml;
using Aspose.Gis.GeoPackage;
using Aspose.Gis.Gpx;
using Aspose.Gis.MapInfoTab;
using Aspose.Gis.Shapefile;

public static ConversionOptions BuildConversionOptions(
    string sourceFormat,
    string targetFormat,
    bool ignoreWrongData = false)   // command‑line switch --ignore-wrong-data
{
    var options = new ConversionOptions();

    // Source options
    if (sourceFormat.Equals("Gml", StringComparison.OrdinalIgnoreCase))
    {
        options.SourceDriverOptions = new GmlOptions { RestoreSchema = true };
    }

    // Target options
    if (targetFormat.Equals("GeoPackage", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new GeoPackageOptions();
    }
    else if (targetFormat.Equals("Gpx", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new GpxOptions { WritePolygonsAsLines = true };
    }
    else if (targetFormat.Equals("MapInfoTab", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new MapInfoTabOptions
        {
            IsIgnoreWrongData = ignoreWrongData
        };
    }
    else if (targetFormat.Equals("Shapefile", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new ShapefileOptions
        {
            IsIgnoreWrongData = ignoreWrongData
        };
    }

    return options;
}

CLI usage example

gis_convert input.gml Gpx output_folder temp_folder --ignore-wrong-data

If --ignore-wrong-data is omitted the conversion will fail when attribute values exceed DBF limits, which forces the caller to correct the source data.

When to use IsIgnoreWrongData

  • Keep it true when the conversion is part of an automated pipeline and losing a few attributes is acceptable; the user receives a usable file quickly.
  • Set it to false (default) when data integrity is critical. The conversion will raise an exception, allowing you to log the problem and ask the user to fix the source file.

Additional driver options you may consider (optional)

Format Option class Typical switch
GeoJson GeoJsonOptions.AllowNonStandardGeometries --allow-nonstandard-geojson
EsriJson EsriJsonOptions.WriteZValues / WriteMValues --write-z / --write-m
Kml KmlOptions.WriteExtendedData --write-extended-data
Csv CsvOptions.Delimiter, HasHeader, Encoding --csv-delimiter ';' etc.
Wkt WktOptions.IsParseMultiGeometry --parse-multi-geom
Geodatabase GeodatabaseOptions.IsReadOnly --gdb-readonly

You can expose these only when the corresponding format is selected.

Best practices

  1. Keep the builder pure – no file I/O, just option composition (as shown).
  2. Validate format strings early and throw ArgumentException for unsupported values to give clear feedback.
  3. Document the switches in your --help-formats output so non‑GIS users know what each flag does.
  4. Log the effective options before invoking the conversion; this helps troubleshooting.
  5. Do not hard‑code “ignore wrong data” – let the caller decide via a flag, as described.

References

If you need sample data for a particular format or further help integrating these switches into your argument parser, let me know.

Waiting to your answer.

Hi, @danies8
We have conversionOptions to use it depend on situation and what user need! My advise for you - do the same thing. Then your converter will more adjustment.
Otherwise it’s up to you which options use.

Of Course if you hardcode options it will be affect for all conversions.
So, it’s up to you decide!

Hi Alexander,

From the list here, can you please see if I can leave part of the options?

My options list that I used:
1.Osm to all others formats excepts to itself to block, is it ? So no rejection from you, is it?

  1. RestoreSchema -to remove or leave it ? Is it problem, ** There is problem with this ?
    .if (sourceFormat.Equals(“Gml”, StringComparison.OrdinalIgnoreCase))
    {
    options.SourceDriverOptions = new GmlOptions { RestoreSchema = true };
    }

3.GeoPackage -to remove or leave it ? - I do not see problem , do you ?
else if (targetFormat.Equals(“GeoPackage”, StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new GeoPackageOptions();
}

4.Gpx -to remove or leave it ? is it real problem? if i leave it what it mean ?
else if (targetFormat.Equals(“Gpx”, StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new GpxOptions() { WritePolygonsAsLines = true };
}

5.MapInfoTab --to remove or leave it ?
else if (targetFormat.Equals(“MapInfoTab”, StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new MapInfoTabOptions() { IsIgnoreWrongData = true };
}
6.Shapefile –to remove or leave it ?
else if (targetFormat.Equals(“Shapefile”, StringComparison.OrdinalIgnoreCase))
{
options.DestinationDriverOptions = new ShapefileOptions() { IsIgnoreWrongData = true };
}

I see only IsIgnoreWrongData has problem to remove it.
It is a problem of invalid input in our case.

Waiting to your answer.
Is all the conversions are risks or only part ?
Can you pass and give me what is the risk for listed options?

Your quick answer will be appreciated!!
Thanks,

Hi Alexander,

Can you pass on all the 6 options and tell me the meaning if I have or not ?

Your quick answer will be appreciated!!

Thanks,

Hi Alexander,
I removed Osm as target format except Itself(Osm->Osm is valid) in my matrix
according to your suggestion.
Thanks,

image.png (49.2 KB)

Hi Dani,

I understand you need to know which driver‑specific options are safe to keep for every conversion, what the risks are, and how to expose them in a CLI tool. Below is a concise summary of the six options you are currently using, followed by a recommended implementation that keeps the safe defaults and makes the potentially‑lossy IsIgnoreWrongData behaviour optional.

1. What each option does

Option Format (source / target) Effect When it is safe to keep
GmlOptions.RestoreSchema = true GML (source) If the input GML does not contain an attribute‑collection schema, the driver creates one on‑the‑fly so features are still read. Keep always – it adds virtually no overhead and prevents “schema not found” errors.
new GeoPackageOptions() GeoPackage (target) Initializes the SQLite container required by the GeoPackage driver. Keep always – the driver throws if the options object is missing.
GpxOptions.WritePolygonsAsLines = true GPX (target) GPX cannot store polygons; this flag converts any polygon/multipolygon to a line string so the conversion succeeds. Keep always unless you are absolutely sure the source never contains polygons (the extra check is negligible).
MapInfoTabOptions.IsIgnoreWrongData = true MapInfoTab (target) Skips features whose DBF attribute exceeds the 254‑character limit. The lost records are not written. Use only when a loss of those records is acceptable (e.g., automated pipelines). Set to false (default) to make the conversion fail and force the user to correct the data.
ShapefileOptions.IsIgnoreWrongData = true Shapefile (target) Same behaviour as MapInfoTab for DBF field length limits. Same recommendation as above.
(no special option) OSM (source or target) OSM driver works out‑of‑the‑box; no extra options are required. No option needed.

2. Recommended builder for a CLI converter

using Aspose.Gis;
using Aspose.Gis.Converters;
using Aspose.Gis.Gml;
using Aspose.Gis.GeoPackage;
using Aspose.Gis.Gpx;
using Aspose.Gis.MapInfoTab;
using Aspose.Gis.Shapefile;

public static ConversionOptions BuildConversionOptions(
    string sourceFormat,
    string targetFormat,
    bool ignoreWrongData = false)               // <-- exposed as --ignore-wrong-data
{
    var options = new ConversionOptions();

    // ---- source‑specific ----
    if (sourceFormat.Equals("Gml", StringComparison.OrdinalIgnoreCase))
    {
        options.SourceDriverOptions = new GmlOptions { RestoreSchema = true };
    }

    // ---- target‑specific ----
    if (targetFormat.Equals("GeoPackage", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new GeoPackageOptions();
    }
    else if (targetFormat.Equals("Gpx", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new GpxOptions { WritePolygonsAsLines = true };
    }
    else if (targetFormat.Equals("MapInfoTab", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new MapInfoTabOptions
        {
            IsIgnoreWrongData = ignoreWrongData
        };
    }
    else if (targetFormat.Equals("Shapefile", StringComparison.OrdinalIgnoreCase))
    {
        options.DestinationDriverOptions = new ShapefileOptions
        {
            IsIgnoreWrongData = ignoreWrongData
        };
    }

    return options;
}

CLI example

gis_convert input.gml Gpx output_folder temp_folder --ignore-wrong-data

If --ignore-wrong-data is omitted the conversion will abort when an attribute exceeds the DBF limit, allowing you to log the problem and ask the user to fix the source file.

3. Risk assessment

Option Risk if kept Risk if removed
RestoreSchema None – it only adds missing schema. No risk, but you may get “schema not found” errors on some GML files.
GeoPackageOptions None – required by the driver. Conversion to GeoPackage will throw ArgumentException.
WritePolygonsAsLines No data loss; polygons become line strings (still visualisable). If a source contains polygons, conversion will fail with NotSupportedException.
IsIgnoreWrongData (MapInfoTab / Shapefile) Potential loss of features/attributes that exceed DBF limits. Conversion fails, giving you a clear error to correct the input.
OSM No options required. N/A

4. Additional optional options you may expose later

  • GeoJsonOptions.AllowNonStandardGeometries
  • EsriJsonOptions.WriteZValues / WriteMValues
  • KmlOptions.WriteExtendedData
  • CsvOptions.Delimiter, HasHeader, Encoding
  • WktOptions.IsParseMultiGeometry
  • GeodatabaseOptions.IsReadOnly

Expose them only when the corresponding format is selected.

5. Best‑practice checklist

  1. Keep safe defaults (RestoreSchema, GeoPackageOptions, WritePolygonsAsLines).
  2. Make loss‑prone options configurable (IsIgnoreWrongData).
  3. Validate sourceFormat / targetFormat early and throw ArgumentException for unsupported values.
  4. Log the effective ConversionOptions before calling the driver – it helps troubleshooting.
  5. Document the CLI switches in your --help-formats output so non‑GIS users understand what each flag does.
  6. Do not perform any I/O inside BuildConversionOptions; it should remain a pure method.

6. References

If you need a small sample file that triggers the IsIgnoreWrongData behaviour (e.g., a Shapefile with a DBF field longer than 254 characters), let me know and I can provide one.

Hope this clarifies which options you can safely keep and how to expose the risky ones in a user‑friendly way. Feel free to ask for any further details.