We have two select statements using "geography::STLineFromText" with almost the same input.
The only difference is in the last point of the line string passed in.
The question is: Why the first query fails when the second does not?
The first query (FAILS):
select geography::STLineFromText('LINESTRING(93.599998 13.2,93.599998 13.21,93.599998 13.19,93.599998 13.17,93.599998 13.42,93.68 13.88,93.790001 14.38,93.970001 14.89,94.010002 15.23,94.0 15.45,94.0 15.64,94.080002 15.76,94.18 15.95,94.360001
16.139999,94.480003 16.34,94.57 16.530001
,94.639999 16.700001)',4326)
--,94.64 16.7)',4326)
union all
select geography::Point(16.700001,94.639999,4326)
The second query (SUCCEEDS):
select geography::STLineFromText('LINESTRING(93.599998 13.2,93.599998 13.21,93.599998 13.19,93.599998 13.17,93.599998 13.42,93.68 13.88,93.790001 14.38,93.970001 14.89,94.010002 15.23,94.0 15.45,94.0 15.64,94.080002 15.76,94.18 15.95,94.360001
16.139999,94.480003 16.34,94.57 16.530001
,94.64 16.7)',4326)
--,94.639999 16.700001)',4326)
union all
select geography::Point(16.700001,94.639999,4326)
We tested the queries in SQL Server 2008 r2 and got the following error
"Msg 6522, Level 16, State 1, Line 1
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.
System.ArgumentException:
at Microsoft.SqlServer.Types.SqlGeography.ConstructGeographyFromUserInput(GeoData g, Int32 srid)
at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
"
Another sample query with the similar issue is:
select geography::STLineFromText('LINESTRING(
66.699996948242188000 13.800000190734863000
,66.699996948242188000 13.810000419616699000
,66.699996948242188000 13.789999961853027000
,66.699996948242188000 13.770000457763672000
,66.709999084472656000 14.010000228881836000
,66.790000915527344000 14.399999618530273000
,66.809997558593750000 14.739999771118164000
,66.809997558593750000 15.109999656677246000
,66.739997863769531000 15.489999771118164000
,66.639999389648438000 15.810000419616699000
,66.470001220703125000 16.190000534057617000
,66.269996643066406000 16.590000152587891000
,65.919998168945313000 17.059999465942383000
,65.510002136230469000 17.489999771118164000
,65.099998474121094000 17.909999847412109000
,64.629997253417969000 18.309999465942383000
,63.990001678466797000 18.690000534057617000
,63.290000915527344000 18.940000534057617000
,62.549999237060547000 19.159999847412109000
,61.770000457763672000 19.360000610351563000
,61.209999084472656000 19.420000076293945000
,60.790000915527344000 19.489999771118164000
,60.409999847412109000 19.569999694824219000
,60.090000152587891000 19.659999847412109000
,59.709999084472656000 19.850000381469727000
,59.319999694824219000 20.120000839233398000
,58.909999847412109000 20.399999618530273000
,58.450000762939453000 20.620000839233398000
,58.069999694824219000 20.819999694824219000)',4326)
After just changing coordinates of the last point the query "starts" working
select geography::STLineFromText('LINESTRING(
66.699996948242188000 13.800000190734863000
,66.699996948242188000 13.810000419616699000
,66.699996948242188000 13.789999961853027000
,66.699996948242188000 13.770000457763672000
,66.709999084472656000 14.010000228881836000
,66.790000915527344000 14.399999618530273000
,66.809997558593750000 14.739999771118164000
,66.809997558593750000 15.109999656677246000
,66.739997863769531000 15.489999771118164000
,66.639999389648438000 15.810000419616699000
,66.470001220703125000 16.190000534057617000
,66.269996643066406000 16.590000152587891000
,65.919998168945313000 17.059999465942383000
,65.510002136230469000 17.489999771118164000
,65.099998474121094000 17.909999847412109000
,64.629997253417969000 18.309999465942383000
,63.990001678466797000 18.690000534057617000
,63.290000915527344000 18.940000534057617000
,62.549999237060547000 19.159999847412109000
,61.770000457763672000 19.360000610351563000
,61.209999084472656000 19.420000076293945000
,60.790000915527344000 19.489999771118164000
,60.409999847412109000 19.569999694824219000
,60.090000152587891000 19.659999847412109000
,59.709999084472656000 19.850000381469727000
,59.319999694824219000 20.120000839233398000
,58.909999847412109000 20.399999618530273000
,58.450000762939453000 20.620000839233398000
,58.069999 20.819999)',4326
)