Home > Database > Mysql Tutorial > body text

How to Retrieve Data Points Within Overlapping Marker Radii from a Geospatial Database?

Patricia Arquette
Release: 2024-10-30 09:48:27
Original
195 people have browsed it

How to Retrieve Data Points Within Overlapping Marker Radii from a Geospatial Database?

Retrieve Results Within Overlapping Marker Radii from Database

The objective is to retrieve data points that fall within the overlapping radii of multiple markers in a geospatial database. To achieve this, you must employ the equation of a circle to determine whether a point lies within a given radius.

Considering User B's location as the circle's center and User A's location as points on the circle's perimeter, the equation of the circle, converted to kilometers for consistency, transforms into:

((x-x1)*111.12)^2 + ((y-y1)*111.12)^2 = 4      (=2^2)
Copy after login

where:

  • x and y represent the latitude and longitude of User A's location
  • x1 and y1 represent the latitude and longitude of User B's location
  • 111.12 converts degrees of latitude and longitude to kilometers

Translating this equation into SQL yields:

SELECT A.user_id, A.radius_id, A.latitude, A.logitude
FROM UserA AS A, 
     (SELECT user_id, latitude, longitude 
       FROM UserB 
       WHERE user_id = 8) AS B
WHERE (POW((A.latitude-B.latitude)*111.12, 2) + POW((A.longitude - B.longitude)*111.12, 2)) <= 4
Copy after login

Note: For enhanced accuracy, consider using (A.longitude - B.longitude)*111.12*cos(A.latitude) or (A.longitude - B.longitude)*111.12*cos(B.latitude) instead of (A.longitude - B.longitude)*111.12 in the equation.

The above is the detailed content of How to Retrieve Data Points Within Overlapping Marker Radii from a Geospatial Database?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!