streetlevel.baidu: Baidu Panorama
Support for Baidu Panorama of Baidu Maps, covering many cities in the PRC.
find_panorama accepts WGS84 in addition to BD09. The positions of retrieved panoramas
are given as both WGS84 and BD09MC.
Finding panoramas
- find_panorama(coord1, coord2, crs=Crs.WGS84, session=None)
Searches for a panorama near the given point.
- Parameters:
coord1 (float) – Latitude or x coordinate of the point.
coord2 (float) – Longitude or y coordinate of the point.
crs (Crs) – (optional) The coordinate system of the given coordinates. Defaults to WGS84.
session (Session | None) – (optional) A requests session.
- Returns:
A BaiduPanorama object if a panorama was found, or None.
- Return type:
BaiduPanorama | None
Usage sample:
from streetlevel import baidu pano = baidu.find_panorama(22.2937592, 114.1692527) print(pano.id) print(pano.lat, pano.lon) print(pano.date)
- async find_panorama_async(coord1, coord2, session, crs=Crs.WGS84)
- Parameters:
coord1 (float)
coord2 (float)
session (ClientSession)
crs (Crs)
- Return type:
BaiduPanorama | None
Usage sample:
from streetlevel import baidu from aiohttp import ClientSession async with ClientSession() as session: pano = await baidu.find_panorama_async(22.2937592, 114.1692527, session) print(pano.id) print(pano.lat, pano.lon) print(pano.heading)
- find_panorama_by_id(panoid, session=None)
Fetches metadata of a specific panorama.
- Parameters:
panoid (str) – The panorama ID.
session (Session | None) – (optional) A requests session.
- Returns:
A BaiduPanorama object if a panorama with this ID was found, or None.
- Return type:
BaiduPanorama | None
Usage sample:
from streetlevel import baidu pano = baidu.find_panorama_by_id("09024200121707301421572809B") print(pano.lat, pano.lon) print(pano.date)
- async find_panorama_by_id_async(panoid, session)
- Parameters:
panoid (str)
session (ClientSession)
- Return type:
BaiduPanorama | None
Usage sample:
from streetlevel import baidu from aiohttp import ClientSession async with ClientSession() as session: pano = await baidu.find_panorama_by_id_async("09024200121707301421572809B", session) print(pano.lat, pano.lon) print(pano.date)
- get_inter_metadata(iid, session=None)
Fetches metadata of a set of interior/tripod (
inter) panoramas.
- Parameters:
iid (str) – The
interID.session (Session | None) – (optional) A requests session.
- Returns:
The metadata.
- Return type:
InteriorMetadata | None
Usage sample:
from streetlevel import baidu inter = baidu.get_inter_metadata("b60ec15c48587562843304bc") print(inter.name) print(inter.lat, inter.lon) for floor in inter.floors: print(floor.number, [p.id for p in floor.panos])
- async get_inter_metadata_async(iid, session)
- Parameters:
iid (str)
session (ClientSession)
- Return type:
InteriorMetadata | None
Usage sample:
from streetlevel import baidu async with ClientSession() as session: inter = await baidu.get_inter_metadata_async("b60ec15c48587562843304bc", session) print(inter.name) print(inter.lat, inter.lon) for floor in inter.floors: print(floor.number, [p.id for p in floor.panos])
Downloading panoramas
- get_panorama(pano, zoom=3)
Downloads a panorama and returns it as PIL image.
- Parameters:
pano (BaiduPanorama) – The panorama to download.
zoom (int) – (optional) Image size; 0 is lowest, 3 is highest. The dimensions of a zoom level of a specific panorama depend on the camera used. If the requested zoom level does not exist, the highest available level will be downloaded. Defaults to 3.
- Returns:
A PIL image containing the panorama.
- Return type:
Image
- async get_panorama_async(pano, session, zoom=3)
- Parameters:
pano (BaiduPanorama)
session (ClientSession)
zoom (int)
- Return type:
Image
- download_panorama(pano, path, zoom=3, pil_args=None)
Downloads a panorama to a file. If the chosen format is JPEG, Exif and XMP GPano metadata are included.
(
PosePitchDegreesandPoseRollDegreesare not set because I’ve been unable to work out the order of operations. Rotations are my arch nemesis and there is only so much time I’m willing to waste on this.)
- Parameters:
pano (BaiduPanorama) – The panorama to download.
path (str) – Output path.
zoom (int) – (optional) Image size; 0 is lowest, 3 is highest. The dimensions of a zoom level of a specific panorama depend on the camera used. If the requested zoom level does not exist, the highest available level will be downloaded. Defaults to 3.
pil_args (dict | None) – (optional) Additional arguments for PIL’s Image.save method, e.g.
{"quality":100}. Defaults to{}.- Return type:
None
Usage sample:
from streetlevel import baidu pano = baidu.find_panorama_by_id("09024200121707301421572809B") baidu.download_panorama(pano, f"{pano.id}.jpg")
- async download_panorama_async(pano, path, session, zoom=3, pil_args=None)
- Parameters:
pano (BaiduPanorama)
path (str)
session (ClientSession)
zoom (int)
pil_args (dict | None)
- Return type:
None
Usage sample:
from streetlevel import baidu from aiohttp import ClientSession async with ClientSession() as session: pano = await baidu.find_panorama_by_id_async("09024200121707301421572809B", session) await baidu.download_panorama_async(pano, f"{pano.id}.jpg", session)
Data classes and Enums
- class BaiduPanorama(id, x, y, elevation=None, lat=None, lon=None, heading=None, pitch=None, roll=None, neighbors=None, historical=None, date=None, height=None, street_name=None, provider=None, creator=None, interior=None, image_sizes=None)
Metadata of a Baidu Maps panorama.
ID and capture date are always present. The availability of other metadata depends on which function was called and what was returned by the API.
- Parameters:
id (str)
x (float)
y (float)
elevation (float)
lat (float)
lon (float)
heading (float)
pitch (float)
roll (float)
neighbors (List[BaiduPanorama])
historical (List[BaiduPanorama])
date (datetime)
height (float)
street_name (str)
provider (Provider | int)
creator (User | None)
interior (PanoInteriorMetadata | None)
image_sizes (List[Size])
- date: datetime = None
The capture date and time in UTC+8.
- elevation: float = None
Elevation at the capture location in meters. May be 0 for interiors/tripods or user-provided footage.
- heading: float = None
Heading of the car in radians, where 0° is north, 90° is east, 180° is south, and 270° is west.
- height: float = None
Camera height above ground (not sea level) in meters. May be 0 for user-provided panoramas.
- historical: List[BaiduPanorama] = None
A list of panoramas with a different date at the same location. Note that ID, capture date and provider are the only set fields.
- id: str
The panorama ID.
- image_sizes: List[Size] = None
The image sizes in which this panorama can be downloaded, from lowest to highest. Indices correspond to zoom levels.
- interior: PanoInteriorMetadata | None = None
If this panorama is part of a set of interior/tripod (
inter) panoramas, this object contains metadata of the PoI and all other panoramas in the set.
- lat: float = None
WGS84 latitude of the panorama’s location.
- lon: float = None
WGS84 longitude of the panorama’s location.
- neighbors: List[BaiduPanorama] = None
A list of nearby panoramas.
- permalink(heading=0.0, pitch=0.0, radians=False)
Creates a permalink to this panorama.
- Parameters:
heading (float) – (optional) Initial heading of the viewport. Defaults to 0°.
pitch (float) – (optional) Initial pitch of the viewport. Defaults to 0°.
radians (bool) – (optional) Whether angles are in radians. Defaults to False.
self (BaiduPanorama)
- Returns:
A Baidu Maps URL pointing to this panorama.
- Return type:
str
- pitch: float = None
Pitch offset for upright correction of the panorama, in radians.
- provider: Provider | int = None
The company or organisation which captured the panorama. If the enum value returned by the API is known, this field is of type
Provider. Otherwise, it contains the raw integer.
- roll: float = None
Roll offset for upright correction of the panorama, in radians.
- street_name: str = None
The street name.
- property tile_size: Size
Baidu panoramas are broken up into a grid of tiles. This returns the size of one tile.
- x: float
BD09MC X coordinate of the panorama’s location.
- y: float
BD09MC Y coordinate of the panorama’s location.
- class Floor(number, name, start_panoid, panos)
One floor of a set of interior/tripod (
inter) coverage as returned by the API call made byget_inter_metadata.
- Parameters:
number (int)
name (str)
start_panoid (str)
panos (List[InteriorPoint])
- name: str
The name of the floor.
- number: int
The floor number.
- panos: List[InteriorPoint]
Panoramas on this floor.
- start_panoid: str
The ID of the initial pano to display for this floor.
- class InteriorMetadata(id, name, uid, x, y, lat, lon, floors, default_floor, exit_pano)
Metadata of a set of interior/tripod (
inter) panoramas as returned by the API call made byget_inter_metadata.
- Parameters:
id (str)
name (str)
uid (str)
x (float)
y (float)
lat (float)
lon (float)
floors (List[Floor])
default_floor (int)
exit_pano (BaiduPanorama | None)
- default_floor: int
The floor which is shown first.
- exit_pano: BaiduPanorama | None
The panorama which is loaded upon exiting the building.
- id: str
The IID identifying the set of panoramas at this PoI.
- lat: float
WGS84 latitude of the PoI’s location.
- lon: float
WGS84 longitude of the PoI’s location.
- name: str
The name of the PoI.
- uid: str
The UID of the PoI.
- x: float
BD09MC X coordinate of the PoI’s location.
- y: float
BD09MC Y coordinate of the PoI’s location.
- class InteriorPoint(name, floor, creator, catalog_label, pano)
One panorma of a set of interior/tripod (
inter) coverage as returned by the API call made byget_inter_metadata.
- Parameters:
name (str)
floor (int)
creator (str | None)
catalog_label (str)
pano (BaiduPanorama)
- catalog_label: str
The room type.
- creator: str | None
The name of the uploader if this is a user-provided panorama.
- floor: int
The floor on which the panorama is located.
- name: str
The name of the panorama, typically describing its location.
- pano: BaiduPanorama
The panorama metadata.
- class PanoInteriorMetadata(id, name, exit_panoid, uid, panos, x=None, y=None, lat=None, lon=None)
Metadata of a set of interior/tripod (
inter) panoramas as returned by the API call made byfind_panorama_by_id.
- Parameters:
id (str)
name (str)
exit_panoid (str)
uid (str)
panos (List[PanoInteriorPoint])
x (float | None)
y (float | None)
lat (float | None)
lon (float | None)
- exit_panoid: str
The ID of a regular panorama which is loaded upon exiting the building.
- id: str
The IID identifying the set of panoramas at this PoI.
- lat: float | None = None
WGS84 latitude of the PoI’s location, if available.
- lon: float | None = None
WGS84 longitude of the PoI’s location, if available.
- name: str
The name of the PoI.
- panos: List[PanoInteriorPoint]
All panoramas of this location.
- uid: str
The UID of the PoI.
- x: float | None = None
BD09MC X coordinate of the PoI’s location, if available.
- y: float | None = None
BD09MC Y coordinate of the PoI’s location, if available.
- class PanoInteriorPoint(id, name, floor, date)
Metadata of an interior/tripod (
inter) panorama as returned by the API call made byfind_panorama_by_id.
- Parameters:
id (str)
name (str)
floor (int)
date (datetime)
- date: datetime
The capture date and time in UTC+8.
- floor: int
The floor on which the panorama is located.
- id: str
The panorama ID.
- name: str
The name of the panorama, typically describing its location.
- class Provider(value)
The provider of a Baidu Maps panorama.
- BAIDU = 0
The panorama was captured by Baidu or a user of Baidu.
- CITY8 = 1
城市吧 (City8, city8.com)
- LIDE_SPACE = 2
立得空间 (LIDE Space)
- PANORAMA_NETWORK = 12
中国全景网 (China Panorama Network, vra.cn)
- PEACEMAP = 6
天下图 (Tianxiatu, peacemap.com.cn)
- SUPER720 = 11
方位科技有限公司 (Super720, super720.com)
- TAAGOO = 4
互动世界 (taagoo.com)
- TIANYA = 13
海南丽声 (Hainan Lisheng, tianya.tv)
- TMIC = 7
时间机器 (Time Machine Cultural Communication, chinatmic.com)
- VRWAY = 3
全瑞景 (VRWay Communication, vrlooking.com)
- ZHDGPS = 5
都市圈 (Guangzhou Zhonghaida Satellite Navigation Technology, zhdgps.com)
Miscellaneous
- build_permalink(id, heading=0.0, pitch=0.0, radians=True)
Creates a permalink to the given panorama.
- Parameters:
id (str) – The pano ID.
heading (float) – (optional) Initial heading of the viewport. Defaults to 0°.
pitch (float) – (optional) Initial pitch of the viewport. Defaults to 0°.
radians (bool) – (optional) Whether angles are in radians. Defaults to False.
- Returns:
A Baidu Maps URL which will open the given panorama.
- Return type:
str