1

I have a Geometry LineString that I wish to convert to Geography. Since the Geometry isn't valid , When I use MakeValid on it, SQL convert it to MultiLineString and than the Geography creation is failing with error :

The specified input does not represent a valid geography instance. Use MakeValid to convert the instance to a valid instance. Note that MakeValid may cause the points of a spatial instance to shift slightly.

What can I do in order to convert the Geometry to Geography ?

Geometry text : http://pastebin.com/Ly8ex41U

Geometry text after MakeValid : http://pastebin.com/HGNFKnS3

1

I grabbed your after text from pastebin and did

SELECT geography::STGeomFromText([your text], 4326)

and got no error. How are you trying to create your geography?

I did find that

SELECT geography::STGeomFromText([your text], 4326).MakeValid()

converted it to a GeometryCollection.

  • 1
    I'm using SQL 2012 , Doing the same as you : DECLARE @g NVARCHAR(max) SET @g = [text from paste] SELECT Geography::STGeomFromText(@g, 4326) And I'm getting error : Msg 6522, Level 16, State 1, Line 4 A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": System.ArgumentException: 24200: The specified input does not represent a valid geography instance. Use MakeValid to convert the instance to a valid instance. Note that MakeValid may cause the points of a spatial instance to shift slightly. – Alophind Jul 24 '13 at 15:13
  • Specifically, I tested with SQL 2012 Express version 11.0.2100.60 and in-lined the text rather than assigning (not that I would expect that to make a difference). – Russell at ISC Jul 25 '13 at 15:51
  • I have no idea how come it works for you and not for me. very very strange. Can you load it into SQL Fiddle or send me your script so ill run it? I'm running on : Microsoft SQL Server Management Studio 11.0.2100.60 Microsoft Data Access Components (MDAC) 6.1.7601.17514 Microsoft MSXML 3.0 4.0 6.0 Microsoft Internet Explorer 9.10.9200.16635 Microsoft .NET Framework 4.0.30319.18052 Operating System 6.1.7601 – Alophind Jul 27 '13 at 9:36
  • Something very strange happening now. Query DOES work on master , but doesn't work on my DB which is in the same instance. Any idea ?! – Alophind Jul 27 '13 at 18:00
  • I've solved it. My DB was import from 2008. I've created new one , imported only the data and tables and now it works. so weird. – Alophind Jul 27 '13 at 18:16

Your Answer

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

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