Skip to content

Commit

Permalink
Fig bug in auto computation of zoom levels (#214)
Browse files Browse the repository at this point in the history
For maps with large aspect ratio, contextily downloads tiles as if the map was
as small as the smallest dimension. It should base the zoom level on the
dimension that's a larger extent.
  • Loading branch information
jelson committed May 30, 2023
1 parent d821ac7 commit 0c8c9ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contextily/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def _calculate_zoom(w, s, e, n):
# Calculate the zoom
zoom_lon = np.ceil(np.log2(360 * 2.0 / lon_length))
zoom_lat = np.ceil(np.log2(360 * 2.0 / lat_length))
zoom = np.max([zoom_lon, zoom_lat])
zoom = np.min([zoom_lon, zoom_lat])
return int(zoom)


Expand Down
10 changes: 5 additions & 5 deletions tests/test_ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,13 @@ def test_add_basemap_auto_zoom():
4891969.810251278,
)
assert_array_almost_equal(ax_extent, ax.images[0].get_extent())
assert ax.images[0].get_array()[:, :, :3].sum() == 563185119
assert ax.images[0].get_array().sum() == 830571999
assert ax.images[0].get_array().shape == (1024, 1024, 4)
assert ax.images[0].get_array()[:, :, :3].sum() == 141378723
assert ax.images[0].get_array().sum() == 208225443
assert ax.images[0].get_array().shape == (512, 512, 4)
assert_array_almost_equal(
ax.images[0].get_array()[:, :, :3].mean(), 179.03172779083252
ax.images[0].get_array()[:, :, :3].mean(), 179.772343
)
assert_array_almost_equal(ax.images[0].get_array().mean(), 198.023796)
assert_array_almost_equal(ax.images[0].get_array().mean(), 198.579257)


@pytest.mark.network
Expand Down

0 comments on commit 0c8c9ce

Please sign in to comment.