locked
STDistance from point to multilinestring incorrect? RRS feed

  • Question

  • I have very simple example:

     

    DECLARE @Point Geography = geography::Point(28.31320117, -26.15484997, 4326)
    DECLARE @Road Geography = geography::STMLineFromText('MULTILINESTRING ((28.31320116 -26.15484996, 28.31385672 -26.15535594))', 4326)
    SELECT @Point.STDistance(@Road)

    Returning: 8380821.64252868 (As I understand these are meters)

    But this answer is wrong, since @Point have same coordinates as first multiline's point with increased last digit by 1.

    QUESTION: what I do wrong? Is it a bug?

     

    Thursday, October 21, 2010 11:45 AM

Answers

  • You've got the coordinate ordering wrong.

    WKT methods (i.e. anything that you supply to STxxxFromText) require geography coordinates to be specified in Longitude - Latitude order.

    But SQL Server's internal methods, e.g. Point(), or the AddLine() method, require coordinates to be specified in Latitude - Longitude order.

    Try the following and you'll get the result you were expecting (a distance of about 0.2mm):

    DECLARE @Point Geography = geography::Point(-26.15484997, 28.31320117, 4326)
    DECLARE @Road Geography = geography::STMLineFromText('MULTILINESTRING ((28.31320116 -26.15484996, 28.31385672 -26.15535594))', 4326)
    SELECT @Point.STDistance(@Road)
    


    Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290
    • Marked as answer by Andris Lubans Thursday, October 21, 2010 12:11 PM
    Thursday, October 21, 2010 12:05 PM
    Answerer