简体   繁体   中英

how to map wgs84 coordinates to sql server b-tree index (w/o using built in spatial indexes)

I would like to be able to map geographic points from WGS84, I believe, formatted for ms sql server, to the set of cells it would touch if the same coordinate pair were to be tessallated into an sql server spatial index with 4 hiearchical grids of 256 cells each.

The sql server 2008 spatial index does not ideally suit our needs because it doesn't support the use of both geographic and non-geographic data within the same index.

If we knew how to perform the translation ourselves it would seem like that would allow us to bypass the above limitation.

this page shows visually how a geography point can be mapped to planar cells which can be individually encoded as a sequence of from 1 and up to 4 positive integers. For an example of numbered cells please refer to the section "Deepest-Cell Rule" within the linked page.

I'm basically looking for pseduo-code on how to do just that.

Any help will be appreciated and if you know the algorithmic details that would be very much appreciated.

Thank you in advance.

A simple solution is to interleave x-and y co-ordinate, like in a morton curve aka z curve. You can verify it by calcuting the upper bound using the most significant bit. Bing maps uses a morton curve: http://msdn.microsoft.com/en-us/library/bb259689.aspx but a hilbert curve is much more complicated but also better in most cases. In hilbert curve it's using a gray code for the co-ordinate. Here is some code example: Mapping N-dimensional value to a point on Hilbert curve .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM