How to convert between HERE HDLM 2D Coordinates and WGS84 longitude and latitude?
How to convert between HERE HDLM 2D Coordinates and WGS84 longitude and latitude?
HERE HDLM uses 64bit signed integer to present coordinates, you got a integer of 4354955124161939766, you want to know its WGS84 latitude and longitude, you have to:
1. Convert 64bit signed integer to binary, the result will be 0011110001101111111010001001110010100100011100001000100100110110.
2. Strip the 1st 0, the result will be 011110001101111111010001001110010100100011100001000100100110110.
3. Create 2 empty strings, one for latitude and the other for longitude. Iterate the binary, write 1st bit (0) to longitude string, 2nd bit (1) to latitude string, and so on, until full binary is iterated. You will get 2 stings: "01101011100001100010110000010110" for longitude, "1100111111010101100010010100101" for latitude.
4. Convert both binary string to integer, you will get 1803955222 for longitude, and -404044635 for latigude.
5. Convert latitude and longitude to degree, latitude will be -404044635 * (180 / 2^31) and longitude will be 1803955222 * (360 / math.pow(2^32)).
6. You will get result as latitude: -33.866630075499415, longitude: 151.20577996596694 .
You can use reversed logic to convert WGS84 latitude and longitude to HDLM coordinates format.
Python 3 codes below shows the conversion, from WGS84 to HDLM format, and vise versa.<br />import mathfrom bitstring import BitArraydef wgs84_to_hdlm_coord(lat, lng): lat_int_from_bin = math.floor(lat / (180 / math.pow(2, 31))) lng_int_from_bin = math.floor(lng / (360 / math.pow(2, 32))) b31_lat = '{:031b}'.format(lat_int_from_bin + (1 << 31)) b32_lng = '{:032b}'.format(lng_int_from_bin) b64_lat_lng = '0{}0'.format(''.join(i + j for i, j in zip(b32_lng, b31_lat))) b64_bitarray = BitArray(bin=b64_lat_lng) b64_signed_integer = b64_bitarray.int return b64_signed_integerdef hdlm_coord_to_WGS84(b64_signed_integer): b64int = BitArray(int=b64_signed_integer, length=64) b64bin = b64int.bin print(b64bin) bin_index = 0 b64bin_stripped = b64bin[1:] lng_bin = '' lat_bin = '' while bin_index < len(b64bin_stripped): if bin_index % 2 == 0: lng_bin += b64bin_stripped[bin_index] else: lat_bin += b64bin_stripped[bin_index] bin_index += 1 lat_int_from_bin = BitArray(bin=lat_bin).int lng_int_from_bin = BitArray(bin=lng_bin).int lat_float_from_int = lat_int_from_bin * (180 / math.pow(2, 31)) lng_float_from_int = lng_int_from_bin * (360 / math.pow(2, 32)) return {'lat': lat_float_from_int, 'lng': lng_float_from_int}print(wgs84_to_hdlm_coord(-33.86663, 151.20578))print(hdlm_coord_to_WGS84(4354955124161939766))<br />