wannesm / LeuvenMapMatching

Leuven.MapMatching toolbox for aligning GPS measurements to locations on a map.
Other
222 stars 43 forks source link

No route satisfies mapmatch criteria #33

Open TanCari opened 2 years ago

TanCari commented 2 years ago

Mostly using examples in the docu, I do the following:

Download a map

from pathlib import Path import requests xml_file = Path(".") / "osm.xml" url = 'http://overpass-api.de/api/map?bbox=4.694933,50.870047,4.709256000000001,50.879628' r = requests.get(url, stream=True) with xml_file.open('wb') as ofile: for chunk in r.iter_content(chunk_size=1024): if chunk: ofile.write(chunk)

Create a map, removing the limitation 'highway in entity.tags'

from leuvenmapmatching.map.inmem import InMemMap import osmread

map_con = InMemMap("myosm", use_latlon=True, use_rtree=True, index_edges=True) for entity in osmread.parse_file(str(xml_file)):

if isinstance(entity, osmread.Way) and 'highway' in entity.tags:

if isinstance(entity, osmread.Way):
    for node_a, node_b in zip(entity.nodes, entity.nodes[1:]):
        map_con.add_edge(node_a, node_b)
        # Some roads are one-way. We'll add both directions.
        map_con.add_edge(node_b, node_a)
if isinstance(entity, osmread.Node):
    map_con.add_node(entity.id, (entity.lat, entity.lon))

map_con.purge()

Create my own track

track = [(50.87158705419287, 4.701149818142195), (50.87162768899347, 4.701342872760166), (50.87164800638049, 4.701557377891264), (50.8716818686725, 4.70172898199615), (50.87169541358241, 4.701932761870685), (50.87173604828854, 4.702157992258305), (50.87178345540092, 4.70228669533694), (50.87179700028131, 4.7025012004680375), (50.87168864112794, 4.702608453033586), (50.87161414406387, 4.702554826750811), (50.87155996430614, 4.702587002520461), (50.871444832111806, 4.702694255086009), (50.87131615461689, 4.702822958164683), (50.87132292712548, 4.70291948547367), (50.87132292712548, 4.703048188552304), (50.87123488443708, 4.70314471586129), (50.87111975143977, 4.703155441117853), (50.87103170836759, 4.703198342144065), (50.87093012000073, 4.703348495735825), (50.870889484592006, 4.70347719881446), (50.87080821366827, 4.703509374584148), (50.87077435074152, 4.703595176636571), (50.87075403297369, 4.703670253432471), (50.87071339741144, 4.703713154458683), (50.87064567139563, 4.703788231254543)]

Try to mapmatch it

from leuvenmapmatching.util.gpx import gpx_to_path

matcher = DistanceMatcher(map_con, max_dist=100, max_dist_init=25, # meter min_prob_norm=0.001, non_emitting_length_factor=0.75, obs_noise=50, obs_noise_ne=75, # meter dist_noise=50, # meter non_emitting_states=True, max_lattice_width=5) states, lastidx = matcher.match(track)

But the result is poor: no mapmatched way seems to satisfy the selection criteria.

assert not [l for l in matcher.lattice.values() if l.values_all()]

Could you please help me with that?

felipinbombin commented 2 years ago

Hi! I had a similar issue this week. I noticed that the use_rtree option causes the problem because nodes are not inserted in rtree; that is why it didn't work.

You can make it work if it sets use_rtree to False. It is slower without an index, but it works.

I hope it can be helpful :-)

This IF doesn't work: https://github.com/wannesm/LeuvenMapMatching/blob/master/leuvenmapmatching/map/inmem.py#L218