Bug report #14590

Updated by Nathan Woodrow almost 6 years ago

When loading a layer into QGIS which contains invalid features QGIS fails to completely render the layer and stops on any invalid feature without any error message to the user. This leaves the user confused as to what has occurred.

The reason for this is the MSSQL spatial filtering process using ST_Intersects which will throw an exception if the feature is not valid. e.g

SELECT [id],[ogr_geometry]FROM [dbo].[invalid_parcels] where [ogr_geometry].STIntersects([geometry]::STGeomFromText('POLYGON((...))',4326)) = 1

might throw this error:

Msg 6522, Level 16, State 1, Line 5

A .NET Framework error occurred during execution of user-defined routine or aggregate "geometry":

System.ArgumentException: 24144: This operation cannot be completed because the instance is not valid. Use MakeValid to convert the instance to a valid instance. Note that MakeValid may cause the points of a geometry instance to shift slightly.


at Microsoft.SqlServer.Types.SqlGeometry.ThrowIfInvalid()

at Microsoft.SqlServer.Types.SqlGeometry.STIntersects(SqlGeometry other)

A couple options here:

1/ At least raise an error with the user that the layer contains invalid features and to fix them.

2/ Use FIlter instead or STIntersect for the spatial filtering function as Filter can operate on invalid geometries. This might also make sense due to performance reasons. See #10947.

I vote for 2!

I have attached a screenshot showing what happens in a typical situation in the map window. I have also attached a SQL dump of a test layer which contains invalid geometries.