cyang-kth / fmm

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

[feature request] importing OSM network data #13

Closed kkdd closed 5 years ago

kkdd commented 6 years ago

Hello, It would be nice if fmm can import OSM network data by using libosmium or others.

cyang-kth commented 6 years ago

Thank you for this information. I am also considering adding support for OSM data. However, I can only work on this project in my spare time. I am not sure how long it will take to implement this feature. I will add call for contributions to this feature.

cyang-kth commented 6 years ago

@kkdd If you are familiar with PostGIS. You can use osm2pgrouting to import osm network to a PostGIS database.

aferber commented 6 years ago

@cyang-kth I've been trying to use osm2pgrouting to build a .shp file usable by ubodt_gen. However, the tool seems to stall on the output. Is there specific configuration needed to get this work?

cyang-kth commented 6 years ago

@aferber I did not get your question. Have you generated a shapefile with topology information (source and target column)? How many edges are there in your network?

aferber commented 6 years ago

Thanks for the repl, and sorry for the confusion.

I am using the Michigan OSM data: http://download.geofabrik.de/north-america/us/michigan.html. I ran osm2pgrouting to generate a network table for the OSM ways. Next I ran pgsql2shp to export to a .shp file. Finally I run ubodt_gen on the using the shape file. ubodt_gen stalls with the following

------------ Fast map matching (FMM) ------------ ------------ Author: Can Yang ------------ ------------ Version: 2018.03.09 ------------ ------------Application: ubodt_gen_opt------------ Read configuration from xml file: ubodt_config.xml Validating configuration for UBODT construction: Warning, overwrite existing result file.ubodt.txt Validating success. Write UBODT to file ubodt.txt Read network shp file from data/michigan.shp Id column osm_id Number of edges in file: 1532002 SHP ID idx: 0 SHP source idx: 2 SHP target idx: 1 SRID is 4326 Read network finish. The maximum node ID is 1168538 Total number of edges read 1532002 Construct graph from network edges start Network edges :1532002 Graph nodes 1168538 Construct graph from network edges end Upperbound config (delta): 3000 Start to generate UBODT with delta 3000 Progress 0 / 1168538

Heres my config:

<?xml version="1.0" encoding="utf-8"?>
<ubodt_config>
    <input>
        <network>
            <file>data/michigan.shp</file>
            <id>osm_id</id>
            <source>source</source>
            <target>target</target>
        </network>
    </input>
    <parameters>
        <delta>3000</delta>
    </parameters>
    <output>
        <file>ubodt.txt</file>
    </output>
</ubodt_config>

I am assuming the target and source are correct, but I'm not sure about what the ID should be (osm_id is the best candidate from the table).

I wonder if I am missing a step or configuration in creating the .shp file.

Edit: XML formating

Thanks

cyang-kth commented 6 years ago

@aferber I think that the problem is that the delta you used is too big. Since your network coordinate is in degrees, an upperbound (delta) of 3000 degrees covers the whole earth. That implies that you are calculating all pairs of shortest path of the network.

As one degree of longitude and latitude both cover about 111 kilometers, you should try some rather small value like 0.02 (about 2km) to check your result.

The unit of delta is equal to the unit of the shapefile unit. You can specify it in meters only if your network is projected with unit of meter.

cyang-kth commented 6 years ago

The search radius r and gps error defined in the configuration of fmm should also be specified in degrees in your case.

aferber commented 6 years ago

Thanks again. I was able to get it to complete using a delta of 0.02.

cyang-kth commented 5 years ago

@kkdd @aferber

It is great to know that OSMNX provides a convenient API to download the road network from OSM as edges and nodes in shapefile format, which can be directly used here.

Example can be found at https://github.com/cyang-kth/fmm/tree/master/preprocess https://github.com/gboeing/osmnx-examples/blob/master/notebooks/05-example-save-load-networks-shapes.ipynb