Get images of OpenStreetMap and Geographical Survey Institute maps with Python + py-staticmaps

Overview

--Get images of OpenStreetMap and Geographical Survey Institute maps using the Python library py-staticmaps

This environment

Install py-staticmaps

Install the py-staticmaps package.

$ pip install py-staticmaps

Pycairo, s2sphere, etc. are also installed as dependent libraries.

Get a map image of OpenStreetMap

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.

osm.png

Get a map image of the Geographical Survey Institute map

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.

chiriin.png

Reference material

Recommended Posts

Get images of OpenStreetMap and Geographical Survey Institute maps with Python + py-staticmaps
Get images of OpenStreetMap and Geographical Survey Institute maps with Python + staticmap
Try to image the elevation data of the Geographical Survey Institute with Python
Get media timeline images and videos with Python + Tweepy
Get rid of dirty data with Python and regular expressions
Sample of HTTP GET and JSON parsing with python of pepper
Coexistence of Python2 and 3 with CircleCI (1.0)
Capturing images with Pupil, python and OpenCV
Importing and exporting GeoTiff images with Python
Get rid of DICOM images in Python
Get the number of articles accessed and likes with Qiita API + Python
Get and estimate the shape of the head using Dlib and OpenCV with python
Explanation of creating an application for displaying images and drawing with Python
Get git branch name and tag name with python
[Python] Get rid of dating with regular expressions
Implementation of TRIE tree with Python and LOUDS
Get CPU information of Raspberry Pi with Python
Wavelet transform of images with PyWavelets and OpenCV
Get Gmail subject and body with Python and Gmail API
Continuation of multi-platform development with Electron and Python
Get the stock price of a Japanese company with Python and make a graph
Example of reading and writing CSV with Python
Get a large amount of Starbucks Twitter data with python and try data analysis Part 1
Extract images and tables from pdf with python to reduce the burden of reporting
Display embedded images of mp3 and flac with mutagen
Try projective transformation of images using OpenCV with Python
Easy partial download of mp4 with python and youtube-dl!
Visualize the range of interpolation and extrapolation with python
Get comments on youtube Live with [python] and [pytchat]!
Create a batch of images and inflate with ImageDataGenerator
Get mail from Gmail and label it with Python3
Get the operation status of JR West with Python
[Python] Get user information and article information with Qiita API
Get an abstract understanding of Python modules and packages
Comparison of CoffeeScript with JavaScript, Python and Ruby grammar
Version control of Node, Ruby and Python with anyenv
I tried "morphology conversion" of images with Python + OpenCV
Get date with python
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
Get a list of CloudWatch Metrics and a correspondence table for Unit units with Python boto
Compare HTTP GET / POST with cURL (command) and Python (programming)
Perform isocurrent analysis of open channels with Python and matplotlib
Get a list of purchased DMM eBooks with Python + Selenium
Send experiment results (text and images) to slack with Python
Detect objects of a specific color and size with Python
[Python x Zapier] Get alert information and notify with Slack
Get additional data to LDAP with python (Writer and Reader)
Play with the password mechanism of GitHub Webhook and Python
Get the source of the page to load infinitely with python.
Get country code with python
Programming with Python and Tkinter
Encryption and decryption with Python
Bordering images with python Part 1
Get Twitter timeline with python
Get Youtube data with python
Get thread ID with python
Faster loading of Python images
Get started with Python! ~ ② Grammar ~
python with pyenv and venv
[python] Get quotient and remainder
Get stock price with Python