[PYTHON] YOLP Get map information XML file with Yahoo! Static Map API

Overview

--Call YOLP Yahoo! Static Map API in Python to get map image and map information XML --YOLP If you specify xml in the output parameter of Yahoo! Static Map API, you can get the information about the map image to be acquired when output = xml is not in XML. --Operation check environment: macOS Catalina + Python 3.8.5

Program by Python

from urllib.request import Request, urlopen
import xml.dom.minidom as MD

appid = 'YOUR APPLICATION ID' #Specify application ID
headers = {'User-Agent': 'Yahoo AppID: {0}'.format(appid)}

# lat=Latitude of the center, lon=Longitude of the center, z=Scale level, output=Output format
#This time, specify the latitude and longitude of Nagoya Station
png_url = 'https://map.yahooapis.jp/map/V1/static?lat=35.170476&lon=136.882250&z=17'
xml_url = 'https://map.yahooapis.jp/map/V1/static?lat=35.170476&lon=136.882250&z=17&output=xml'

#Download and save the map image
req = Request(png_url, headers=headers)
with urlopen(req) as res:
  with open ('map.png', mode='wb') as file:
    file.write(res.read())

#Output XML of map information
req = Request(xml_url, headers=headers)
with urlopen(req) as res:
  body = res.read().decode('utf-8')
  with open ('map.xml', mode='w') as file:
    #Format XML and output
    dom = MD.parseString(body)
    dom.writexml(file, addindent='  ', newl='\n', encoding='utf-8')

Output result

Map image

The acquired map image.

map.png

Map information XML

The meaning of the main elements and attributes.

--Coordinates: Map center coordinates --Coordinate-UL: Coordinates on the upper left of the map --Coordinate-UR: Coordinates on the upper right of the map --Coordinate-DL: Coordinates at the bottom left of the map --Coordinate-DR: Coordinates at the bottom right of the map --Image: Map size (unit: pixel) --Scales: List of scale values that can be displayed on the map in the center coordinates of the map --mode: Map type --Scale: Scale value --zlevel: Scale level --sc: Scale ID

The retrieved XML file.

map.xml


