最有效的方法来保存方式点并进行比较?

[英]Most efficient way to save way points and do comparisons?


I would like to know your opinion. I created an application, where users create routes and we track this route and save all the way points in the database. Then, the application does comparisons of users way points.

我想知道你的意见。我创建了一个应用程序,用户在其中创建路径并跟踪此路径并保存数据库中的所有路径点。然后,应用程序对用户路点进行比较。

Currently, I use a MSSQL Server, using two tables, one for Routes and the other for storing way points (with spatial data type). The comparisons are made in a stored procedure using SQL Server geographic functions such as st_distance...

目前,我使用MSSQL Server,使用两个表,一个用于路由,另一个用于存储路点(具有空间数据类型)。使用SQL Server地理函数(如st_distance)在存储过程中进行比较...

I have investigated other options. One that I implemented is with Oracle 11g using objects. I store all data in only one Object Table, and the way points are stored in a Varray of a type with Latitude and Longitude attributes. This way is very efficient saving and retrieving data, but gets some complicated when comparing.

我调查过其他选择。我实现的是使用对象的Oracle 11g。我将所有数据存储在一个对象表中,并且路径点存储在具有纬度和经度属性的类型的Varray中。这种方式非常有效地保存和检索数据,但在比较时会变得复杂。

I'm looking for a NoSQL solution, some algorithm or method to do this efficiently. What do you think?

我正在寻找NoSQL解决方案,一些算法或方法来有效地做到这一点。你怎么看?

1 个解决方案

#1


15  

Using database functions like STDistance for all n records is suboptimal. Your CPU overhead will increase exponentially.

对所有n个记录使用STDistance等数据库函数是次优的。您的CPU开销将呈指数级增长。

What you should do is check for the amount of points within a rectangle around the current epicenter you are searching. Here's an example (in MySQL):

你应该做的是检查你正在搜索的当前震中周围的矩形内的点数。这是一个例子(在MySQL中):

SELECT * FROM `points`
    WHERE `latitude` >= X1 AND `latitude` <= X2
    AND `longitude` >= Y1 AND `longitude` <= Y2

This provides a reduced superset of points that should then be further reduced by calculating the orthodromic distance (with respect to the curvature of the Earth) using the Haversine formula.

这提供了减少的点的超集,然后通过使用Haversine公式计算顺向距离(相对于地球的曲率)来进一步减少这些点的超集。

Don't forget to set up a composite index on latitude and longitude.

不要忘记在纬度和经度上设置复合索引。

Orthodromic distance

Here it is in PHP:

这是PHP:

<?php
function haversine($latitude1, $longitude1,
                   $latitude2, $longitude2, $unit = 'Mi') {
    $theta = $longitude1 - $longitude2;
    $distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) +
    (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $distance = acos($distance);
    $distance = rad2deg($distance);
    $distance = $distance * 60 * 1.1515;
    switch ($unit) {
    case 'Mi':
        break;
    case 'Km':
        $distance = $distance * 1.609344;
    }
    return (round($distance, 2));
}
?>

To recap:

回顾一下:

Here's an example image illustrating what to do:

这是一个示例图片,说明了该做什么:

Example with CN Tower

The first search would involve a bounding box collision search (MySQL example) to determine the superset, excluding the red points. The second verification process would involve calculating if the points are within an appropriate orthodromic distance with the Haversine formula (PHP example) and taking a subset (composed of the black points).

第一次搜索将涉及边界框碰撞搜索(MySQL示例)以确定超集,不包括红点。第二个验证过程将涉及使用Haversine公式(PHP示例)计算点是否在适当的顺向距离内并且采用子集(由黑点组成)。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2012/09/24/4a6e19203fb0560ac3f4b5d1948f2e8.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号