--Get images of OpenStreetMap and Geographical Survey Institute maps using the Python library py-staticmaps
Install the py-staticmaps package.
$ pip install py-staticmaps
Pycairo, s2sphere, etc. are also installed as dependent libraries.
Source code.
import staticmaps
#Create a Context object and specify the zoom level and latitude / longitude
#Latitude / longitude is create_s2sphere generated by latlng.Specify LatLng object
context = staticmaps.Context()
context.set_zoom(17)
context.set_center(staticmaps.create_latlng(35.170560, 136.882090))
#Pycairo cairo by specifying the width and height of the image.Get ImageSurface object
image_surface = context.render_cairo(800, 600)
#Output map image PNG file
image_surface.write_to_png('osm.png')
Execution result.
Source code.
import staticmaps
#Create a TileProvider object for the Geographical Survey Institute tiles of the Geographical Survey Institute
tile_provider_chiriin = staticmaps.TileProvider(
name='chiriin',
url_pattern='https://cyberjapandata.gsi.go.jp/xyz/std/$z/$x/$y.png', #Geographical Survey tile URL
attribution='Source: Geospatial Information Authority of Japan', #I can't use Japanese, so it's written in English
max_zoom=18, #Maximum zoom level available
)
#Create a Context object and specify TileProvider, zoom level and latitude / longitude
context = staticmaps.Context()
context.set_tile_provider(tile_provider_chiriin)
context.set_zoom(14)
context.set_center(staticmaps.create_latlng(35.170560, 136.882090))
#Pycairo cairo by specifying the width and height of the image.Get ImageSurface object
image_surface = context.render_cairo(800, 600)
#Output map image PNG file
image_surface.write_to_png('chiriin.png')
Execution result.
Recommended Posts