Custom MapΒΆ

Map generation relies on the mosstool toolkit in MOSS: MObility Simulation System. mosstool downloads road network and AOI data from OpenStreetMap, preprocesses it, and reconstructs lane-level high-precision map files, ultimately generating the required Protobuf format map files.

mosstool is also a Python package that can be quickly installed via pip:

pip install mosstool

After installation, the following code can be used to generate a map file within a specified latitude and longitude range:

from mosstool.map.osm import RoadNet, Building
from mosstool.map.builder import Builder
from mosstool.util.format_converter import dict2pb
from mosstool.type import Map

min_latitude = 39.78
max_latitude = 39.92
min_longitude = 116.32
max_longitude = 116.40

projstr = f"+proj=tmerc +lat_0={(min_latitude + max_latitude) / 2} +lon_0={(min_longitude + max_longitude) / 2}"
rn = RoadNet(
    proj_str=projstr,
    max_latitude=max_latitude,
    min_latitude=min_latitude,
    max_longitude=max_longitude,
    min_longitude=min_longitude,
    proxies=None,
)
roadnet = rn.create_road_net()
building = Building(
    proj_str=projstr,
    max_latitude=max_latitude,
    min_latitude=min_latitude,
    max_longitude=max_longitude,
    min_longitude=min_longitude,
    proxies=None,
)
aois = building.create_building()
builder = Builder(
    net=roadnet,
    aois=aois,
    proj_str=projstr,
)
m = builder.build("map_name")
pb = dict2pb(m, Map())
with open("./map.pb", "wb") as f:
    f.write(pb.SerializeToString())

You can modify min_latitude, max_latitude, min_longitude, and max_longitude in the code to generate maps for different regions.

Network Proxy

If you need to use a proxy to download data, you can set the proxies parameter, such as proxies={"http": "http://127.0.0.1:7890", "https": "http://127.0.0.1:7890"}.

Tip

We provide map files for some large cities, which can be downloaded from the Map Page on the AgentSociety Official Website.