<?xml version="1.0" encoding="utf-8"?>
<ResultSet xmlns="urn:yahoo:jp:olp:static" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:yahoo:jp:olp:static http://olp.yahooapis.jp/OpenLocalPlatform/V1/staticResponse.xsd">
  <Result>
    <Coordinates datum="WGS84" format="lon,lat">136.88225,35.170476</Coordinates>
    <Coordinate-UL>
      <Coordinates datum="WGS84" format="lon,lat">136.8768855819702,35.1748609813922</Coordinates>
    </Coordinate-UL>
    <Coordinate-UR>
      <Coordinates datum="WGS84" format="lon,lat">136.8876144180298,35.1748609813922</Coordinates>
    </Coordinate-UR>
    <Coordinate-DL>
      <Coordinates datum="WGS84" format="lon,lat">136.8768855819702,35.1660907821191</Coordinates>
    </Coordinate-DL>
    <Coordinate-DR>
      <Coordinates datum="WGS84" format="lon,lat">136.8876144180298,35.1660907821191</Coordinates>
    </Coordinate-DR>
    <Scale zlevel="17" sc="4">23842</Scale>
    <Image>
      <Width>500</Width>
      <Height>500</Height>
    </Image>
    <Scales mode="map">
      <Scale zlevel="1" sc="20">1562498438</Scale>
      <Scale zlevel="2" sc="19">781249219</Scale>
      <Scale zlevel="3" sc="18">390624609</Scale>
      <Scale zlevel="4" sc="17">195312305</Scale>
      <Scale zlevel="5" sc="16">97656152</Scale>
      <Scale zlevel="6" sc="15">48828076</Scale>
      <Scale zlevel="7" sc="14">24414038</Scale>
      <Scale zlevel="8" sc="13">12207019</Scale>
      <Scale zlevel="9" sc="12">6103510</Scale>
      <Scale zlevel="10" sc="11">3051755</Scale>
      <Scale zlevel="11" sc="10">1525877</Scale>
      <Scale zlevel="12" sc="9">762939</Scale>
      <Scale zlevel="13" sc="8">381469</Scale>
      <Scale zlevel="14" sc="7">190735</Scale>
      <Scale zlevel="15" sc="6">95367</Scale>
      <Scale zlevel="16" sc="5">47684</Scale>
      <Scale zlevel="17" sc="4">23842</Scale>
      <Scale zlevel="18" sc="3">11921</Scale>
      <Scale zlevel="19" sc="2">5960</Scale>
      <Scale zlevel="20" sc="1">2980</Scale>
    </Scales>
    <Scales mode="map-mobile">
      <Scale zlevel="1" sc="20">1562498438</Scale>
      <Scale zlevel="2" sc="19">781249219</Scale>
      <Scale zlevel="3" sc="18">390624609</Scale>
      <Scale zlevel="4" sc="17">195312305</Scale>
      <Scale zlevel="5" sc="16">97656152</Scale>
      <Scale zlevel="6" sc="15">48828076</Scale>
      <Scale zlevel="7" sc="14">24414038</Scale>
      <Scale zlevel="8" sc="13">12207019</Scale>
      <Scale zlevel="9" sc="12">6103510</Scale>
      <Scale zlevel="10" sc="11">3051755</Scale>
      <Scale zlevel="11" sc="10">1525877</Scale>
      <Scale zlevel="12" sc="9">762939</Scale>
      <Scale zlevel="13" sc="8">381469</Scale>
      <Scale zlevel="14" sc="7">190735</Scale>
      <Scale zlevel="15" sc="6">95367</Scale>
      <Scale zlevel="16" sc="5">47684</Scale>
      <Scale zlevel="17" sc="4">23842</Scale>
      <Scale zlevel="18" sc="3">11921</Scale>
      <Scale zlevel="19" sc="2">5960</Scale>
      <Scale zlevel="20" sc="1">2980</Scale>
    </Scales>
    <Scales mode="photo">
      <Scale zlevel="1" sc="20">1562498438</Scale>
      <Scale zlevel="2" sc="19">781249219</Scale>
      <Scale zlevel="3" sc="18">390624609</Scale>
      <Scale zlevel="4" sc="17">195312305</Scale>
      <Scale zlevel="5" sc="16">97656152</Scale>
      <Scale zlevel="6" sc="15">48828076</Scale>
      <Scale zlevel="7" sc="14">24414038</Scale>
      <Scale zlevel="8" sc="13">12207019</Scale>
      <Scale zlevel="9" sc="12">6103510</Scale>
      <Scale zlevel="10" sc="11">3051755</Scale>
      <Scale zlevel="11" sc="10">1525877</Scale>
      <Scale zlevel="12" sc="9">762939</Scale>
      <Scale zlevel="13" sc="8">381469</Scale>
      <Scale zlevel="14" sc="7">190735</Scale>
      <Scale zlevel="15" sc="6">95367</Scale>
      <Scale zlevel="16" sc="5">47684</Scale>
      <Scale zlevel="17" sc="4">23842</Scale>
      <Scale zlevel="18" sc="3">11921</Scale>
      <Scale zlevel="19" sc="2">5960</Scale>
      <Scale zlevel="20" sc="1">2980</Scale>
      <Scale zlevel="21" sc="1">1490</Scale>
    </Scales>
    <Scales mode="hybrid">
      <Scale zlevel="1" sc="20">1562498438</Scale>
      <Scale zlevel="2" sc="19">781249219</Scale>
      <Scale zlevel="3" sc="18">390624609</Scale>
      <Scale zlevel="4" sc="17">195312305</Scale>
      <Scale zlevel="5" sc="16">97656152</Scale>
      <Scale zlevel="6" sc="15">48828076</Scale>
      <Scale zlevel="7" sc="14">24414038</Scale>
      <Scale zlevel="8" sc="13">12207019</Scale>
      <Scale zlevel="9" sc="12">6103510</Scale>
      <Scale zlevel="10" sc="11">3051755</Scale>
      <Scale zlevel="11" sc="10">1525877</Scale>
      <Scale zlevel="12" sc="9">762939</Scale>
      <Scale zlevel="13" sc="8">381469</Scale>
      <Scale zlevel="14" sc="7">190735</Scale>
      <Scale zlevel="15" sc="6">95367</Scale>
      <Scale zlevel="16" sc="5">47684</Scale>
      <Scale zlevel="17" sc="4">23842</Scale>
      <Scale zlevel="18" sc="3">11921</Scale>
      <Scale zlevel="19" sc="2">5960</Scale>
      <Scale zlevel="20" sc="1">2980</Scale>
      <Scale zlevel="21" sc="1">1490</Scale>
    </Scales>
    <Scales mode="map-b1">
      <Scale zlevel="19" sc="3">5960</Scale>
      <Scale zlevel="20" sc="2">2980</Scale>
      <Scale zlevel="21" sc="1">1490</Scale>
    </Scales>
    <Scales mode="hd">
      <Scale zlevel="1" sc="20">1562498438</Scale>
      <Scale zlevel="2" sc="19">781249219</Scale>
      <Scale zlevel="3" sc="18">390624609</Scale>
      <Scale zlevel="4" sc="17">195312305</Scale>
      <Scale zlevel="5" sc="16">97656152</Scale>
      <Scale zlevel="6" sc="15">48828076</Scale>
      <Scale zlevel="7" sc="14">24414038</Scale>
      <Scale zlevel="8" sc="13">12207019</Scale>
      <Scale zlevel="9" sc="12">6103510</Scale>
      <Scale zlevel="10" sc="11">3051755</Scale>
      <Scale zlevel="11" sc="10">1525877</Scale>
      <Scale zlevel="12" sc="9">762939</Scale>
      <Scale zlevel="13" sc="8">381469</Scale>
      <Scale zlevel="14" sc="7">190735</Scale>
      <Scale zlevel="15" sc="6">95367</Scale>
      <Scale zlevel="16" sc="5">47684</Scale>
      <Scale zlevel="17" sc="4">23842</Scale>
      <Scale zlevel="18" sc="3">11921</Scale>
      <Scale zlevel="19" sc="2">5960</Scale>
      <Scale zlevel="20" sc="1">2980</Scale>
    </Scales>
    <Scales mode="hd-mobile">
      <Scale zlevel="1" sc="20">1562498438</Scale>
      <Scale zlevel="2" sc="19">781249219</Scale>
      <Scale zlevel="3" sc="18">390624609</Scale>
      <Scale zlevel="4" sc="17">195312305</Scale>
      <Scale zlevel="5" sc="16">97656152</Scale>
      <Scale zlevel="6" sc="15">48828076</Scale>
      <Scale zlevel="7" sc="14">24414038</Scale>
      <Scale zlevel="8" sc="13">12207019</Scale>
      <Scale zlevel="9" sc="12">6103510</Scale>
      <Scale zlevel="10" sc="11">3051755</Scale>
      <Scale zlevel="11" sc="10">1525877</Scale>
      <Scale zlevel="12" sc="9">762939</Scale>
      <Scale zlevel="13" sc="8">381469</Scale>
      <Scale zlevel="14" sc="7">190735</Scale>
      <Scale zlevel="15" sc="6">95367</Scale>
      <Scale zlevel="16" sc="5">47684</Scale>
      <Scale zlevel="17" sc="4">23842</Scale>
      <Scale zlevel="18" sc="3">11921</Scale>
      <Scale zlevel="19" sc="2">5960</Scale>
      <Scale zlevel="20" sc="1">2980</Scale>
    </Scales>
    <Scales mode="loco">
      <Scale zlevel="1" sc="20">1562498438</Scale>
      <Scale zlevel="2" sc="19">781249219</Scale>
      <Scale zlevel="3" sc="18">390624609</Scale>
      <Scale zlevel="4" sc="17">195312305</Scale>
      <Scale zlevel="5" sc="16">97656152</Scale>
      <Scale zlevel="6" sc="15">48828076</Scale>
      <Scale zlevel="7" sc="14">24414038</Scale>
      <Scale zlevel="8" sc="13">12207019</Scale>
      <Scale zlevel="9" sc="12">6103510</Scale>
      <Scale zlevel="10" sc="11">3051755</Scale>
      <Scale zlevel="11" sc="10">1525877</Scale>
      <Scale zlevel="12" sc="9">762939</Scale>
      <Scale zlevel="13" sc="8">381469</Scale>
      <Scale zlevel="14" sc="7">190735</Scale>
      <Scale zlevel="15" sc="6">95367</Scale>
      <Scale zlevel="16" sc="5">47684</Scale>
      <Scale zlevel="17" sc="4">23842</Scale>
      <Scale zlevel="18" sc="3">11921</Scale>
      <Scale zlevel="19" sc="2">5960</Scale>
      <Scale zlevel="20" sc="1">2980</Scale>
    </Scales>
    <Positions/>
    <Copyright>(C)Yahoo Japan,(C)ZENRIN</Copyright>
  </Result>
