Get all points(circles with radius), that overlap given point

你。 提交于 2019-12-06 10:25:47

Yes, this is exactly the kind of thing that geography and spatial methods are good at. Here is a short example:

DECLARE @Restaurant TABLE (
    Name nvarchar(50),
    Location geography,
    DeliveryRadiusMetres int
);

INSERT @Restaurant
VALUES
-- long lat
('Dominos','POINT(-0.109339 51.532835)',2000 ),
('Pizza Hut','POINT(-0.102961 51.541157)',2000 );

Note that here to construct the geography values I am using an implicit conversion from string, which behind the scenes calls geography::Parse.

DECLARE @MyLocation geography = 'POINT(-0.115063 51.550231)';

SELECT
    Name
FROM
    @Restaurant R
WHERE
    R.Location.STDistance(@MyLocation) <= R.DeliveryRadiusMetres
;

Yes you can draw your circles as points as a Geography / Geometry datatype. Then you can write SQL queries directly against this data with functions like STWithin and STTouches.

Set up your restaurant location as a point with a radius. Then you can write a query like this:

DECLARE @RestaurantCoverage Geometry
SET @RestaurantCoverage = 'Point(10 5)' --Location
SET @RestaurantCoverage = @RestaurantCoverage.STBuffer(5)     --Cover radius
DECLARE @YourLocation Geometry
SET @YourLocation = 'Point(13 5)' --Your location

SELECT @YourLocation.STWithin(@RestaurantCoverage)

http://technet.microsoft.com/en-us/library/bb933991.aspx

Also works directly against table data with where statement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!