【mysql】基于城市多边形,配合mysql库,查询目标点是否在指定城市内-测试

时间:2024-11-14 07:39:27
查询目标点是否在指定的城市区域内

执行SQL:

select  coordinate
from   target_coordinate_table tct
where st_within(tct.coordinate, (select polygon from city_polygon_table cpt where id = 1)) = 1;

查询结果:

image-20241113095301645

查询两个目标点的距离

执行SQL

select  coordinate, st_distance_sphere(corrdinate, point(106.529617,29.454004)) as distance
from   target_coordinate_table;

查询结果:

image-20241113100135828

查询目标点半径范围内的其他点
SELECT *
FROM (
    SELECT 
        coordinate, 
        st_distance_sphere(coordinate, point(106.529617,29.454004)) as distance
    FROM 
        target_coordinate_table
) AS subquery
WHERE subquery.distance < 20000;

image-20241113100440446