cyang-kth / fmm

Fast map matching, an open source framework in C++
https://fmm-wiki.github.io/
Apache License 2.0
878 stars 205 forks source link

Weird map-matching results #173

Closed MathiasVersichele closed 3 years ago

MathiasVersichele commented 3 years ago

Hi, I have the following code which runs a map-matching on a test trajectory.

from fmm import Network,NetworkGraph,STMATCH,STMATCHConfig
network = Network("/Users/mathias/Dropbox (RetailSonar)/Operations/RetailSonar/2. projects/191476_geouniq/footfall_nl/input_data/geouniq_nl_car.shp")
print("Nodes {} edges {}".format(network.get_node_count(),network.get_edge_count()))
graph = NetworkGraph(network)
model = STMATCH(network,graph)
k = 4
gps_error = 50
radius = 300
vmax = 120
factor = 1.5
stmatch_config = STMATCHConfig(k=k, radius=radius, gps_error=gps_error, factor=factor, vmax=vmax, reverse_tolerance_arg=0.9)

from fmm import GPSConfig,ResultConfig
input_config = GPSConfig()
input_config.file = "gps_test2.txt"
input_config.id = "id"
print(input_config.to_string())

result_config = ResultConfig()
result_config.file = "mr.txt"
result_config.output_config.write_opath = False
result_config.output_config.write_error = True
result_config.output_config.write_speed = True
result_config.output_config.write_duration = True
result_config.output_config.write_spdist = True
print(result_config.to_string())

status = model.match_gps_file(input_config, result_config, stmatch_config)
print(status)

This is the content of gps_test2.txt:

id;geom;timestamp
1;LINESTRING (99406.92361806546 443072.2887783501, 99204.10972147947 442736.7248502466, 99269.5145399943 442651.2317875866, 99308.04044800179 442601.8559311253, 99463.5656252863 442199.0205587792, 99728.81734325775 441646.9579962573, 99583.33997333166 441430.1106436024, 99267.3827536426 441205.0192908072, 98871.84810259208 440923.5502438692, 98558.65435265383 440687.72358160454, 98224.37353173005 440545.87531630014, 98396.42858909824 440431.7109613266, 98514.37151546999 440293.696771779);1583823442,1583823941,1583823950,1583823956,1583824046,1583824091,1583824136,1583824226,1583824271,1583824316,1583824361,1583824406,1583824451

I get the following result in mr.txt, where I have replaced ';' with newlines to increase readability:

