ABAP实现Geohash

前几天群里有人问ABAP有没有Geohash函数,用来帮助SAP存储门店位置、实现对附近门店查找的功能。因为没有查到,所以我动手写了一个。

 

Geohash是什么

Geohash是一种公共域地理编码系统,它将一个地理位置编码成一串字母和数字。字符串越长,表示的范围越精确。两个字符串的相同前缀越多,表示它们所代表的地点的距离越近,这样就可以利用字符串的前缀匹配来快速查询附近的地点信息。

关于Geohash的更多介绍,可以参考:

GeoHash核心原理解析

【应用】基于IPFS和GeoHash构建具有地理位置价值服务的DDApp(理论篇)

Wikipedia

 

本文链接:https://www.cnblogs.com/hhelibeb/p/11426826.html 

原创内容,转载请注明

实现

我在Github创建了一个repo,包含了自己写的编码、解码方法。地址是:https://github.com/hhelibeb/geohash-abap

 目前还有更多功能在实现中,有兴趣的朋友可以来一起写~

class zcl_geohash definition public final create public . public section. types: ty_tude type p length 16 decimals 12 . constants c_max_hash_length type i value 12 ##NO_TEXT. class-methods class_constructor . class-methods encode importing !i_longitude type ty_tude !i_latitude type ty_tude !i_length type i default 8 returning value(r_geo_hash) type string . class-methods decode importing !i_geo_hash type string exporting !e_longitude type ty_tude !e_latitude type ty_tude . protected section. private section. types: begin of ty_base32, decimals type i, base32 type string, end of ty_base32 . types: ty_base32_t1 type hashed table of ty_base32 with unique key decimals . types: ty_base32_t2 type hashed table of ty_base32 with unique key base32 . types: begin of ty_code, code type string, end of ty_code. types: ty_code_t type standard table of ty_code with empty key. class-data mt_base32_code1 type ty_base32_t1 . class-data mt_base32_code2 type ty_base32_t2 . constants c_longitude_min type ty_tude value '-180.00' ##NO_TEXT. constants c_longitude_max type ty_tude value '180.00' ##NO_TEXT. constants c_latitude_min type ty_tude value '-90.00' ##NO_TEXT. constants c_latitude_max type ty_tude value '90.00' ##NO_TEXT. constants c_zero type c value '0' ##NO_TEXT. constants c_one type c value '1' ##NO_TEXT. class-methods bin_to_dec importing !i_bin type string default '0' returning value(r_dec) type int4 . class-methods dec_to_bin importing !i_dec type int4 returning value(r_bin) type string . class-methods get_bin importing !i_left type ty_tude !i_right type ty_tude !i_tude type ty_tude exporting !e_left type ty_tude !e_right type ty_tude !e_bin type char1 . class-methods get_tude importing !i_left type ty_tude !i_right type ty_tude !i_bin type string exporting !e_left type ty_tude !e_right type ty_tude !e_tude type ty_tude . class-methods: get_code_neighbor importing i_table type standard table i_member type string returning value(r_table) type ty_code_t. ENDCLASS.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsfsgp.html