Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have imported a polygon shape file in MSSQL2008 using Shape2SQL loader without any issue. When I import the loaded polygon file in QGIS, I can't see it ! When I import other point or line features (previously loaded in MSSQL2008), I can see a few polygons from my file but not all of them.

At first I thought that the geometry of the poly file was not complete, so I repaired the geometry using ArcGIS 10.1 and reloaded the ""fixed geometry" file in MSSQL2008, and still am running in the same problem when I import the layer in QGIS.

One thing I have noticed in QGIS: when I connect to my MSQL2008 database, the points and line features have the geometry and SRID already determined but the polygon file requires the user to define the geometry type and SRID. I have tried selecting polygon and multipolygon type and set the SRID to 0 (like the other features in the DB) and still am running into problems viewing my poly file in QGIS. My original poly file has 1285 polygons in it.

I have tried using a subset of my original file and still am running into problems in QGIS.

share|improve this question

1 Answer 1

I had the same problem and repairing invalid geometries within SQL Server (I'm using 2012) fixed it for me. Qgis was then also able to auto-detect the geometry type and srid

If running this query:

select * from yourgeotable
where geom.STIsValid() = 0;

returns any records, then you have invalid records.

Fix them with this query:

update yourgeotable
set geom = geom.MakeValid()
output inserted.id
where geom.STIsValid() = 0;

The Spatial Results tab in SSMS automatically uses MakeValid to repair geometries for display, so that can cause confusion as well. Since SQL Server is displaying the results, you may think they are valid when in fact SQL Server is repairing them for you.

Check out part 2 of the 2nd link posted below for more information on valid shapes and MakeValid.

Sources:

http://www.sqlskills.com/blogs/bobb/loading-spatial-data-and-cleansing-converting-with-sql-server-2012/

http://blogs.msdn.com/b/davidlean/archive/2008/11/01/sql-2008-spatial-samples-part-1-of-9-how-to-learn-sql-spatial.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.