脚本
CREATE TABLE mylocation ( id SERIAL PRIMARY KEY,geom GEOMETRY(Point,4326),name VARCHAR(128),x double precision,y double precision ); INSERT INTO mylocation (geom,name,x,y) VALUES ( ST_GeomFromText('POINT(0.0001 0)','zhangsan',0.0001,0 ); INSERT INTO mylocation (geom,y) VALUES ( ST_GeomFromText('POINT(0.001 0)',0.001,y) VALUES ( ST_GeomFromText('POINT(0.1 0)',0.1,0 ); SELECT id,geom,y,ST_DistanceSphere( geom,ST_GeometryFromText('POINT(0 0)')) distance FROM mylocation WHERE ST_DWithin( geom,ST_GeomFromText('POINT(0 0)',0.001 )ORDER BY distance asc;;
查询语句 下面距离单位为m
SELECT id,ST_GeometryFromText('POINT(0 0)')) distance FROM mylocation WHERE ST_DWithin( geom::geography,4326)::geography,1000 ) ORDER BY distance asc;
原文链接:https://www.f2er.com/postgresql/194258.html