We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Nvalid geometry: LinearRing should be closed (first point should equal to the last one)

using (var dataset = Dataset.Open(path, Drivers.FileGdb, options))
{
    Console.WriteLine("FileGDB has {0} layers", dataset.LayersCount);
    for (int i = 0; i < dataset.LayersCount; ++i)
    {
        Console.WriteLine("Layer {0} name: {1}", i, dataset.GetLayerName(i));

        using (var layer = dataset.OpenLayerAt(i))
        {
            //1.Aspose.Gis.GisException:“Invalid geometry: LinearRing should be closed (first point should equal to the last one)”
            layer.SaveTo($"xx.geojson", Drivers.GeoJson, new SavingOptions()
            {
               DriverOptions = new GeoJsonOptions()
               {
                   XYPrecisionModel = PrecisionModel.Rounding(6)
               }
            });


            Console.WriteLine("Layer has {0} features", layer.Count);
            foreach (var feature in layer)
            {
                //2.here  no exception  throw
                //3.how control   XYPrecisionModel?
                var t =  feature.Geometry.AsText(WktVariant.ExtendedPostGis);
                Console.WriteLine(t);
                
            }
        }
        Console.WriteLine("");
    }

q1:
code at label1 , will throw exception , but label 3 (feature.Geometry.AsText) no exception, and we can use gdal convert it to geojson success

q2:
how control label 3 (feature.Geometry.AsText) XYPrecisionModel? I pass FileGdbOptions in Dataset.Open , it seem not work

@lsl,

Could you please also provide Geodatabase gdb file, so we can evaluate your issue precisely.

@lsl

It seems. The Input File contains the “invalid geometries by SFA (Simple Feature Access)” . Our library avoids “invalid geometries” on writing. As result, the above code throws the exception. Please try use option ValidateGeometriesOnWrite = false

        layer.SaveTo($"xx.geojson", Drivers.GeoJson, new SavingOptions()
        {
            DriverOptions = new GeoJsonOptions()
            {
                XYPrecisionModel = PrecisionModel.Rounding(6),
                ValidateGeometriesOnWrite = false
            }
       });

please use direct cast to control the precision

 var geometry = (Geometry) feature.Geometry;
 var t = geometry.AsText(WktVariant.ExtendedPostGis, NumericFormat.General(6));
 Console.WriteLine(t);

Best Regards

ValidateGeometriesOnWrite = false

still get exception , or can you auto add a point same as first point at end (like gdal)?

geometry.AsText(WktVariant.ExtendedPostGis, NumericFormat.General(6));

it work fine, could you can add it to feature.Geometry will be better?

Thanks for the ideas. I created tasks (GISNET-1330, GISNET-1331) that are easy to implement.