表a中存储的是区域点坐标,数据量50万左右;
数据存储格式为
FID X Y
0001 1111.00 223422.00
0002 13241.00 224322.00
0003 1113451.00 234222.00
0004 113511.00 234222.00
0005 115611.00 222342.00
0006 154111.00 224322.00
0007 117711.00 342222.00
0008 11611.00 234222.00给定坐标x0,y0怎么找出与(x0,y0)距离最小的点记录的FID.
数据存储格式为
FID X Y
0001 1111.00 223422.00
0002 13241.00 224322.00
0003 1113451.00 234222.00
0004 113511.00 234222.00
0005 115611.00 222342.00
0006 154111.00 224322.00
0007 117711.00 342222.00
0008 11611.00 234222.00给定坐标x0,y0怎么找出与(x0,y0)距离最小的点记录的FID.
select fid
from a
where sqrt(power(abs(x0 - x), 2) + power(abs(y0 - y), 2)) =
(select min(sqrt(power(abs(x0 - x), 2) + power(abs(y0 - y), 2)))
from a)
from a,select fid
from a,
(
select min(x) x
from a
where
x>x0
) minx,
(
select min(y) y
from a
where
y>y0
) minywhere
a.x=minx.x
and a.y=miny.y
其實兩個座標間的距離(m)可以看成是一個直角三角型的第三邊
其他兩邊分別為n1=abs(x0-x),n2=abs(y0-y)
這樣power(m,2) = power(n1,2)+power(n2,2)--直角三角型的三邊關係:)
建议使用逐步查询的方法,如用 where x> x-100 and x<x+100 and y>y-100 and y<y+100方型区域进行sqrt计划,如没有结果,再扩大。
然后建x,y复合索引,速度会很快