mirrorworld.baidu: Baidu Panorama¶
Support for Baidu Panorama of Baidu Maps, covering many cities in the PRC.
find_panorama accepts WGS84, GCJ-02, BD09, or BD09MC. The positions of retrieved panoramas
are given as WGS84, GJC-02, and BD09MC.
Finding panoramas¶
- find_panorama(coord1, coord2, crs=Crs.WGS84, session=None)[source]¶
Searches for a panorama near the given point.
- Parameters:
- Returns:
A BaiduPanorama object if a panorama was found, or None.
- Return type:
BaiduPanorama | None
Usage sample:
from mirrorworld 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)[source]¶
- Parameters:
- Return type:
BaiduPanorama | None
Usage sample:
from mirrorworld 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)[source]¶
Fetches metadata of a specific panorama.
- Parameters:
panoid (str) – The panorama ID.
session (Session) – (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 mirrorworld 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)[source]¶
- Parameters:
panoid (str)
session (ClientSession)
- Return type:
BaiduPanorama | None
Usage sample:
from mirrorworld 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)[source]¶
Fetches metadata of a set of interior/tripod (
inter) panoramas.
- Parameters:
iid (str) – The
interID.session (Session) – (optional) A requests session.
- Returns:
The metadata.
- Return type:
InteriorMetadata | None
Usage sample:
from mirrorworld 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)[source]¶
- Parameters:
iid (str)
session (ClientSession)
- Return type:
InteriorMetadata | None
Usage sample:
from mirrorworld 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)[source]¶
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)[source]¶
- Parameters:
pano (BaiduPanorama)
session (ClientSession)
zoom (int)
- Return type:
Image
- download_panorama(pano, path, zoom=3, pil_args=None)[source]¶
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) – (optional) Additional arguments for PIL’s Image.save method, e.g.
{"quality":100}. Defaults to{}.- Return type:
None
Usage sample:
from mirrorworld 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)[source]¶
- Parameters:
pano (BaiduPanorama)
path (str)
session (ClientSession)
zoom (int)
pil_args (dict)
- Return type:
None
Usage sample:
from mirrorworld 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 Crs(*values)[source]¶
Coordinate systems supported by
find_panorama.
- WGS84 = 0¶
- BD09 = 1¶
- BD09MC = 2¶
- GCJ02 = 3¶
- class BaiduPanorama(id, x, y, elevation=None, lat=None, lon=None, gcj02_lat=None, gcj02_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)[source]¶
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)
gcj02_lat (float)
gcj02_lon (float)
heading (float)
pitch (float)
roll (float)
neighbors (List[BaiduPanorama])
historical (List[BaiduPanorama])
date (datetime)
height (float)
street_name (str)
creator (User | None)
interior (PanoInteriorMetadata | None)
- 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.
- neighbors: List[BaiduPanorama] = None¶
A list of nearby 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.
- height: float = None¶
Camera height above ground (not sea level) in meters. May be 0 for user-provided panoramas.
- 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.
- 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.
- property tile_size: Size¶
Baidu panoramas are broken up into a grid of tiles. This returns the size of one tile.
- image_sizes: List[Size] = None¶
The image sizes in which this panorama can be downloaded, from lowest to highest. Indices correspond to zoom levels.
- permalink(heading=0.0, pitch=0.0, radians=False)[source]¶
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:
- class Floor(number, name, start_panoid, panos)[source]¶
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])
- panos: List[InteriorPoint]¶
Panoramas on this floor.
- class InteriorMetadata(id, name, uid, x, y, lat, lon, floors, default_floor, exit_pano)[source]¶
Metadata of a set of interior/tripod (
inter) panoramas as returned by the API call made byget_inter_metadata.
- Parameters:
- exit_pano: BaiduPanorama | None¶
The panorama which is loaded upon exiting the building.
- class InteriorPoint(name, floor, creator, catalog_label, pano)[source]¶
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)
- pano: BaiduPanorama¶
The panorama metadata.
- class PanoInteriorMetadata(id, name, exit_panoid, uid, panos, x=None, y=None, lat=None, lon=None)[source]¶
Metadata of a set of interior/tripod (
inter) panoramas as returned by the API call made byfind_panorama_by_id.
- Parameters:
- panos: List[PanoInteriorPoint]¶
All panoramas of this location.
- class PanoInteriorPoint(id, name, floor, date)[source]¶
Metadata of an interior/tripod (
inter) panorama as returned by the API call made byfind_panorama_by_id.
- class Provider(*values)[source]¶
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)
- VRWAY = 3¶
全瑞景 (VRWay Communication, vrlooking.com)
- TAAGOO = 4¶
互动世界 (taagoo.com)
- ZHDGPS = 5¶
都市圈 (Guangzhou Zhonghaida Satellite Navigation Technology, zhdgps.com)
- PEACEMAP = 6¶
天下图 (Tianxiatu, peacemap.com.cn)
- TMIC = 7¶
时间机器 (Time Machine Cultural Communication, chinatmic.com)
- SUPER720 = 11¶
方位科技有限公司 (Super720, super720.com)
- PANORAMA_NETWORK = 12¶
中国全景网 (China Panorama Network, vra.cn)
- TIANYA = 13¶
海南丽声 (Hainan Lisheng, tianya.tv)