Radius Latitude Longitude

  • I have a table with latitude longitude in the format.  45.123456 , -111.123456 , Primary Key .   I want to find all ids within a radius in miles.

    Thanks in advance . Have a great day.

     

     

  • You use the (longitude, latitude) to create/define a @Point. and then you use STDistance to calculate the distance between them.

    STDistance (geography Data Type) - SQL Server | Microsoft Learn

  • Thanks that was a good exercise but that's for two points . I was hoping some type of calculation that draws a radius and returns all the points that fall within that radius or circle.  If you have any links for radius please share.

  • HeftSteady wrote:

    Thanks that was a good exercise but that's for two points . I was hoping some type of calculation that draws a radius and returns all the points that fall within that radius or circle.  If you have any links for radius please share.

    All points inside a circle of radius x? That's an infinite number.


  • Here is a picture . Let me know if you need it in another language.

    Attachments:
    You must be logged in to view attached files.
  • x

    • This reply was modified 2 weeks, 5 days ago by HeftSteady.
  • If you cannot provide a concise answer . Please move onto the next topic . Have a great day and sql on!

  • Sorry, wrong function. you want STContains.

    Remarks

    STContains() always returns null if the spatial reference IDs (SRIDs) of the geometry instances do not match.

    Examples

    The following example uses STContains() to test two geometry instances to see if the first instance contains the second instance.

    DECLARE @g geometry;

    DECLARE @h geometry;

    SET @g = geometry::STGeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))', 0);

    SET @h = geometry::STGeomFromText('POINT(1 1)', 0);

    SELECT @g.STContains(@h);

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply