ThinkGeo.com    |     Documentation    |     Premium Support

DrawCore SQL Bug

Hi,

The product team keeps reporting an issue when they encounter the following error message in our product, but I haven’t been able to replicate it locally.

The reported error is:

A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry": 
System.FormatException: 24126: Point coordinates cannot be infinite or not a number (NaN).
System.FormatException: 
   at Microsoft.SqlServer.Types.Validator.ValidatePoint(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.Validator.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.ForwardingGeoDataSink.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.WellKnownBinaryReader.ReadFirstPoint(ByteOrder byteOrder, Boolean readZ, Boolean readM)
   at Microsoft.SqlServer.Types.WellKnownBinaryReader.ReadLinearRing(ByteOrder byteOrder, Boolean readZ, Boolean readM)
   at Microsoft.SqlServer.Types.WellKnownBinaryReader.ParseWkbPolygonWithoutHeader(ByteOrder byteOrder, Boolean readZ, Boolean readM)
   at Microsoft.SqlServer.Types.WellKnownBinaryReader.ParseWkb(OpenGisType type)
   at Microsoft.SqlServer.Types.WellKnownBinaryReader.Read(OpenGisType type, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeometry.GeometryFromBinary(OpenGisType type, SqlBytes binary, Int32 srid)

Additionally, when I tested the product, I encountered an exception. Here’s the stack trace:

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
   at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
   at System.Data.SqlClient.SqlDataReader.Read()
   at ThinkGeo.Core.SqlServerFeatureSource.h0I=(RectangleShape boundingBox, QueryType queryType, IEnumerable`1 returningColumnNames)
   at ThinkGeo.Core.FeatureSource.GetFeaturesInsideBoundingBox(RectangleShape boundingBox, IEnumerable`1 returningColumnNames)
   at ThinkGeo.Core.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)

I have verified that there is no issue with our data—there are no NaN values present.

Best wishes,
Mahdi

hi @Mahdi_Rastegari,

Regarding the first error, at least one point coordinates is either NaN or infinite. If there’s no NaN values, it could be infinite values. You could execute “SELECT @YourGeometry.STAsText();” to look for infinite values in the output, also you could execute “SELECT @YourGeometry.STIsValid();” to check if it’s valid, returns 0 if invalid.

For the second error, it could be caused by Timeout, Invalid SQL Query. Could you post the detailed exception message to narrow it down?

Regards,
Leo

Hi Leo,

Thanks for your response. I checked the STIsValid() function, and the data seems good to me. However, it appears that the bug occurs when I set ProjectionConverter to GDALProjectionConverter .

Just to clarify, the top message was the exception’s message, and the bottom one was its stack trace.

Best regards
Mahdi

Hi Mahdi,

I suspect some projected points are generating invalid (NaN or Infinity) coordinates. Although the data in your database is valid, this can occur if you project a point to a projection that doesn’t match its location (e.g., projecting a California point into a UK projection).

To resolve this, ensure that points are only projected into valid projections. If you can’t avoid the mismatch, you could filter or fix any invalid projected geometries before storing them. One approach is to create a custom ProjectionConverter, override the relevant core method (e.g., ConvertToExternalProjectionCore), and either correct or discard any features that produce NaN or Infinity coordinates, like following

class MyProjectionConverter : GdalProjectionConverter
{
    protected override Collection<Vertex> ConvertToExternalProjectionCore(IEnumerable<Vertex> verticies)
    {
        var result = base.ConvertToExternalProjectionCore(verticies);
        // check if the result is valid
        return result;
    }

    protected override Collection<Vertex> ConvertToInternalProjectionCore(IEnumerable<Vertex> vertices)
    {
        var result = base.ConvertToInternalProjectionCore(vertices);
        // check if the result is valid
        return result;
    }
}

Let us know if that works.

Thanks,
Ben