Skip to content

Conversation

jorisvandenbossche
Copy link
Member

This PR removed the use of cartopy's merge_tiles with a custom implementation
(related to https://github.com/darribas/contextily/issues/4 and SciTools/cartopy#792).

It seemed this tile merging can actually rather easily be done, using some of the features of mercantile (which is already used to calculate the web tile x and y numbers given the zoom and bounds), and using some assumptions about the fact that we only deal with web map tiles (all rectangular equal sized images for a given extent).

Just pushing this now to show the implementation. I didn't yet look at or update the tests.
I actually expect the tests to be failing, as while doing this, I discovered that there is a bug in the current implementation (we are overlaying the tiles with one pixel overlap, so losing one pixel row, which gave a subtle hardly noticeable difference (only noted it by comparing the final array of both methods, you need to zoom in a lot to actually see it in the image).

@darribas
Copy link
Collaborator

Excellent! I think this will make contextily a lot leaner installation-wise!!!

@coveralls
Copy link

coveralls commented Jan 11, 2019

Coverage Status

Coverage increased (+0.4%) to 90.873% when pulling 57214b4 on jorisvandenbossche:merge-tiles into cb7a4a0 on darribas:master.

Copy link
Member Author

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests should be passing now.

Added some comments to explain the changes in the tests.

assert_array_almost_equal(ext, (0.0, 939258.2035682457,
6261721.35712164, 6887893.492833804))
assert_array_almost_equal(ext, (0.0, 939258.2035682457,
6261721.35712164, 6887893.492833804))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was duplicated with the line above

assert_array_almost_equal(ext, (0.0, 939258.2035682457,
6261721.35712164, 6887893.492833804))
rtr_bounds = [-613.0928221724841, 6262334.050013727,
938645.1107460733, 6888506.185725891]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needed to be updated, because the shape of the img array changed (and therefore also the transform calculation when writing the merged tiles with rasterio)

assert_array_almost_equal(ax_extent, ax.images[0].get_extent())
assert ax.images[0].get_array().sum() == 75687792
assert ax.images[0].get_array().shape == (256, 511, 3)
assert ax.images[0].get_array().sum() == 75853866
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all those small number changes are due to the fact that the 1 row/column on 256 is no longer incorrectly dropped when merging the tiles -> see also the shape changes; they are now multiples of 256)

@darribas
Copy link
Collaborator

Nice!!! I'd say, add documentation for _merge_tiles and this is good to go. It'll be great to merge this one.

@darribas darribas merged commit 9a4269f into geopandas:master Jan 18, 2019
@jorisvandenbossche jorisvandenbossche deleted the merge-tiles branch January 18, 2019 14:07
@darribas darribas mentioned this pull request Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants