4

I'm struggling to load spatial data into QGIS from SQL Server 2014. I have a table with 4 geography columns (3 are polygon layers, one is a point layer). The table has a primary key column that is a 32-bit integer. I believe the data is loaded correctly as it displays fine in the spatial results tab in SSMS query editor. Also I am able to retrieve the data correctly with custom code I have written.

Whenever I attempt to load with QGIS (or preview with QGIS browser) I immediately receive a crash message "R6025 -pure virtual function call" and down the program goes.

I've tried to populate a geometry_columns table without any help. FWIW I do not see the primary key column listed when attempting to add a layer.

I traced the sql being generated by qgis when I try to load the point layer and found the following to be the culprit (this is part of the select query for the layer):

select [geography]::STGeomFromText('POLYGON(
(-172.75210512499998572 -73.81694445636215107, 
  186.90200612499998556 -73.81694445636215107, 
  186.90200612499998556 143.2662874563621358, 
  -172.75210512499998572 143.2662874563621358, 
  -172.75210512499998572 -73.81694445636215107))',4326)

It appears that latitude & longitude values are somehow scrambled. I manually queried the geography point field and found latitude ranging from 0 to 69.4 and longitude ranging from -164.4 to 178.3 which seems reasonable to me.

I'm baffled as to where QGIS came up with this bounding polygon that it is using to select the layer (complete sql statement below).

SELECT [id],[centroid]FROM [dbo].[table] where     [centroid].STIntersects([geography]::STGeomFromText('POLYGON((-172.75210512499998572 -73.81694445636215107, 186.90200612499998556 -73.81694445636215107, 186.90200612499998556 143.2662874563621358, -172.75210512499998572 143.2662874563621358, -172.75210512499998572 -73.81694445636215107))',4326)) = 1
  • This one still isn't solved, but I did find a workaround using python. The two lines: uri = "MSSQL:server={serverName};database={databaseName};tables={tableName};trusted_connection=yes" qgis.utils.iface.addVectorLayer(uri,'{yourLayerNameHere}','ogr') Link for this info – Hank Brandenburg Aug 8 '15 at 22:28
  • I think you should add that as an answer. – PolyGeo Jun 23 '16 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.