forked from geopandas/contextily
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
accept TMS source urls with flipped Y tiles
If a '{-y}' substring exists in source url, 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 Introduced try-except in _merge_tiles() to avoid some problems with tiles near server map limits. Probably not the best way to do this, so please test with other servers and correct it. Example usages: ```Python contextily_tms_test() # defaults to whole Iberian Peninsula contextily_tms_test(bbox=[-9.302, 42.85, -9.175, 43.060], zoom=14) # raises some errors trying to merge certain tiles: def contextily_tms_test(bbox=[-10.0, 35.0, 5.0, 45.0], tilesource='', size = (10,10), zoom=None): import contextily as cx import matplotlib.pyplot as plt import geopandas as gpd from shapely.geometry import shape west, south, east, north = tuple(bbox) ## gdf: GEODATAFRAME USED TO DEFINE MAP BOUNDARIES: geojson = { "type":"FeatureCollection", "crs": { "type": "name", "properties": { "name": "epsg:4326" } }, "features":[ { "type": "Feature", "properties": { "id": 1, "test": "a" }, "geometry": {"type": "Polygon", "coordinates": [[[west, north], [west, south], [east, south], [east, north]]]} }, ] } gdf = gpd.GeoDataFrame.from_features(geojson["features"], crs='epsg:4326') crs='epsg:4326' if len(tilesource)==0: tilesource = 'https://tms-mapa-raster.ign.es/1.0.0/mapa-raster/{z}/{x}/{-y}.jpeg' ## alpha=0 (only want to see the basemap: polygon is just used to define map limits) ax = gdf.plot(figsize=size, alpha=0.000, edgecolor="k") if zoom is None: cx.add_basemap(ax=ax, crs=crs, source=tilesource) else: cx.add_basemap(ax=ax, crs=crs, source=tilesource, zoom=zoom) str_limits = "_".join([str(round(p,2)) for p in bbox]) plt.savefig('contextily_test_{}_zoom-{}.png'.format(str_limits, zoom), bbox_inches='tight') ```
- Loading branch information
1 parent
0e38541
commit 5ba41c7
Showing
1 changed file
with
62 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters