Skip to content

Commit

Permalink
update to 0.2.22
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchenplus committed Jul 17, 2024
1 parent 2271936 commit a755dbf
Show file tree
Hide file tree
Showing 7 changed files with 605 additions and 322 deletions.
2 changes: 0 additions & 2 deletions examples/map_osm2geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
}
# Configure log and store it in the file mapbuilder2.log
logging.basicConfig(
filename="mapbuilder2.log",
filemode="w",
level=logging.INFO,
format="%(asctime)s %(levelname)s %(message)s",
)
Expand Down
19 changes: 18 additions & 1 deletion examples/merge_map.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
import logging

from mosstool.type import Map
from mosstool.map.builder import Builder
from mosstool.util.map_merger import merge_map
from mosstool.util.format_converter import dict2pb

logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(message)s",
)

REBUILD_MAP = True
maps = []
for i in [0, 1]:
with open(f"data/temp/test_{i}.pb", "rb") as f:
pb = Map()
pb.ParseFromString(f.read())
maps.append(pb)
merge_map(
merged_pb = merge_map(
partial_maps=maps,
output_path="data/temp/merged_m.pb",
)
if REBUILD_MAP:
builder = Builder(
net=merged_pb,
proj_str=merged_pb.header.projection,
gen_sidewalk_speed_limit=50 / 3.6,
aoi_mode="append", # keep AOIs in merged_pb
road_expand_mode="M",
)
rebuild_m = builder.build(merged_pb.header.name)
rebuild_pb = dict2pb(rebuild_m, Map())
with open("data/temp/rebuild_merged_m.pb", "wb") as f:
f.write(rebuild_pb.SerializeToString())

39 changes: 12 additions & 27 deletions mosstool/map/_map_util/aoi_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,14 @@
import shapely.ops as ops
from scipy.spatial import KDTree
from shapely.affinity import scale
from shapely.geometry import (
LineString,
MultiLineString,
MultiPoint,
MultiPolygon,
Point,
Polygon,
)
from shapely.geometry import (LineString, MultiLineString, MultiPoint,
MultiPolygon, Point, Polygon)
from shapely.strtree import STRtree

from ...type import AoiType
from .._util.angle import abs_delta_angle, delta_angle
from .._util.line import (
connect_line_string,
get_line_angle,
get_start_vector,
line_extend,
offset_lane,
)
from .._util.line import (connect_line_string, get_line_angle,
get_start_vector, line_extend, offset_lane)
from .aoiutils import geo_coords

# ATTENTION: In order to achieve longer distance POI merging, the maximum recursion depth needs to be modified.
Expand Down Expand Up @@ -742,12 +731,10 @@ def _add_poly_aoi_unit(arg):
"positions": [{"x": c[0], "y": c[1]} for c in geo_coords(geo)],
"area": geo.area,
"external": {
"osm_tencent_ids": [
aoi["id"]
], # id in aoi_osm_tencent_fudan.aoi_beijing5ring
"osm_input_ids": [aoi["id"]],
"ex_poi_ids": aoi["external"].get(
"inner_poi", []
), # Tencent id of poi contained in aoi
), # Input id of poi contained in aoi
# aoi population
"population": aoi["external"].get("population", 0),
"land_types": aoi["external"].get("land_types", defaultdict(float)),
Expand Down Expand Up @@ -849,14 +836,12 @@ def _add_aoi_stop_unit(arg):
"positions": [{"x": c[0], "y": c[1]} for c in geo_coords(geo)],
"area": geo.area,
"external": {
"osm_tencent_ids": [
aoi["id"]
], # id in aoi_osm_tencent_fudan.aoi_beijing5ring
"osm_input_ids": [aoi["id"]],
"stop_id": aoi["external"]["stop_id"],
"station_type": station_type,
"ex_poi_ids": aoi["external"].get(
"inner_poi", []
), # Tencent id of poi contained in aoi
), # Input id of poi contained in aoi
# aoi population
"population": aoi["external"].get("population", 0),
"land_types": aoi["external"].get("land_types", defaultdict(float)),
Expand Down Expand Up @@ -1630,7 +1615,7 @@ def _add_pois(aois, pois, projstr):
"position": {"x": x, "y": y},
"aoi_id": poi_id_to_aoi_id[poi_id],
"external": {
"tencent_poi_id": poi_id,
"input_poi_id": poi_id,
},
}
poi_uid += 1
Expand Down Expand Up @@ -1890,10 +1875,10 @@ def add_aoi_to_map(
raw_pois = {doc["id"]: doc for doc in input_pois}

aois = _add_aoi(aois=input_aois, stops=input_stops, workers=workers, merge_aoi=True)
added_tencent_poi = []
added_input_poi = []
for _, aoi in aois.items():
added_tencent_poi.extend(aoi["external"].get("ex_poi_ids", []))
logging.info(f"Added Tencent POI num: {len(added_tencent_poi)}")
added_input_poi.extend(aoi["external"].get("ex_poi_ids", []))
logging.info(f"Added Input POI num: {len(added_input_poi)}")
# Post-compute
logging.info("Post Compute")
aois = _add_aoi_land_use(aois, shp_path, bbox, projstr)
Expand Down
Loading

0 comments on commit a755dbf

Please sign in to comment.