Truncated Decimals in WKT Strings

When converting IGeometry to WKT with the AsText() method, decimal precision is lost as compared to other libraries (SqlGeometry, DotSpatial).

For example:
-108.45392758962691 becomes:
-108.453927589627

This is because internally your code is generating number strings for WKT via:
stringBuilder.Append(num.ToString(CultureInfo.InvariantCulture));

What it should be is:
stringBuilder.Append(num.ToString("G17", CultureInfo.InvariantCulture));

Actually, num.ToString("R", CultureInfo.InvariantCulture) seems to test better for compatibility with how other libraries handle rounding. I would like to request that.

Hello, @DavidB!

Thank you for your interest in the Aspose.GIS product.

We have included this improvement request in our issue tracking system as GISNET-513. And we will update you here as soon as additional information is available.

Hello, @DavidB,

The features you were looking for is available in Aspose.GIS for .NET 20.3. Aspose.GIS allows you to change the decimal precision in WKT String.

Please, consider the following code to handle rounding:

Point point = new Point(23.5732, 25.3421) { M = 40.3 };
point.SpatialReferenceSystem = SpatialReferenceSystem.Wgs84;

// to get max a decimal precision
Console.WriteLine("G17 : " + point.AsText(WktVariant.Iso, NumericFormat.General(17)));
Console.WriteLine("R : " + point.AsText(WktVariant.Iso, NumericFormat.RoundTrip));
// console:
// POINT M (23.5732 25.342099999999999 40.299999999999997)
// POINT M (23.5732 25.3421 40.3)

// to trim a decimal precision
Console.WriteLine("G3 : " + point.AsText(WktVariant.Iso, NumericFormat.General(3)));
Console.WriteLine("Flat3: " + point.AsText(WktVariant.Iso, NumericFormat.Flat(3)));
// console:
// POINT M (23.6 25.3 40.3)
// POINT M (23.573 25.342 40.3)

Thanks.

I upgraded and now get results consistent with other libraries if I use the new NumericFormat.RoundTrip.

Perfect.