id
error
spdist
cpath
mgeom
duration
speed
1
5.29229,3.56671,0.0771821,2.39811,2.97411,1.15196,0.201399,0.466927,3.16708,0.045113,4.27532,3.17205,0.346702
519.748,1.79769e+308,1.79769e+308,1.79769e+308,1.79769e+308,1.79769e+308,1.79769e+308,1.79769e+308,1.79769e+308,1.79769e+308,1.79769e+308,1.79769e+308
-133982903,-150874318,-171647103,-117026827,-144102171,-107904238,-152710414,-141834721,160809835,106319570,141834720,-141834721,160809835,75035413,110676440,106319569,-106319570,75035413,116655128,143227389,98653649,125809617,104469415,104655212,130468806,85357459,140069044,82571133,93852051,83781116,78791824,119573838,-119573837,-137735086,-171372020,137348518,126020328,99649412,151589248,170010343,140740033,161852202,168248504,129354190,151427317,124331213,147656737,108460735,131855909,88277466,137127625,98300425,106318252,170764536,96180908,119759039,111267656,143305367,108064593,117650283,85335666,141334362,131652301,132258012,156943231,148558579,162021435,112695681,157666393,141076463,101593846,82750049,152262189,97888804,150268880,149391450,116708550,110372113,-110372114,-156388815,-120242270,-162735901,-89701449,-82038894,-92830765,-144423042,-119049750,-131897296,-138247484,-84689491,84689491
LINESTRING(99412.1228651 443073.276786,99440.8643318 443029.741062,99388.8299205 442993.313279,99423.5706048 442944.191841,99273.9566787 442835.561394,99287.8913305 442816.279222,99203.6893047 442757.525202,99196.7604261 442752.462141,99191.175786 442748.38546,99268.1986352 442642.934893,99272.8966864 442646.387339,99196.7604261 442752.462141,99191.175786 442748.38546,99268.1986352 442642.934893,99310.1867534 442584.174054,99315.2237742 442587.823038,99272.8966864 442646.387339,99268.1986352 442642.934893,99310.1867534 442584.174054,99347.0964099 442532.75812,99353.2873409 442524.010362,99357.8531223 442517.439285,99368.6063068 442501.797841,99406.0607385 442448.584912,99445.5220958 442392.835338,99452.1396264 442383.482125,99375.1291602 442331.588177,99368.6311503 442326.987392,99373.1798687 442320.716942,99380.1912339 442310.936436,99415.681976 442261.461775,99446.2312487 442218.740569,99483.3838473 442165.309109,99489.4902988 442156.317688,99503.1806543 442136.44918,99511.5773158 442117.685432,99517.4728618 442106.404311,99519.7825311 442093.438413,99526.2486847 442060.509726,99535.1047301 442028.010696,99556.0464238 441966.615232,99575.8054227 441915.658615,99591.9561765 441873.988318,99608.2428324 441828.433391,99630.8880757 441784.755176,99644.4707541 441763.708862,99681.9232356 441709.541312,99716.2617541 441662.117859,99731.7485777 441641.017339,99735.7901634 441634.786232,99769.0766913 441583.513878,99770.4763887 441580.794639,99772.8223219 441576.618481,99777.802992 441568.274101,99768.6601545 441561.387707,99603.9984128 441444.52406,99555.8026085 441410.321641,99548.825382 441405.369882,99531.1294025 441392.815309,99419.7949419 441313.073676,99380.6153588 441285.014612,99378.1188612 441283.06188,99365.1742765 441273.781825,99266.1844859 441203.597331,99230.6581165 441178.413829,99224.6413897 441173.963613,99222.5550398 441172.429188,99207.1531282 441161.074051,99083.6602444 441073.297557,99040.5291655 441042.637221,98829.4927698 440888.743885,98826.8240085 440886.79336,98813.2731994 440876.976324,98801.3974938 440868.175253,98685.5365205 440779.910886,98662.9920306 440762.729694,98588.3264155 440722.325976,98579.7319457 440717.404936,98570.989455 440712.162912,98558.2874625 440686.893231,98539.7340718 440674.96376,98498.8559086 440651.403588,98496.4847994 440650.262112,98490.6192608 440648.959887,98474.4390793 440638.383509,98466.306848 440632.41153,98458.6175788 440626.701588,98450.4014102 440621.820993,98441.721493 440616.667495,98417.7687645 440604.588197,98398.0026631 440596.122231,98360.4393725 440583.073649,98202.49991 440545.000171,98192.5928157 440542.609329,98181.2937751 440539.945046,98196.0935561 440530.619531,98331.2100742 440564.078201,98368.3123117 440572.825792,98404.7694112 440582.293069,98439.6084116 440596.418729,98450.3395823 440601.782661,98464.2377108 440608.746386,98468.5781813 440596.179826,98469.7231894 440592.862265,98502.1842909 440493.412565,98491.6133889 440490.683713,98486.6717328 440492.664517,98479.064216 440502.096935,98428.5801347 440570.284795,98422.8431325 440574.878298,98395.9023161 440568.518644,98368.9614291 440562.159135,98359.5719297 440559.928996,98355.4055001 440557.506128,98352.0043389 440554.662901,98362.5171936 440511.038634,98381.8385273 440432.299104,98400.6196222 440435.691311,98404.2883608 440433.624704,98406.9688176 440429.28834,98416.5626861 440390.659337,98427.8994035 440345.023109,98433.5121964 440323.362804,98437.5591704 440308.540845,98444.4896479 440285.44143,98447.2779702 440276.653225,98542.1937009 440301.271048,98547.6397019 440297.66012,98542.1937009 440301.271048,98514.284473 440294.03237)
499,9,6,90,45,45,90,45,45,45,45,45
1.04157866007,1.99743681651e+307,2.99615522477e+307,1.99743681651e+306,3.99487363303e+306,3.99487363303e+306,1.99743681651e+306,3.99487363303e+306,3.99487363303e+306,3.99487363303e+306,3.99487363303e+306,3.99487363303e+306

Visually, the map-matching looks ok-ish: image

But before diving into the details, I'm wondering how to interpret these results. The duration and speed lists contain 10 elements, but the shortest path is clearly longer. And why do I have speeds of e+307 order of magnitude ?

What I would like to get from output is:

cyang-kth commented 3 years ago

The speed and duration are calculated for each GPS point rather than each edge. Two GPS points can connect many edges. The reason of large speed may be that your network data is not projected. Make sure your GPS data and network data are in the same coordinate system.