OSM Tile Loader¶
In [1]:
Copied!
from srai.loaders.osm_loaders import OSMTileLoader
from srai.regionalizers import geocode_to_region_gdf
ZOOM = 9
from srai.loaders.osm_loaders import OSMTileLoader
from srai.regionalizers import geocode_to_region_gdf
ZOOM = 9
Get tiles from tile server¶
In order to get tiles use load method. Method load
returns GeoDataFrame
object with images or path to them, as chosen data_collector. Returned frame contains also geographical coordinates of tile and x, y, z coordinates used by tile servers.
In [2]:
Copied!
loader = OSMTileLoader("https://tile.openstreetmap.de", zoom=ZOOM, verbose=True)
gdf = geocode_to_region_gdf("Wroclaw, Poland")
tiles = loader.load(gdf)
tiles
loader = OSMTileLoader("https://tile.openstreetmap.de", zoom=ZOOM, verbose=True)
gdf = geocode_to_region_gdf("Wroclaw, Poland")
tiles = loader.load(gdf)
tiles
Getting tile from url: https://tile.openstreetmap.de/9/279/170.png
Getting tile from url: https://tile.openstreetmap.de/9/279/171.png
Getting tile from url: https://tile.openstreetmap.de/9/280/170.png
Getting tile from url: https://tile.openstreetmap.de/9/280/171.png
Out[2]:
x | y | geometry | z | tile | |
---|---|---|---|---|---|
region_id | |||||
279_170_9 | 279 | 170 | POLYGON ((16.87500 51.61802, 16.87500 51.17934... | 9 | <PIL.PngImagePlugin.PngImageFile image mode=P ... |
279_171_9 | 279 | 171 | POLYGON ((16.87500 51.17934, 16.87500 50.73646... | 9 | <PIL.PngImagePlugin.PngImageFile image mode=P ... |
280_170_9 | 280 | 170 | POLYGON ((17.57812 51.61802, 17.57812 51.17934... | 9 | <PIL.PngImagePlugin.PngImageFile image mode=P ... |
280_171_9 | 280 | 171 | POLYGON ((17.57812 51.17934, 17.57812 50.73646... | 9 | <PIL.PngImagePlugin.PngImageFile image mode=P ... |
To get records conveniently use SlippyMapId
In [3]:
Copied!
tiles.loc[f"279_170_{ZOOM}"]["tile"]
tiles.loc[f"279_170_{ZOOM}"]["tile"]
Out[3]:
Get one tile¶
In [4]:
Copied!
loader = OSMTileLoader("https://tile.openstreetmap.de", zoom=2)
tile = loader.get_tile_by_x_y(2, 1)
tile
loader = OSMTileLoader("https://tile.openstreetmap.de", zoom=2)
tile = loader.get_tile_by_x_y(2, 1)
tile
Out[4]: