cratedb geo 查询
cratedb支持的geo 查询还相对比较全,开发基本的功能已经够用了
安装cratedb
使用docker
docker run -d -p 4200:4200 crate
创建数据库
- 创建表
CREATE TABLE country (
name string,
country_code string primary key,
shape geo_shape INDEX USING "geohash" WITH (precision='100m'),
capital string,
capital_location geo_point
) WITH (number_of_replicas=0);
- 添加数据
INSERT INTO country (mame, country_code, shape, capital, capital_location)
VALUES (
'Austria',
'at',
{type='Polygon', coordinates=[
[[16.979667, 48.123497], [16.903754, 47.714866],
[16.340584, 47.712902], [16.534268, 47.496171],
[16.202298, 46.852386], [16.011664, 46.683611],
[15.137092, 46.658703], [14.632472, 46.431817],
[13.806475, 46.509306], [12.376485, 46.767559],
[12.153088, 47.115393], [11.164828, 46.941579],
[11.048556, 46.751359], [10.442701, 46.893546],
[9.932448, 46.920728], [9.47997, 47.10281],
[9.632932, 47.347601], [9.594226, 47.525058],
[9.896068, 47.580197], [10.402084, 47.302488],
[10.544504, 47.566399], [11.426414, 47.523766],
[12.141357, 47.703083], [12.62076, 47.672388],
[12.932627, 47.467646], [13.025851, 47.637584],
[12.884103, 48.289146], [13.243357, 48.416115],
[13.595946, 48.877172], [14.338898, 48.555305],
[14.901447, 48.964402], [15.253416, 49.039074],
[16.029647, 48.733899], [16.499283, 48.785808],
[16.960288, 48.596982], [16.879983, 48.470013],
[16.979667, 48.123497]]
]},
'Vienna',
[16.372778, 48.209206]
);
数据查询
具体语法可以参考参考资料对应的连接
- 支持match
SELECT name from country
WHERE match("shape",
'LINESTRING (13.3813 52.5229, 11.1840 51.5497, 8.6132 50.0782, 8.3715 47.9457, 8.5034 47.3685)'
);
- intersects distance within
SELECT within(capital_location, shape) AS capital_in_country
FROM country;
SELECT distance(capital_location, 'POINT(0.0 90.0)') as from_northpole
FROM country ORDER BY country_code;
SELECT intersects(
{type='LineString', coordinates=[[13.3813, 52.5229],
[11.1840, 51.5497],
[8.6132, 50.0782],
[8.3715, 47.9457],
[8.5034, 47.3685]]},
shape) as berlin_zurich_intersects
FROM country ORDER BY country_code;
参考资料
https://crate.io/docs/crate/reference/en/latest/general/dql/geo.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2014-08-06 window.open()与window.showModalDialog