博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cratedb geo 查询
阅读量:6976 次
发布时间:2019-06-27

本文共 2261 字,大约阅读时间需要 7 分钟。

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;

参考资料

 
 
 
 

转载地址:http://yiupl.baihongyu.com/

你可能感兴趣的文章
什么是机器人底盘 答案在这里!
查看>>
SNMP 协议 OID的使用
查看>>
【CSS3教程】CSS3基础&常用技巧&实例集合
查看>>
面试题:2018最全Redis面试题整理
查看>>
引用头文件#include <queue>出错
查看>>
koa2 简单了解
查看>>
阿里P7架构师告诉你Java架构师必须知道的 6 大设计原则
查看>>
详解微信域名防封的方法以及检测等工具的技术原理
查看>>
smobiler介绍(二)
查看>>
Windows 8 快捷键大全
查看>>
安装hadoop下的sqoop1.99.3及配置问题全解决
查看>>
expect
查看>>
Could not create the view: An unexpected exception was thrown. Myeclipse空间报错
查看>>
RHEL6入门系列之九,常用命令2
查看>>
LINUX新手入门-1.装系统
查看>>
Attach Volume 操作(Part II) - 每天5分钟玩转 OpenStack(54)
查看>>
puppet 初识
查看>>
rsync
查看>>
ubuntu安装redis的方法以及PHP安装redis扩展、CI框架sess使用redis的方法
查看>>
功能演示:戴尔PowerConnect 8024交换机VLAN的创建与删除
查看>>