I search on the Internet, but find merely a little information about How to convert the latitude & longitude to Morton code(z order curve). From the link I know how to make two int to Morton Code. But, if I have float values like latitude or longitude, How should I convert the float value to int? Then I can convert the int to Morton code. For exmaple, c# code:
我在互联网上搜索,但只找到一些关于如何将纬度和经度转换为莫顿码(z阶曲线)的信息。从链接我知道如何使两个int到莫顿代码。但是,如果我有浮动值,如纬度或经度,我应该如何将浮点值转换为int?然后我可以将int转换为Morton代码。例如,c#代码:
float value a=43.2345f;
int aint1=43.2345*10000;
int aint2=(int)BitConverter.DoubleToInt64Bits(43.2345);
Here, I don't have any idea which I should choose. Could you please help me? I didn't find a method like 'BitConverter.FloatToInt32Bits'. As of now, I don't know the reason.
在这里,我不知道应该选择哪个。请你帮助我好吗?我找不到像'BitConverter.FloatToInt32Bits'这样的方法。截至目前,我不知道原因。
Upate 1: I found an answer here, but I don't quite understand the answer.
Upate 1:我在这里找到了答案,但我不太明白答案。
1 个解决方案
#1
I have spent sometime searching for answer to that question. It appears that spatial curves (z-order curve, Hilbert curve, etc) need to be build on positive integers, which is a problem because lat/lon can be negative floating numbers.
我花了一些时间寻找这个问题的答案。似乎空间曲线(z-顺序曲线,希尔伯特曲线等)需要建立在正整数上,这是一个问题,因为lat / lon可以是负浮点数。
Found several projects where solution is to convert to positive integers, for example:
找到了几个解决方案转换为正整数的项目,例如:
// lat: -90 .. +90
var iLat = Math.round((lat + 90.0) * 100000); // 5 digits
// lng: -180 .. +180
var iLng = Math.round((lng + 180.0) * 100000); // 6 digits
After converting to ints some convert integers to bit arrays and build curve on those values, while others just use the integer representation to build curve. I guess for large space length of the curve might be too big to fit into an integer and that is why arrays are used. However, I am still looking into that.
转换为int后,一些转换整数到位数组并在这些值上构建曲线,而其他只是使用整数表示来构建曲线。我想曲线的大空间长度可能太大而不适合整数,这就是使用数组的原因。但是,我仍在调查。
#1
I have spent sometime searching for answer to that question. It appears that spatial curves (z-order curve, Hilbert curve, etc) need to be build on positive integers, which is a problem because lat/lon can be negative floating numbers.
我花了一些时间寻找这个问题的答案。似乎空间曲线(z-顺序曲线,希尔伯特曲线等)需要建立在正整数上,这是一个问题,因为lat / lon可以是负浮点数。
Found several projects where solution is to convert to positive integers, for example:
找到了几个解决方案转换为正整数的项目,例如:
// lat: -90 .. +90
var iLat = Math.round((lat + 90.0) * 100000); // 5 digits
// lng: -180 .. +180
var iLng = Math.round((lng + 180.0) * 100000); // 6 digits
After converting to ints some convert integers to bit arrays and build curve on those values, while others just use the integer representation to build curve. I guess for large space length of the curve might be too big to fit into an integer and that is why arrays are used. However, I am still looking into that.
转换为int后,一些转换整数到位数组并在这些值上构建曲线,而其他只是使用整数表示来构建曲线。我想曲线的大空间长度可能太大而不适合整数,这就是使用数组的原因。但是,我仍在调查。