</ResultSet>

Reference material

-YOLP \ (Map ): Yahoo ! Static Map API -Yahoo ! Developer Network -[urllib \ .request ---extensible library for opening URLs — Python 3 \ .8 \ .5 documentation](https://docs.python.org/ja/3.8/library/urllib .request.html) -[xml \ .dom \ .minidom ---Minimal DOM implementation — Python 3 \ .8 \ .5 documentation](https://docs.python.org/ja/3.8/library/xml .dom.minidom.html)

Recommended Posts

YOLP Get map information XML file with Yahoo! Static Map API
Get information with zabbix api
Get video file information with ffmpeg-python
[Python] Get Python package information with PyPI API
Get coincheck virtual currency information with API ♪
[Python] Get user information and article information with Qiita API
YOLP: Extract latitude and longitude with Yahoo! Geocoder API.
Get Alembic information with Python
Get Japanese stock price information from yahoo finance with pandas
Get ranking with Rakuten API
Python: Extract file information from shared drive with Google Drive API
Get weather information using Yahoo! Open Local Platform (YOLP) and let Raspberry Pi talk with AquesTalkPi
Get reviews with python googlemap api
Serve static files with X-Send File
[python] Read information with Redmine API
Get weather information with Python & scraping
Introducing Google Map API with rails
[Yahoo! Weather Replacement Version] How to get weather information with LINE Notify + Python
I tried to get the movie information of TMDb API with Python
Collecting information from Twitter with Python (Twitter API)
Get property information by scraping with python
Map rent information on a map with python
Get BITCOIN LTP information with Raspberry PI
Get holidays with the Google Calendar API
Ask the bot to tell you the weather (precipitation information) using the weather information API (YOLP) provided by Yahoo ~ slack bot development with python ④ ~