none
STIntersection() throws COMException: Error HRESULT E_FAIL RRS feed

  • Question

  • Hi,

    I have two geometries, when i try to get STIntersection from these two geometries, sql server return output of Exception.

    Msg 6522, Level 16, State 1, Line 6
    A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry": 
    System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
    System.Runtime.InteropServices.COMException: 
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at Microsoft.SqlServer.Types.GLNativeMethods.Combine(CombineMode combineMode, GeoData g1, GeoData g2)
       at Microsoft.SqlServer.Types.SqlGeometry.STIntersection(SqlGeometry other)
    .

    I am trying to STIntersection on two polygons, which one of them has 51536 points from STNumPoints and the other one has 3125.

    I tried it with this selects:

    declare @geomHnv geometry = ( select top 1 Shape from dbo.hnv)
    declare @geomSaps geometry = ( select top 1 Shape from dbo.Saps)
    select @geomHnv.STIntersection(@geomSaps)
    
    
    select o1.Shape.STIntersection(o2.Shape)
    from dbo.hnv o1
    cross join dbo.saps o2

    The polygon is so big, that i cannot copy it here, so i made a backup of database with only two polygons from above.

    Link: https://drive.google.com/open?id=0B8Vv9ogG99P-YmZSNkFDLUpZb3M

    Dump consist of two tables, where each table contains one geometry column.

    I tried it on SQL Server 2014.


    • Edited by Matus K Monday, October 17, 2016 1:28 PM
    Monday, October 17, 2016 10:40 AM

All replies

  • I restored your backup to a SQL Server 2016 instance, then validated each instance (IsValidDetailed) and checked SRID to make sure they match. That checked out fine, although the (internal) error should not occur in any case. I got the same error on your cross join query as you did.

    Suggest that you ensure your instance is at the latest patch level (in case there's the problem's already been fixed). And then report it via Connect (https://connect.microsoft.com/) or open a support case.

    In the meantime, this error appears to be related to complexity of the operation (number of points). Using the Reduce() method, you can reducing either polygon down to where the STIntersection will work. Using your example:

    --select @geomHnv.Reduce(.105).STNumPoints()
    --set @geomHnv = @geomHnv.Reduce(.105)

    -- or
    select @geomSaps.Reduce(.0000001).STNumPoints()
    set @geomSaps = @geomSaps.Reduce(.0000001)

     
    Tuesday, October 18, 2016 8:03 PM