Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with sample tile system code #318

Open
hvanbakel opened this issue Dec 28, 2023 · 2 comments
Open

Issue with sample tile system code #318

hvanbakel opened this issue Dec 28, 2023 · 2 comments
Labels

Comments

@hvanbakel
Copy link

I use the tile system class as documented here

This has been working well for years. However recently a bug was reported which boiled down to a lat lng of length x would generate a different key then asking for a key of length x+1.
This violates the rule that removing characters at the end gets you a key to a bigger tile that enconmpasses the smaller one.

I've added a sample test case that fails given the code that's on the page right now.

break the tiles.txt

@timlms
Copy link

timlms commented Feb 5, 2024

This is a result of rounding when converting a lat/long pair (double) to a pixel X,Y (integer), which is in the PixelX/Y equations.
This is intended to center the pixel on the integer value, such that a pixel with x=1 would include all longitude values that fall between 0.5 and 1.5.
In some edge cases, a pixel can get rounded into one tile at one level of detail, but into a different tile at another LOD - it is just how the map gets pixelated at a given level of detail.
In your example, your longitude is -117.78443
At LOD 16, this gives an exact value of 2899455.71236978. This gets rounded up to 2899456, which determines the tile and quadkey.
However, at LOD 17, this gives an exact value of 5798911.42473956, which gets rounded down, effectively pushing the pixel left, into the 02301320201131013 quadkey.
If it is important to your algorithm that the pixel always be in the same parent quadkey then you can truncate the double value and that should always keep the pixels together.

@hvanbakel
Copy link
Author

Thank you for looking into this.

Your last sentence has me a little confused though

If it is important to your algorithm that the pixel always be in the same parent quadkey then you can truncate the double value and that should always keep the pixels together.

Isn't that the exact purpose of what this algorithm is trying to achieve? What's the rationale for not doing that in the sample code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants