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

TMS tile providers: negative {-y} in urls #250

Open
abubelinha opened this issue Aug 19, 2024 · 5 comments
Open

TMS tile providers: negative {-y} in urls #250

abubelinha opened this issue Aug 19, 2024 · 5 comments

Comments

@abubelinha
Copy link

abubelinha commented Aug 19, 2024

Basically all this is already described in geopandas/xyzservices#177

I found some tile servers in these pages and I was trying to use them in contextily:

https://www.ign.es/web/ide-area-nodo-ide-ign
https://idee.es/en/servicios-teselas

I am guessing there is a problem with xyz syntax since their urls end in {z}/{x}/{-y}.extension
Not sure how to implement that in my code:

import contextily as cx
# gdf is a simple geodataframe of a 10 x 10 Km square polygon inside Spain
ax = gdf.plot(figsize=(10, 10), alpha=0.05, edgecolor="k")
# this works well for my area:
tile_source = cx.providers.OpenStreetMap.Mapnik  
tile_attribution = 'OSM contributors' 
# but this fails:
tile_source='https://tms-pnoa-ma.idee.es/1.0.0/pnoa-ma/{z}/{x}/-{y}.jpeg'  
tile_attribution = 'idee.es pnoa-ma'
cx.add_basemap(ax=ax, crs='epsg:4326', source=tile_source, attribution=tile_attribution)
plt.savefig('contextily_test.png', bbox_inches='tight')

Thanks for any help
@abubelinha

EDIT: some related links?

@abubelinha abubelinha changed the title help adding new tile providers with negative {-y} in urls TMS tile providers: negative {-y} in urls Aug 19, 2024
@abubelinha
Copy link
Author

I was able to got this to work touching some tile.py lines in my installed package.

I basically look for a '{-y}' string in source url.
If that substring exists, I reconstruct the tiles array in both bounds2img() and _merge_tiles() in order to correct y values using the formula provided by @tmcw here:
https://gist.github.com/tmcw/4954720

This is probably not the best way to do it but I am happy to share my code so an expert can tell if there is something reusable in it or this should be implemented in a very different way.
Sorry I am not a git user.
Would it be enough if I clone the repo, edit the file and share a link here, so someone else can test it?

@martinfleis
Copy link
Member

Would it be enough if I clone the repo, edit the file and share a link here, so someone else can test it?

Yeah, that would help!

@abubelinha
Copy link
Author

abubelinha commented Aug 24, 2024

I uploaed my modified tile.py here:
https://github.com/abubelinha/contextily/commits/inverted_y_sources/contextily/tile.py

But when I compared lines changed, I realized I was not using the last version published in github:
I edited the pip-installed version (1.5.2) instead.

I later tried to install development version from github, but I couldn't:

C:\Python38\scripts\pip install https://github.com/geopandas/contextily/archive/master.zip
Collecting https://github.com/geopandas/contextily/archive/master.zip
  Using cached https://github.com/geopandas/contextily/archive/master.zip
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  ¦ exit code: 1
      LookupError: setuptools-scm was unable to detect version for C:\Users\abu\AppData\Local\Temp\pip-req-build-mexwnes2.

      Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.

      For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.

I hope differences are not important and you can test my changes (I only touched a couple of functions and added a new one).

In my commit I also added (as a commit-comment) a contextily_tms_test() function to test my changes using a given server, zoom and bounding box coordinates to generate a image.

I couldn't find yet any global coverage mapping service which also uses flipped '{-y}' tiles and reaches high zoom levels (i.e. 14 or higher). So my examples are only from the Spanish services I posted above and I guess they will fail to serve tiles outside Spain unless you use big bounding boxes to force small zoom levels.

Please test it using other flipped-Y servers that you know

@martinfleis
Copy link
Member

This is all eventually related to #120 which was never finished.

@abubelinha
Copy link
Author

No idea, but IMHO my issue is much simpler.

Just a matter of correcting y values when servers use an inverted tile numbering system for y axis

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

No branches or pull requests

2 participants