如何确定一个有效的圈子里面n个位置? [英] How to determine n locations inside a circle efficiently?

查看:108
本文介绍了如何确定一个有效的圈子里面n个位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于这种情景:


  1. 我们有1,000,000点在世界各地的顺序,按经度和纬度指定;

  2. 我们有基于一个点PC一个圆c(由经度和纬度规定的)和一个半径的rc

  3. 我们想有效地确定该点是在圈内

我在C#和存储在SQL Server 2008中的位置发展。

I'm developing in C# and the locations stored in SQL server 2008.

所以当我看到它,我有这3个选项:

So as I see it I have these 3 options:


  1. 存放位置经度纬度花车和在C#中执行计算

  1. Store the locations as longitude latitude floats and perform the calculations in C#.

店铺的位置为地理数据类型和执行SQL Server 2008中的计算是这样的:

Store the locations as geographical data types and perform the calculations in SQL server 2008 like this:

CREATE TABLE UserLocations
[UserId] [bigint] NOT NULL,
[CurrentLocation] [geography] NOT NULL

ALTER PROCEDURE sp_GetCurrentUsersInRange
@userPoint geography, 
@RangeInMeters int
AS
BEGIN

select  UserId from UserLocations
where @userPoint.STDistance(CurrentLocation) <= @RangeInMeters
and UserId <> @userId

END



缺点:使用带有LinqToSQL和LinqToEntities地理数据问题

Disadvantages: problems using geographical data with LinqToSQL and LinqToEntities.

优点:使用DBMS处理能力在大数据和SQL Server空间索引的使用

Advantages: using dbms processing power over large data, and usage of the SQL Server spatial index.

3,采用一些网络服务,如谷歌的地理定位和计算服务。
到目前为止,我没有发现这样的Web服务。

3.Using some web service such as google's geolocation and calculation services. So far I didn't find such web service.

这是最有效的在您看来?请证明你的答案

感谢您

推荐答案

我的幼稚的方法是定义围绕该点PC纬度/长边框,并使用之间这些箱子坐标从数据库中选择。统计学通过该测试点约79%将在圆内。代码中的一个简单的检查将淘汰的圈子之外的人。

My naive approach would be to define a lat/long bounding box around the point pc and select from the database using BETWEEN on those box coordinates. Statistically around 79% of the points passing that test will be within the circle. A simple check in the code will weed out the ones outside the circle.

我说天真,因为我不熟悉SQL Server的几何形状的能力。

I say naive because I'm not familiar with the geometry capabilities of SQL Server.

这篇关于如何确定一个有效的圈子里面n个位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