pycitydata.map.map¶
Module Contents¶
Classes¶
地图API Map API |
Data¶
API¶
- pycitydata.map.map.__all__¶
[‘Map’]
- class pycitydata.map.map.Map(mongo_uri: Optional[str] = None, mongo_db: Optional[str] = None, mongo_coll: Optional[str] = None, cache_dir: Optional[str] = None, cache_path: Optional[str] = None, pb_path: Optional[str] = None)¶
地图API Map API
Initialization
Args:
mongo_uri (Optional[str]): mongo数据库的uri。MongoDB uri.
mongo_db (Optional[str]): 数据库名。Database name.
mongo_coll (Optional[str]): 集合名。Collection name.
cache_dir (Optional[str]): 缓存目录, Defaults to None. Cache directory, Defaults to None.
cache_path (Optional[str]): 缓存文件路径, Defaults to None. Cache file path, Defaults to None.
pb_path (Optional[str]): pb文件路径, Defaults to None. pb file path, Defaults to None.
Users can init Map with either mongo_uri, mongo_db, mongo_coll or pb_path.
- header: dict¶
None
地图元数据,包含如下属性: Map metadata, including the following attributes:
name (string): 城市道路名称,供标识数据集合的语义。Map name, to identify the semantics of data collections.
date (string): 城市道路数据的创建时间。Map data creation time.
north (float): 道路数据的北边界坐标。The coordinate of the northern boundary of the Map data.
south (float): 道路数据的南边界坐标。The coordinate of the southern boundary of the Map data.
east (float): 道路数据的东边界坐标。The coordinate of the eastern boundary of the Map data.
west (float): 道路数据的西边界坐标。The coordinate of the western boundary of the Map data.
projection (string): PROJ.4 投影字符串,用以支持xy坐标到其他坐标系的转换。PROJ.4 projection string to support the conversion of xy coordinates to other coordinate systems.
- juncs: Dict[int, dict]¶
None
地图中的路口集合(junction),字典的值包含如下属性: The intersection collection (junction) in the map, the value of the dictionary contains the following attributes:
id (int): 路口编号。Junction ID.
lane_ids (list[int]): 属于该路口的所有车道和人行道编号。IDs of all driving and pedestrian lanes belonging to this junction.
center (Dict[str, float]): 路口的大致中心点。The approximate center of the junction. example: {‘x’: 5983.14, ‘y’: 1807.73}
- lanes: Dict[int, dict]¶
None
地图中的车道集合(lane),字典的值包含如下属性: The lane collection (lane) in the map. The value of the dictionary contains the following attributes:
id (int): 车道编号。Lane ID.
type (int): 车道类型 (1:行车|2:步行)。Lane type (1: Driving | 2: Pedestrian).
turn (int): 转向类型 (1:直行|2:左转|3: 右转|4: 掉头)。Turn type (1: straight | 2: left | 3: right | 4: around).
max_speed (float): 最大速度限制(单位: m/s)。Maximum speed limit (m/s).
length (float): 车道中心线的长度(单位: m)。Length of lane centerline (m).
width (float): 车道的宽度(单位: m)。Lane width.
center_line (list[XYPosition]): 车道中心线的形状。Lane centerline shape.
predecessors (list[LaneConnection]): 前驱车道编号和连接类型。对于路口内的车道,最多只有一个前驱车道。对于 LANE_TYPE_DRIVING,连接类型必须是 LANE_CONNECTION_TYPE_TAIL。对于 LANE_TYPE_WALKING,两种连接类型都可能。ID and connection type of predecessor lanes. For lanes within a junction, there is at most one predecessor lane. For LANE_TYPE_DRIVING, the connection type must be LANE_CONNECTION_TYPE_TAIL. For LANE_TYPE_WALKING, both connection types are possible.
successors (list[LaneConnection]): 后继车道编号和连接类型。对于路口内的车道,最多只有一个后继车道。对于 LANE_TYPE_DRIVING,连接类型必须是 LANE_CONNECTION_TYPE_HEAD。对于 LANE_TYPE_WALKING,两种连接类型都可能。ID and connection type of successor lanes. For lanes within a junction, there is at most one successor lane. For LANE_TYPE_DRIVING, the connection type must be LANE_CONNECTION_TYPE_HEAD. For LANE_TYPE_WALKING, both connection types are possible.
left_lane_ids (list[int]): 左侧相邻车道的车道编号,从最近到最远排列。Lane IDs of the adjacent lanes on the left, arranged from closest to furthest.
right_lane_ids (list[int]): 右侧相邻车道的车道编号,从最近到最远排列。Lane IDs of the adjacent lanes on the right, arranged from closest to furthest.
parent_id (int): 车道所属的道路/路口编号。The road/intersection ID to which the lane belongs.
aoi_ids (list[int]): 与车道连接的 AOI 编号。AOI IDs connected to the lane.
shapely_xy (shapely.geometry.LineString): 车道中心线的形状(xy坐标系)。Shape of lane centerline (in xy coordinates).
shapely_lnglat (shapely.geometry.LineString): 车道中心线的形状(经纬度坐标系)Shape of lane centerline (in latitude and longitude).
- roads: Dict[int, dict]¶
None
地图中的道路集合(road),字典的值包含如下属性: The road collection (road) in the map, the value of the dictionary contains the following attributes:
id (int): 道路编号。Road ID.
lane_ids (list[int]): 道路所包含的车道和人行道编号。Driving and pedestrian lane IDs that the road contains.
- aois: Dict[int, dict]¶
None
地图中的AOI集合(aoi),字典的值包含如下属性: AOI collection (aoi) in the map, the value of the dictionary contains the following attributes:
id (int): AOI编号。AOI ID.
positions (list[XYPosition]): 多边形空间范围。Shape of polygon.
area (float): 面积(单位: m2)。Area.
driving_positions (list[LanePosition]): 和道路网中行车道的连接点。Connection points to driving lanes.
walking_positions (list[LanePosition]): 和道路网中人行道的连接点。Connection points to pedestrian lanes.
driving_gates (list[XYPosition]): 和道路网中行车道的连接点对应的AOI边界上的位置。Position on the AOI boundary corresponding to the connection point to driving lanes.
walking_gates (list[XYPosition]): 和道路网中人行道的连接点对应的AOI边界上的位置。Position on the AOI boundary corresponding to the connection point to pedestrian lanes.
urban_land_use (Optional[str]): 城市建设用地分类,参照执行标准GB 50137-2011(https://www.planning.org.cn/law/uploads/2013/1383993139.pdf) Urban Land use type, refer to the national standard GB 50137-2011.
poi_ids (list[int]): 包含的POI列表。Contained POI IDs.
shapely_xy (shapely.geometry.Polygon): AOI的形状(xy坐标系)。Shape of polygon (in xy coordinates).
shapely_lnglat (shapely.geometry.Polygon): AOI的形状(经纬度坐标系)。Shape of polygon (in latitude and longitude).
- pois: Dict[int, dict]¶
None
地图中的POI集合(poi),字典的值包含如下属性: POI collection (poi) in the map, the value of the dictionary contains the following attributes:
id (int): POI编号。POI ID.
name (string): POI名称。POI name.
category (string): POI类别编码。POI category code.
position (XYPosition): POI位置。POI position.
aoi_id (int): POI所属的AOI编号。AOI ID to which the POI belongs.
- projector: pyproj.Proj¶
None
采用PROJ.4投影字符串创建的转换器,用以支持xy坐标到WGS84坐标系的转换 Converter created using PROJ.4 projection string to support conversion of xy coordinates to WGS84 coordinate system
- _parse_map(m: List[Any]) Dict[str, Any]¶
- _download_map_with_cache(uri: str, db: str, coll: str, cache_dir: Optional[str]) Dict[str, Any]¶
- _build_geo_index()¶
- _get_lane_s(position: pycityproto.city.geo.v2.geo_pb2.Position, lane_id: int) float¶
解算position对应的在lane_id上的s值 Solve the s value corresponding to position on lane_id
- _get_driving_geo(road_id: int)¶
根据道路ID获取几何信息对应的Lane ID和Lane的几何信息 Obtain the Lane ID and Lane’s geometric information corresponding to the geometric information based on the road ID.
- _get_walking_geo(segment: pycityproto.city.routing.v2.routing_pb2.WalkingRouteSegment)¶
根据步行路段(导航结果)获取几何信息对应的Lane ID和Lane的几何信息 Obtain the Lane ID and Lane’s geometric information corresponding to the geometric information based on the walking path (navigation result).
- lnglat2xy(lng: float, lat: float) Tuple[float, float]¶
经纬度转xy坐标 Convert latitude and longitude to xy coordinates
Args:
lng (float): 经度。longitude.
lat (float): 纬度。latitude.
Returns:
Tuple[float, float]: xy坐标。xy coordinates.
- xy2lnglat(x: float, y: float) Tuple[float, float]¶
xy坐标转经纬度 xy coordinates to longitude and latitude
Args:
x (float): x坐标。x coordinate.
y (float): y坐标。y coordinate.
Returns:
Tuple[float, float]: 经纬度。Longitude and latitude.
- position2xy(position: Union[pycityproto.city.geo.v2.geo_pb2.Position, Dict[str, Any]]) Tuple[float, float]¶
将position转换为xy坐标 Convert position to xy coordinates
- get_header()¶
查询header query header
- get_aoi(id: int, include_unused: bool = False) Optional[Any]¶
查询AOI query AOI
Args:
id (int): AOI id
include_unused (bool, optional): 是否包含未使用或无效的AOI属性. Defaults to False. Whether contains unused or invalid AOI attributes. Defaults to False.
Returns:
Optional[Any]: AOI(经过复制后的dict)。AOI (copied dict).
- get_poi(id: int, include_unused: bool = False) Optional[Any]¶
查询poi query poi
Args:
id (int): poi id
include_unused (bool, optional): 是否包含未使用或无效的poi属性. Defaults to False. Whether contains unused or invalid POI attributes. Defaults to False.
Returns:
Optional[Any]: poi(经过复制后的dict)。POI (copied dict).
- get_lane(id: int, include_unused: bool = False) Optional[Any]¶
查询lane query lane
Args:
id (int): lane id
include_unused (bool, optional): 是否包含未使用或无效的lane属性. Defaults to False. Whether contains unused or invalid lane attributes. Defaults to False.
Returns:
Optional[Any]: lane(经过复制后的dict)。Lane (copied dict).
- get_road(id: int, include_unused: bool = False) Optional[Any]¶
查询road query road
Args:
id (int): road id
include_unused (bool, optional): 是否包含未使用或无效的road属性. Defaults to False. Whether contains unused or invalid road attributes. Defaults to False.
Returns:
Optional[Any]: road(经过复制后的dict)。Road (copied dict).
- get_junction(id: int, include_unused: bool = False) Optional[Any]¶
查询junction query junction
Args:
id (int): junction id
include_unused (bool, optional): 是否包含未使用或无效的junction属性. Defaults to False. Whether contains unused or invalid junction attributes. Defaults to False.
Returns:
Optional[Any]: junction(经过复制后的dict)。Junction (copied dict).
- export_aoi_center_as_geojson(id: int, properties: Union[Dict[str, Any], Literal[auto]] = 'auto') dict¶
导出aoi中心点为geojson Export aoi center point as geojson
Args:
id (int): aoi id
properties (Dict[str, Any] | str, optional): geojson的properties, 设置为”auto”时包含aoi类别与所含的poi列表. Defaults to {}. Geojson’s properties, when set to “auto”, the properties include aoi category and the list of contained poi. Defaults to {}.
Returns:
dict: geojson格式的dict。dict in geojson format.
- export_aoi_as_geojson(id: int, properties: Union[Dict[str, Any], Literal[auto]] = 'auto') dict¶
导出aoi为geojson Export aoi as geojson
Args:
id (int): aoi id
properties (Dict[str, Any] | str, optional): geojson的properties, 设置为”auto”时包含aoi类别与所含的poi列表. Defaults to {}. Geojson’s properties, when set to “auto”, the properties include aoi category and the list of contained poi. Defaults to {}.
Returns:
dict: geojson格式的dict。dict in geojson format.
- export_poi_as_geojson(id: int, properties: Union[Dict[str, Any], Literal[auto]] = 'auto') dict¶
导出poi为geojson Export poi as geojson
Args:
id (int): poi id
properties (Dict[str, Any] | str, optional): geojson的properties, 设置为”auto”时包含poi类别、名称. Defaults to “auto”. Geojson’s properties, when set to “auto”, the properties include poi category and name. Defaults to “auto”.
Returns:
dict: geojson格式的dict. dict in geojson format.
- export_lane_as_geojson(id: int, properties: Union[Dict[str, Any], Literal[auto]] = 'auto') dict¶
导出lane为geojson geojson的properties. Defaults to {}.
Args:
id (int): lane id
properties (Dict[str, Any], optional): geojson的properties. Defaults to “auto”(含lane的类别、转向类别、父对象ID、最大车速). geojson properties. Defaults to {}. (including lane type, turn type, parent object ID, maximum vehicle speed).
Returns:
dict: geojson格式的dict。dict in geojson format.
- export_road_as_geojson(id: int, properties: Dict[str, Any] = {}) dict¶
导出road为geojson Export road as geojson
Args:
id (int): road id
properties (Dict[str, Any], optional): geojson的properties. Defaults to {}. geojson properties. Defaults to {}.
Returns:
dict: geojson格式的dict。dict in geojson format.
- _route_to_xys(route_req: pycityproto.city.routing.v2.routing_service_pb2.GetRouteRequest, route_res: pycityproto.city.routing.v2.routing_service_pb2.GetRouteResponse) numpy.ndarray¶
- export_route_as_geojson(route_req: Union[pycityproto.city.routing.v2.routing_service_pb2.GetRouteRequest, dict], route_res: Union[pycityproto.city.routing.v2.routing_service_pb2.GetRouteResponse, dict], properties: dict = {}) dict¶
导出route为geojson Export route as geojson
Args:
route_req (routing_service.GetRouteRequest): 请求导航的输入参数。Input parameters for request navigation.
route_res (routing_service.GetRouteResponse): 请求导航的输出结果。Output results for request navigation.
properties (dict, optional): geojson的properties. Defaults to {}. geojson properties. Defaults to {}.
Returns:
dict: geojson格式的dict。dict in geojson format.
- estimate_route_time(route_req: Union[pycityproto.city.routing.v2.routing_service_pb2.GetRouteRequest, dict], route_res: Union[pycityproto.city.routing.v2.routing_service_pb2.GetRouteResponse, dict]) float¶
估算导航路线的时间 Estimate navigation route time
Args:
route_req (routing_service.GetRouteRequest): 请求导航的输入参数。Input parameters for request navigation.
route_res (routing_service.GetRouteResponse): 请求导航的输出结果。Output results for request navigation.
walking_speed (float, optional): 步行速度(单位:m/s). Defaults to 1.1. Walking speed (unit: m/s). Defaults to 1.1.
Returns:
float: 估算的时间(单位:s)。Estimated time (unit: s).
- query_pois(center: Union[Tuple[float, float], shapely.geometry.Point], radius: Optional[float] = None, category_prefix: Optional[str] = None, limit: Optional[int] = None, return_distance: bool = True) Union[List[Tuple[Any, float]], List[Any]]¶
查询center点指定半径内类别满足前缀的poi(按距离排序)。Query the POIs whose categories satisfy the prefix within the specified radius of the center point (sorted by distance).
Args:
center (x, y): 中心点(xy坐标系)。Center point (xy coordinate system).
radius (float, optional): 半径(单位:m)。如果不提供则返回所有的poi。Radius (unit: m).If not provided, all pois within the map will be returned.
category_prefix (str, optional): 类别前缀,如实际类别为100000,那么匹配的前缀可以为10、1000等。Category prefix, if the actual category is 100000, then the matching prefix can be 10, 1000, etc.
limit (int, optional): 最多返回的poi数量,按距离排序,近的优先(默认None). The maximum number of POIs returned, sorted by distance, closest ones first (default to None).
return_distance (bool): 是否返回距离。Return the distance or not.
Returns:
Union[List[Tuple[Any, float]],List[Any]]: poi列表,每个元素为(poi, 距离)或者poi。poi list, each element is (poi, distance) or poi.
- query_aois(center: Union[Tuple[float, float], shapely.geometry.Point], radius: float, urban_land_uses: Optional[List[str]] = None, limit: Optional[int] = None) List[Tuple[Any, float]]¶
查询center点指定半径内城市用地满足条件的aoi(按距离排序)。Query the AOIs whose urban land use within the specified radius of the center point meets the conditions (sorted by distance).
Args:
center (x, y): 中心点(xy坐标系)。Center point (xy coordinate system).
radius (float): 半径(单位:m)。Radius (unit: m).
urban_land_uses (List[str], optional): 城市用地分类列表,参照执行标准GB 50137-2011(https://www.planning.org.cn/law/uploads/2013/1383993139.pdf). Urban land use classification list, refer to the national standard GB 50137-2011.
limit (int, optional): 最多返回的aoi数量,按距离排序,近的优先(默认None). The maximum number of AOIs returned, sorted by distance, closest ones first (default to None).
Returns:
List[Tuple[Any, float]]: aoi列表,每个元素为(aoi, 距离)。aoi list, each element is (aoi, distance).
- query_lane(xy: Union[Tuple[float, float], shapely.geometry.Point], radius: float, lane_type: int = 1)¶
查询xy点指定半径内的lane和s坐标 Query the lane and s coordinates within the specified radius of the xy point.
Args:
xy (x, y): 中心点(xy坐标系)。Center point (xy coordinate system).
radius (float): 半径(单位:m),超出半径则返回空列表。Radius (unit: m), if the radius is exceeded, an empty list will be returned.
lane_type (int): 车道类型(1:行车,默认|2:步行)。Lane type (1: driving, default | 2: walking).
Returns:
List[Tuple[Any, float, float]]: lane列表,每个元素为(lane, s, 距离)。lane list, each element is (lane, s, distance).