8

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?

1 Answer 1

12

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

3
  • 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. Commented Mar 8, 2017 at 12:41
  • try: RoadGeometry.STAsText() Commented Mar 8, 2017 at 12:49
  • 1
    Updated answer. I should have actually read the docs instead of assuming it worked the same as PostGIS. Commented Mar 8, 2017 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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