Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ba
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
markn92
ba
Commits
dacee3fa
Commit
dacee3fa
authored
4 years ago
by
markn92
Browse files
Options
Downloads
Patches
Plain Diff
stupid but works so far. osmr has problems with high frequency of requests.
parent
e39259d7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
evrouting/osm.py
+26
-17
26 additions, 17 deletions
evrouting/osm.py
with
26 additions
and
17 deletions
evrouting/osm.py
+
26
−
17
View file @
dacee3fa
...
...
@@ -14,12 +14,12 @@ Added :
import
copy
import
xml.sax
import
time
from
math
import
radians
,
cos
,
sin
,
asin
,
sqrt
from
collections
import
namedtuple
import
networkx
as
nx
import
aiohttp
import
asyncio
import
requests
from
evrouting.graph_tools
import
DISTANCE_KEY
...
...
@@ -141,26 +141,35 @@ def read_osm(osm_xml_data,
G
.
nodes
[
n_id
][
'
id
'
]
=
n
.
id
coordinates_map
[
n_id
]
=
(
n
.
lon
,
n
.
lat
)
asyncio
.
run
(
augment_distances
(
G
,
query_url
)
)
augment_distances
(
G
,
query_url
)
G
=
nx
.
relabel_nodes
(
G
,
coordinates_map
)
return
G
async
def
augment_distances
(
G
,
url_factory
):
def
augment_distances
(
G
,
url_factory
):
# Estimate the length of each way
async
with
aiohttp
.
ClientSession
()
as
session
:
for
u
,
v
,
d
in
G
.
edges
(
data
=
True
):
url
=
url_factory
(
'
route
'
,
[
(
G
.
nodes
[
u
][
'
lat
'
],
G
.
nodes
[
u
][
'
lon
'
]),
(
G
.
nodes
[
v
][
'
lat
'
],
G
.
nodes
[
v
][
'
lon
'
])
])
async
with
session
.
get
(
url
)
as
resp
:
resp
.
raise_for_status
()
resp
=
await
resp
.
json
()
duration
=
resp
[
'
routes
'
][
0
][
'
duration
'
]
G
.
add_weighted_edges_from
([(
u
,
v
,
duration
)],
weight
=
DISTANCE_KEY
)
i
=
0
for
u
,
v
,
d
in
G
.
edges
(
data
=
True
):
i
+=
1
url
=
url_factory
(
'
route
'
,
[
(
G
.
nodes
[
u
][
'
lat
'
],
G
.
nodes
[
u
][
'
lon
'
]),
(
G
.
nodes
[
v
][
'
lat
'
],
G
.
nodes
[
v
][
'
lon
'
])
])
try
:
resp
=
requests
.
get
(
url
,
timeout
=
0.1
)
except
requests
.
exceptions
.
Timeout
:
print
(
'
Timeout at request:
'
,
i
)
raise
if
resp
.
status_code
==
200
:
resp
=
resp
.
json
()
else
:
continue
duration
=
resp
[
'
routes
'
][
0
][
'
duration
'
]
time
.
sleep
(
0.005
)
G
.
add_weighted_edges_from
([(
u
,
v
,
duration
)],
weight
=
DISTANCE_KEY
)
class
Node
(
object
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment