-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add osm2cityflow #63
base: master
Are you sure you want to change the base?
Add osm2cityflow #63
Conversation
testcase added |
tools/converter/osm2cityflow.py
Outdated
if str(wayID + '_' + str(pos) + '_' + str(endPos)) not in road_dic: | ||
build_road(wayID, maxSpeed, oneDirectionLanes, points, | ||
wayID + '_' + str(pos) + '_' + str(endPos), nodeID, endID) | ||
if road_dic[str(wayID + '_' + str(pos) + '_' + str(endPos))]["endIntersection"] == crossID: | ||
in_roadIDs.append(wayID + '_' + str(pos) + '_' + str(endPos)) | ||
else: | ||
out_roadIDs.append(wayID + '_' + str(pos) + '_' + str(endPos)) | ||
if otherDirectionLanes > 0: | ||
if str(wayID + '_' + str(endPos) + '_' + str(pos)) not in road_dic: | ||
build_road(wayID, maxSpeed, otherDirectionLanes, otherPoints, | ||
wayID + '_' + str(endPos) + '_' + str(pos), endID, nodeID) | ||
if road_dic[str(wayID + '_' + str(endPos) + '_' + str(pos))]["endIntersection"] == crossID: | ||
in_roadIDs.append(wayID + '_' + str(endPos) + '_' + str(pos)) | ||
else: | ||
out_roadIDs.append(wayID + '_' + str(endPos) + '_' + str(pos)) | ||
return in_roadIDs, out_roadIDs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make wayID + '_' + str(endPos) + '_' + str(pos)
a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
tools/converter/osm2cityflow.py
Outdated
if tag.getAttribute('k') == 'lanes': | ||
numLanes = int(tag.getAttribute('v')) | ||
if tag.getAttribute('k') == 'lanes:forward': | ||
oneDirectionLanes = int(tag.getAttribute('v')) | ||
if tag.getAttribute('k') == 'lanes:backward': | ||
otherDirectionLanes = int(tag.getAttribute('v')) | ||
if tag.getAttribute('k') == 'oneway' and tag.getAttribute('v') == 'yes': | ||
oneway = True | ||
if tag.getAttribute('k') == 'maxspeed': | ||
maxSpeed = float(tag.getAttribute('v')[0:-3]) * 1.609344 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why getAttribute('k')
so many times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a list of tags in one road, their order is not fixed.
intersection = { | ||
"id": nodeID, | ||
"point": {"x": x, "y": y}, | ||
"width": 5, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the width of an intersection is a constant?
``` | ||
python osm2cityflow.py --osmFile statecollege.osm --CityFlowNet statecollege_roadnet.json | ||
``` | ||
*Example osm roadnet, CityFlow roadnet and simple flow files can be downloaded [here](https://github.com/cityflow-project/data/tree/master/tools/Converter/examples)* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any new dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there isn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the script depend on pyproj and folium?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pyproj is used to convert latitude and longitude to x-y two-dimensional coordinates.
folium is used to draw two graphs with osm map as background, which show the roads and intersections that will be kept in CityFlow road net.
@@ -88,7 +88,7 @@ stages: | |||
python_version: '3.7' | |||
cxx_standard: '14' | |||
target: 'all test' | |||
- script: cp build/cityflow* . && python3.7 -m unittest discover tests/python/ | |||
- script: python3.7 -m pip install pyproj folium && cp build/cityflow* . && git clone https://github.com/cityflow-project/data.git && python3.7 -m unittest discover tests/python/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we split these commands into serval scripts?
add osm2cityflow
current problems: 1. osm doesn't provide the width of lanes or intersections, so I just set a default value.
2. Only use highway.primary road.
3. Since osm road net will always cut one road into many segments, when there are serval short segments near intersections, vehicles may be unable to stop before stop line and rush across the intersection.