数仓项目中geohash字典的构建(上)

数仓项目中geohash字典的构建(上)

–先将自己的全国县市字典表调整成扁平化的结构的表
–源表 t_md_areas
–目标表 geohash

–源表样例:

`id` `areaname` `parentid`(父编号) `shortname` `level`(级别) `flag` `wgs84_lng` `wgs84_lat` `gcj02_lng` `gcj02_lat` `bd09_lng`(区的纬度) `bd09_lat` (区的经度)
110000	北京市	0	北京	1	1	116.225197381925	40.2195249171251	116.23128	40.22077	116.395645037879	39.9299857780802
110100	北京市	110000	北京	2	1	116.225197381925	40.2195249171251	116.23128	40.22077	116.395645037879	39.9299857780802
110101	东城区	110100		3	1	116.410130065889	39.9271493544194	116.41637	39.92855	116.421884701264	39.9385740129861
110102	西城区	110100		3	1	116.359896235384	39.910932409618	116.36611	39.91231	116.373190104018	39.9342801437085
110105	朝阳区	110100		3	1	116.437354734245	39.9205326299248	116.44355	39.9219	116.521694891081	39.9589531664067

–目标表目标表样例:

geo       province   city     district
wtbm7y     河北省   辛集市    新垒头镇
wtbm8y     河南省   南阳市    方程县

–sql语句 意思: 区的父id join 市的id 市的父id join 省的id

create table tmp as 
select
d.bd09_lng as lng,
d.bd09_lat as lat,
p.areaname as province,
c.areaname as city,
d.areaname as district
from
t_md_areas d join t_md_areas c on d.`level`=3 and d.parentid=c.id 
             join t_md_areas p on c.parentid=p.id 
;

–代码实现:

115.795795381251	40.0008930314765	门头沟区	北京市	北京市
115.862836312904	39.7267526207963	房山区	    北京市	北京市
116.740079180676	39.8098148838513	通州区	    北京市	北京市
116.728229045281	40.1549514704414	顺义区	    北京市	北京市
116.216456356894	40.2217235498323	昌平区	    北京市	北京市
116.425194597379	39.6527901183645	大兴区	    北京市	北京市

这还是不是我们最终要的结果我们需要把经纬度改成geohash码!
剩下的需要用到geohash的算法窃听下部分解

发布了48 篇原创文章 · 获赞 11 · 访问量 1519

猜你喜欢

转载自blog.csdn.net/weixin_45896475/article/details/104272652
今日推荐