建表语句:
CREATE TABLE ts.points ( name VARCHAR (20) NOT NULL, location POINT NOT NULL, description VARCHAR (200) );
添加记录如下:
INSERT INTO Points (name, location) VALUES ( ‘p1‘ , GeomFromText( ‘ POINT(10 20) ‘ ) ) INSERT INTO Points (name, location) VALUES ( ‘p2‘ , GeomFromText( ‘ POINT(11 30) ‘ ) ) INSERT INTO Points (name, location) VALUES ( ‘p3‘ , GeomFromText( ‘ POINT(10 21) ‘ ) )
查询操作如下:
SELECT NAME, ASTEXT(LOCATION),X(LOCATION),Y(LOCATION) FROM POINTS
查询所有记录离指定点的距离
SELECT *,ROUND(6378.138*2*ASIN(SQRT(POW(SIN( (X(LOCATION)*PI()/180-10*PI()/180)/2),2)+COS(X(LOCATION)*PI()/180)*COS(10*PI()/180)* POW(SIN( (Y(LOCATION)*PI()/180-20*PI()/180)/2),2)))*1000) AS DISTANCE FROM POINTS ORDER BY DISTANCE ASC
注:指定点信息(10,20),ps:10为X(经度),20为Y(纬度)
查询附近100公里数据:
SELECT name ,X(LOCATION),Y(LOCATION) FROM points WHERE MBRContains ( LineString ( Point ( 10 + 100 / ( 111.1 / COS(RADIANS(104.067221))), 20 + 100 / 111.1 ), Point ( 10 - 100 / ( 111.1 / COS(RADIANS(104.067221))), 20 - 100 / 111.1 ) ), location )
目标点坐标为(10,20)
时间: 2024-11-05 17:31:49