-
Notifications
You must be signed in to change notification settings - Fork 5
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
Error in the implementation of tile box boundaries #13
Comments
Forget that, that was a lack of coffee speaking... |
Sorry, didn't receive any e-mail notifications on this repo in the past time and thus totally missed all recent issues. Will have a look into this later today! |
Looks like we're indeed picking up the wrong tile here. Your code yields quadkey |
This is what it looks like on the map: blue (1) is your query point, green (2 and 3) are SW and NE reported by pyquadkey2 and red (4 and 5) are SW and NE reported by jquad (which are probably the correct ones).
|
Actually, the key returned by using Microsoft.MapPoint;
double latitude = -27.052395;
double longitude = 152.97702;
int levelOfDetail = 6;
string quadKey = GetQuadKey(latitude, longitude, levelOfDetail);
Console.WriteLine("QuadKey: " + quadKey); // returns '311213'
static string GetQuadKey(double latitude, double longitude, int levelOfDetail)
{
int pixelX, pixelY;
TileSystem.LatLongToPixelXY(latitude, longitude, levelOfDetail, out pixelX, out pixelY);
int tileX, tileY;
TileSystem.PixelXYToTileXY(pixelX, pixelY, out tileX, out tileY);
return TileSystem.TileXYToQuadKey(tileX, tileY, levelOfDetail);
} But this would mean both ethlo/jquad and CartoDB/python-quadkey are wrong? 🤔 So, the bug must be somewhere in the tile -> bbox calculation part. |
I went through every line of the code, but couldn't find the issue. I honestly have no clue what's wrong here. Would love to get some help on this! |
I think the issue is here:
You can check this out in the code below: import math
def get_quadkey(lat: float, lng: float, zoom: int)->str:
x = int((lng + 180) / 360 * (1 << zoom))
y = int((1 - math.log(math.tan(math.radians(lat)) + 1 / math.cos(math.radians(lat))) / math.pi) / 2 * (1 << zoom))
quadkey = ''
for i in range(zoom, 0, -1):
digit = 0
mask = 1 << (i - 1)
if (x & mask) != 0:
digit += 1
if (y & mask) != 0:
digit += 2
quadkey += str(digit)
return quadkey
get_quadkey(-27.052395, 152.97702, 6) If you replace |
Thanks a lot for your help on this! |
Hi,
thank you for this really useful library.
I noticed an unexpected behavior, when I run:
for
I get an assertion returns AssertionError is being raised, which is a behavior that clearly shouldn't happen as each point should be included in its associated rectangular box (or I'm missing something).
Thank you,
The text was updated successfully, but these errors were encountered: