Skip to content

Commit

Permalink
In progress with merge
Browse files Browse the repository at this point in the history
  • Loading branch information
cyang-kth committed May 12, 2020
2 parents 73014ad + 13755c2 commit f19cde7
Show file tree
Hide file tree
Showing 5 changed files with 512 additions and 27 deletions.
42 changes: 42 additions & 0 deletions example/osm_example/osm_test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Example to test implementation for reading OSM data directly

These instructions were tested on Ubuntu 18.04, after building the code in the OSM branch. They assume a working directory under ``example/command_line_example/``

### 1. Download test data

```
mkdir osm_test
cd osm_test
wget https://www.dropbox.com/s/a3d8hmtkflckw10/fmm_osm_test_data.zip
unzip fmm_osm_test_data.zip
```

Test data contains:
- OSM data for Singapore (defined by bounding box)
- Road network in shapefile format (converted from OSM with https://github.com/dkondor/osmconvert/ )
- Test data with 5 trajectories (created manually by clicking on the map in QGIS)


### 2. Run stmatch with shapefile input

```
stmatch --network ways.shp --gps test_points.csv --output stmatch_result.csv -k 4 -r 0.4 -e 0.5 --gps_geom WKT --gps_id id --source from --target to
```

### 3. Run stmatch with OSM input

```
stmatch --network Singapore.osm.pbf --gps test_points.csv --output stmatch_result_osm.csv -k 4 -r 0.4 -e 0.5 --gps_geom WKT --gps_id id
```

### 4. Compare results

Unfortunately, it's not possible to compare the list of edge IDs in the output, since these are assigned separately by the two methods. It is possible to compare the output trajectory directly instead:

```
cut -d \; -f 1,3 stmatch_result.csv > stmatch_result2.csv
cut -d \; -f 1,3 stmatch_result_osm.csv > stmatch_result_osm2.csv
diff -q stmatch_result2.csv stmatch_result_osm2.csv
```

No output from the last command means that the output trajectories are identical.
39 changes: 13 additions & 26 deletions src/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,6 @@ Network::Network(const std::string &filename,
}
};

class OSMHandler : public osmium::handler::Handler {
public:
OSMHandler(Network *network_arg) : network(*network_arg){
};
void way(const osmium::Way& way){
if (way.nodes().size()>1) {
try{
EdgeID eid= way.id();
int source = way.nodes().front().ref();
int target = way.nodes().back().ref();
// SPDLOG_INFO("Read road edge {} {} {} nodes {}",
// eid, source, target, way.nodes().size());
std::unique_ptr<OGRLineString> line = factory.create_linestring(way);
LineString geom = ogr2linestring(line.get());
network.add_edge(eid,source,target,geom);
} catch (const std::exception& e) { // caught by reference to base
std::cout << " a standard exception was caught, with message '"
<< e.what() << "'\n";
}
}
};
private:
Network &network;
osmium::geom::OGRFactory<> factory;
};

void Network::add_edge(EdgeID edge_id, NodeID source, NodeID target,
const FMM::CORE::LineString &geom){
NodeIndex s_idx, t_idx;
Expand Down Expand Up @@ -115,6 +89,19 @@ void Network::read_osm_file(const std::string &filename) {
SPDLOG_INFO("Read osm network done with edges read {}",edges.size());
};

void Network::read_osm_file(const std::string &filename) {
SPDLOG_INFO("Read osm network {} ", filename);
auto otypes = osmium::osm_entity_bits::node|osmium::osm_entity_bits::way;
osmium::io::Reader reader{filename, otypes};
bool do_filter = true;
OSMHandler handler(do_filter);
osmium::apply(reader, handler);
reader.close();
handler.generate_simplified_graph(*this);
build_rtree_index();
SPDLOG_INFO("Read osm network done with edges read {}",edges.size());
};

void Network::read_ogr_file(const std::string &filename,
const std::string &id_name,
const std::string &source_name,
Expand Down
Loading

0 comments on commit f19cde7

Please sign in to comment.