1

mysql テーブルに 2063 の場所が保存されています。私のプロセスの 1 つで、特定の結果が特定の起点からどれだけ離れているかに基づいて、特定の結果を除外する必要があります。問題は、一度に数百、おそらく数千の結果をフィルタリングする必要があることです。

では、距離計算を行う最良の方法は何でしょうか。実行時にやるべきか

1. Find all points connecting to my point of origin
2. loops through the connecting points
3. calculate the distance between the point of origin and the connecting point
4. exclude the connecting point if the distance if too great

または、すべてのポイント間の距離が既にわかっているルックアップ テーブルを作成する必要があります。p1 と p2 の間の距離は p2 と p1 の間の距離と同じであるため、行の重複を避けることができますが、それでもテーブル内に数百万行が存在することになります。

または..それを行うより良い方法はありますか?

4

3 に答える 3

4

MySQL の空間拡張機能を使用して距離を計算し、データに R ツリー インデックスを作成して、範囲内のポイントのルックアップを最適化することもできます。

詳細については、MySQL 空間拡張のドキュメントを参照してください: http://dev.mysql.com/doc/refman/5.1-maria/en/spatial-extensions.html

于 2009-05-26T13:07:10.947 に答える
1

データは mysql テーブルにあるため、SQL が支援できるソリューションが本当に必要です。

I will assume that each location has an x and y coordinate. Store these as separate entries in the table.

You can quickly narrow your field of search to a box centered on your point of interest. eg

WHERE X > (MyPosX - Range) AND X < MyPosX + Range) 
AND Y > (MyPosY - Range) AND Y < MyPosY + Range)

Once you have a smaller set of items that are likely to be in range, you can use a more iterative approach

Edit: Avoid square root calculations when working out the actual distances though, as these are expensive. eg instead of

sqrt(x*x + y*y) < distance

try

(x*x + y*y) < distance*distance    
// distance*distance is a constant and can be calculated once
于 2009-05-26T13:13:42.883 に答える
1

これはどう:

1. すべてのポイントをループします。
  2. abs(ab) < 距離 && abs(ab) < 距離の場合:
    3. a と b の間の特殊な距離計算を行います。

つまり、ほとんどのポイントが、関心のある距離によって定義された「ボックス」の外にあると仮定すると、ステップ 2 でほとんどのポイントを非常に迅速に除外し、はるかに少数のポイントの実際の距離のみを計算できます。

于 2009-05-26T13:10:58.083 に答える