locked
Compute distance between two points and return as new field in query results. SQL R2 GEOGRAPHY RRS feed

  • Question

  •  

    This is working great - but now how do I get a new field for each record in the return query that shows the number of miles each place is from the center point? Can I use STDistance some how? Something like this?

    SELECT * , geo.STDistance(GEOGRAPHY::Point(latfield,    Longfield,  4326)) as MILESAWAY

    FROM Venues

    WHERE geo.STDistance(GEOGRAPHY::Point(39.65337,    -105.17643,  4326)) < (25 * 1609.344)


    - 10spotdomain for all your domain and domain related needs
    Wednesday, July 27, 2011 9:02 PM

All replies

  • That is correct.

    SELECT geog.STDistance(geography::STGeomFromText('POINT(-101.67588 21.15239)', 4326)) Distance
    FROM Venues

    If you try to obtain the points in a radio, maybe you could try with this:

    DECLARE @CircleRadius float = 500.0;
    SELECT geog.STBuffer(10.0), POI AS Nombre
    FROM catPOI
    WHERE geography::STGeomFromText('POINT(-101.67588 21.15239)', 4326).STBuffer(@CircleRadius).STIntersects(geog) = 1

    Monday, November 26, 2012 10:24 PM