<jupyter_start><jupyter_text>Jupyter notebook to Install **Fast map matching*** using Google Colab By <NAME>*<NAME> & <NAME> (2018) Fast map matching, an algorithmintegrating hidden Markov model with precomputation, International Journal of Geographical Information Science, 32:3, 547-570, DOI: 10.1080/13658816.2017.1400548https://fmm-wiki.github.io/<jupyter_code># https://fmm-wiki.github.io/docs/installation/ubuntu.html

# Install all the requirements with:
! sudo apt-get install libboost-dev libboost-serialization-dev \
gdal-bin libgdal-dev make cmake libbz2-dev libexpat1-dev swig python-dev
! git clone https://github.com/cyang-kth/fmm.git
# !!!! This cell will take some time... !!!!

import os
# change working directory
os.chdir("fmm")

if not os.path.exists('build'):
  os.mkdir('build')
# ! mkdir build
os.chdir("build")
# ! cd build
! cmake ..
! make -j4
! sudo make install
# Verfication of installation
! fmm
# Run python script

# Change to the parent folder which contains fmm_test.py
# cd ../example/python
if os.getcwd() != "/content/fmm/example/python":
  os.chdir("/content/fmm/example/python")
os.system('python fmm_test.py')
# !!! SKIP !!!
# zip and download fmm folder 
# !zip -r /content/fmm.zip /content/fmm/

# from google.colab import files
# files.download("/content/fmm.zip")<jupyter_output><empty_output><jupyter_text>Example: Demo of fmm Python APIhttps://github.com/cyang-kth/fmm/blob/master/example/notebook/fmm_example.ipynb<jupyter_code>from fmm import Network,NetworkGraph,FastMapMatch,FastMapMatchConfig,UBODT
network = Network("/content/fmm/example/data/edges.shp")
print("Nodes {} edges {}".format(network.get_node_count(),network.get_edge_count()))
graph = NetworkGraph(network)
from fmm import UBODTGenAlgorithm
ubodt_gen = UBODTGenAlgorithm(network,graph)
status = ubodt_gen.generate_ubodt("/content/fmm/example/data/ubodt.txt", 4, binary=False, use_omp=True)
print(status)
ubodt = UBODT.read_ubodt_csv("/content/fmm/example/data/ubodt.txt")
model = FastMapMatch(network,graph,ubodt)
k = 4
radius = 0.4
gps_error = 0.5
fmm_config = FastMapMatchConfig(k,radius,gps_error)
wkt = "LINESTRING(0.200812146892656 2.14088983050848,1.44262005649717 2.14879943502825,3.06408898305084 2.16066384180791,3.06408898305084 2.7103813559322,3.70872175141242 2.97930790960452,4.11606638418078 2.62337570621469)"
result = model.match_wkt(wkt,fmm_config)
print("Matched path: ", list(result.cpath))
print("Matched edge for each point: ", list(result.opath))
print("Matched edge index ",list(result.indices))
print("Matched geometry: ",result.mgeom.export_wkt())
print("Matched point ", result.pgeom.export_wkt())
candidates = []
for c in result.candidates:
    candidates.append((c.edge_id,c.source,c.target,c.error,c.length,c.offset,c.spdist,c.ep,c.tp))
import pandas as pd
df = pd.DataFrame(candidates,
                  columns=["eid","source","target","error","length","offset","spdist","ep","tp"])
df.head()
from fmm import GPSConfig,ResultConfig
input_config = GPSConfig()
input_config.file = "../data/trips.csv"
input_config.id = "id"
print(input_config.to_string())
result_config = ResultConfig()
result_config.file = "../data/mr.txt"
result_config.output_config.write_opath = True
print(result_config.to_string())
status = model.match_gps_file(input_config, result_config, fmm_config)
print(status)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14302705917335712, 'fraction_numerical': 0.06749925661611657, 'mean_word_length': 6.022964509394572, 'pattern_counts': {'":': 1, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '82180', 'license': 'MIT', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1210, 'n_words': 226, 'path': 'Install_fast_map_matching.ipynb', 'repo_name': 'jalal1/fmm_jupyter', 'size': '3380'}