-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
ENH: Tile warping (#48) #49
Conversation
Anybody recognises the errors popping up? Never seen them and they seem to do with |
Yeah, that's really odd, and it's only affecting the 3.6 runs? never seen this before, but it's probably not anything you've changed. |
The error you're seeing was a temporary problem with pytest-cov (the latest pytest release yesterday broke that package, but they already released an update), so it you restart the travis build (or push again), it should work again. |
Something like --- a/contextily/plotting.py
+++ b/contextily/plotting.py
@@ -84,6 +84,12 @@ def add_basemap(ax, zoom=ZOOM, url=sources.ST_TERRAIN,
# Extent
left, right = ax.get_xlim()
bottom, top = ax.get_ylim()
+ if crs is not None:
+ import pyproj
+ proj_in = pyproj.Proj(crs, preserve_units=True)
+ proj_out = pyproj.Proj({'init': 'epsg:3857'}, preserve_units=True)
+ left, bottom = pyproj.transform(proj_in, proj_out, left, bottom)
+ right, top = pyproj.transform(proj_in, proj_out, right, top)
# Zoom
if isinstance(zoom, str) and (zoom.lower() == 'auto'):
min_ll = _sm2ll(left, bottom) fixes it. But the question is maybe a bit which library we want to use here exactly. |
Merge branch 'master' of https://github.com/darribas/contextily into tile_warping#48
…tile_warping#48
…able to reproject tiles and other rasters on-the-fly
…re merging into master but useful for tests and guidance
OK I've worked on this a bit more and I think it actually now fully works as one would expect it. Things I've included:
One thing I wanted to check with you. As @jorisvandenbossche mentions, for this to work, we need reprojection capabilities for points. Currently, I'm doing this in If you OK this (@jorisvandenbossche and/or @ljwolf ), I'll add tests and make sure they pass, it should be pretty straightforward. |
Personally, I think it's fine to use geopandas's crs stuff for this. It's not a particularly onerous dependency given we will already have rasterio as one for the resampling. |
Some user feedback:
Using WGS84 lon/lat, I need to limit the axis extent manually, otherwise pyproj cannot project the image bounds to WebMercator.
Should we try to automatically limit the bounds? (we know the bounds of web mercator) Converting the countries first to WebMercator gives the following bug:
(which doesn't happen on master) In general, I am also not sure we should by default warp the web mercator images to WGS84 / plate carree coordinates. This will give quite distorted images. |
New commits pass locally and implement warping with a default to no warping. |
@jorisvandenbossche / @ljwolf, any idea of the error that's returning now? I've not seen it before and it's not the rasterio install from the weekend. Maybe something related to #44? |
@darribas seems something went wrong with your rebase / merge of master, as the diff now shows many things of other PRs. Maybe try to squash it into a single commit to clean-up? |
The first one not directly, the second one if from a missing geopandas |
How can I squash? I think it was my merge with |
hey @jorisvandenbossche this is passing after the last commit to add |
Re-up of this one for @jorisvandenbossche and @ljwolf to have a look. if It works we can merge in and we're closer to the release by the end of July :) |
Adding CRS option to add_basemap Adding warping imports on tile.py Adding _warper, warp_tiles and warp_image_transform to tile.py to be able to reproject tiles and other rasters on-the-fly Adding warping functionality to add_basemap Adding notebook guide for warping functionality (we might remove before merging into master but useful for tests and guidance setting default to no warping on add_basemap Adding warp_tiles and warp_img_transform to user land Adding tests for warping functionality in tile.py Adding tests for warping functionality in add_basemap adding geopandas to test suite so warping tests pass
e75d690
to
c919bf9
Compare
@darribas I rebased / squashed everything to fix the conflicts, and forced pushed. The diff looks better now (and I hope I fixed everything correctly, if you can quickly check the diff?). Best be careful how to pull it again locally for you. |
Some feedback:
|
contextily/plotting.py
Outdated
out_bb = in_bb.to_crs(t_crs) | ||
left, top = list(out_bb['lt'].coords)[0] | ||
right, bottom = list(out_bb['rb'].coords)[0] | ||
return left, right, bottom, top |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can rather simply implement this with just pyproj (or even simpler, also no need for creating points of it), and so not need to add geopandas as a dependency (only pyproj). I think the following should be a drop in replacement:
def _reproj_bb(left, right, bottom, top, s_crs, t_crs):
proj_source = pyproj.Proj(s_crs, preserve_units=True)
proj_target = pyproj.Proj(t_crs, preserve_units=True)
x, y = pyproj.transform(proj_source, proj_target, [left, right], [bottom, top])
left, right = x
bottom, top = y
return left, right, bottom, top
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, rasterio also has a rasterio.warp.transform_bounds(src_crs, dst_crs, left, bottom, right, top)
which I think does exactly what we need here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I don't think that was there last time I checked on rasterio
! Addressed in b0354e6
contextily/tile.py
Outdated
@@ -205,6 +209,125 @@ def _fetch_tile(tile_url, wait, max_retries): | |||
return image | |||
|
|||
|
|||
def warp_tiles(img, ext, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ext -> extent ?
(I find that more readable, and it's also called like that in the return section of the bounds2img docstring)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed in 8877dd4
Co-Authored-By: Joris Van den Bossche <jorisvandenbossche@gmail.com>
Merged! |
Initial commit to add tile warping functionality