Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

only-changer
Copy link
Contributor

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.

@only-changer
Copy link
Contributor Author

testcase added

Comment on lines 105 to 124
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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 82 to 91
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
Copy link
Member

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?

Copy link
Contributor Author

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,
Copy link
Contributor

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)*

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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/
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants