7

I currently have a table in SQL server management studio (2012) with a geography column.

enter image description here

It definitely has valid spatial data, as I can view it in SSMS: enter image description here

What I want is to export the data as a flatfile csv, so that I can load it into GIS software, specifically QGIS. I tried exporting as csv and loading the csv into QGIS, selecting the geography column as WKT, however QGIS did not recognise it. Is it possible to convert whatever format SQL stores Geography information into WKT?

10

You should be able to use STAsText:

https://msdn.microsoft.com/en-us/library/bb933977.aspx

So you could create a new table:

CREATE TABLE wkt_export as SELECT *, RoadGeometry.STASText() as WKT FROM table_name;

Then export it and use the WKT field to load as a csv file to QGIS.

You could also try connecting directly to the server:

enter image description here

  • Hmmm, It's returning "STAsText is not a recognized built-in function name" for me. The documentation says it should work for SQL 2012 though. – Joshua Kidd Mar 8 '17 at 12:41
  • try: RoadGeometry.STAsText() – HeikkiVesanto Mar 8 '17 at 12:49
  • Updated answer. I should have actually read the docs instead of assuming it worked the same as PostGIS. – HeikkiVesanto Mar 8 '17 at 12:52

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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