4

Can any point me to the Java code for Z-order curve implementation? I have x,y floating point coordinates and I want a single dimensional representation for them, which I know is possible using Z-order curve transformation. I am unable to find a Java implementation or a C code for this function.

I will great appreciate any help on this!!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
ayush singhal
  • 1,879
  • 2
  • 18
  • 33

2 Answers2

1

GridKit has a Z-Order implementation according to koders. There is also STANN for nearest neighbour searches on point clouds, if you accept c++ as well.

SpaceTrucker
  • 13,377
  • 6
  • 60
  • 99
0

I'd write this myself.

First convert from float to integer, by computing both exponents using Math.getExponent and taking the maximum of these. Then you can scale the numbers such that the larger of these numbers has 32 bits before the decimal point. Then round (or truncate) the results to int. Then you'll have to combine those two integers into a single long using bit-interleaving, and finally you can scale the result again using the stored exponent.

If your input already is restricted to e.g. the [0,1] range, you can simply use fixed-point arithmetic based on integers instead of this manual rescaling.

To do the bit interleaving, I'd use a lookup map which e.g. takes a block of 8 bits and computes the corresponding 16 bit interleaved block. That way you won't have to do too many bit shift operations.

MvG
  • 57,380
  • 22
  • 148
  • 276
  • 1
    I assume that the OP is not looking merely to *encode* the latitude/longitude pair—which is the easy part—but to do efficient look-up later taking advantage of the Tropf and Herzog *BIGMIN*/*LITMAX* range cutting technique. – seh Aug 08 '12 at 23:50
  • Could you please give more details? I don't quiet understand. Could you please give a sample of how to convert a float to int? I have found the result of how two integers into a single long using bit-interleaving. – gfan Apr 07 '15 at 12:12
  • 1
    Hi MvG, Could you please give a sample code of your first and second paragraph. For the third, I have known how to bit interleaving. – gfan May 09 '15 at 08:52