简体   繁体   English

搜索地理坐标的数据库设计

[英]Database design for search of geocoordinates

In a MySQL database I have tracking data of animals (elephants). 在MySQL数据库中,我有动物(大象)的跟踪数据。 Currently the design is a follows: 目前的设计如下:

timestamp(INT) | individualID(INT) | longitude(DECIMAL) | latitude(DECIMAL)

Now I'd like to ask several questions to the database 现在我想向数据库提几个问题

  1. What is the closest individual at time t? 在时间t,最接近的个体是什么?
  2. Which individuals are around (perimeter 50km) at time t? 在时间t,哪些人在周围(周长50公里)?
  3. Which individuals are present in the reservation at time t? 在时间t,预订中有哪些人? (reservation is given by a polygon) (预定由多边形给出)

Is there some built-in functionality available for MySQL? 是否有一些可用于MySQL的内置功能? Should I choose a different database? 我应该选择不同的数据库吗?

There is a MySQL Spatial Extension , that implements GEOMETRY , based on OGC SFS (simple features specification). 有一个基于OGC SFS (简单功能规范)实现GEOMETRYMySQL Spatial Extension It is a base standard for SPATIAL data implementation for a lot of database engines. 它是许多数据库引擎的SPATIAL数据实现的基本标准。

For client-side there are OpenLayers , HTML5 SVG, Google Maps . 对于客户端,有OpenLayers ,HTML5 SVG, Google Maps Look at GIS.StackExchange.com . 看看GIS.StackExchange.com


From my experince (if it might be take into a count, as it was 2 years ago), MySQL implementation of a spatial data is sufficient, but not the best. 从我的经验来看(如果它可能需要计算,就像2年前一样),MySQL实现空间数据就足够了,但不是最好的。 It is implemented better in Oracle and MS SQL Server (IMHO). 它在Oracle和MS SQL Server(IMHO)中实现得更好。 If you are not going to build very complex map - MySQL functionality is good enough. 如果你不打算构建非常复杂的地图 - MySQL功能就足够了。 For complex functionality I would suggest to use different database engine. 对于复杂的功能,我建议使用不同的数据库引擎。


There are similar question on SO: Fastest Way to Find Distance Between Two Lat/Long Points , where accepted answer used MySQL Spatial Extension. 在SO上有类似的问题: 找到两个纬度/长点之间距离的最快方法 ,其中接受的答案使用MySQL Spatial Extension。 If you will research more, you may find out answers on your other questions. 如果您要进行更多研究,可以在其他问题上找到答案。


I also may try to supply query basis: 我也可以尝试提供查询依据:

I overcame the first 2 problems in my PHP app using the following code http://www.geodatasource.com/developers/php there is also a SQL version of the solution there. 我使用以下代码克服了我的PHP应用程序中的前两个问题http://www.geodatasource.com/developers/php那里还有一个SQL版本的解决方案。

Basically you need to calculate the length of an arc on the surface of the globe, using trigonometry to get the distance between 2 grid points. 基本上,您需要使用三角法计算地球表面上弧的长度,以获得2个网格点之间的距离。

You can then compare the distances of multiple individuals from your base location and eliminate all with a distance of more than 50km to get your group of animals within the perimeter. 然后,您可以比较多个人与基地位置的距离,并消除距离超过50公里的所有人,以便让您的动物群在周界内。

Part 3 of your question requires some more complicated algebra and is not a problem that I have tackled. 你的问题的第3部分需要一些更复杂的代数,这不是我所解决的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM