From ac86db73c8649cc53a8b9ce897901e21bd21d049 Mon Sep 17 00:00:00 2001 From: dnesbitt Date: Tue, 12 Sep 2017 10:19:37 -0400 Subject: [PATCH 1/3] Change from using MultiLineString to LineString. Remove duplicate coords at the start of new edges. Make the headers consistent. --- src/geojson_osmlr.cpp | 17 +++++++++++++---- src/output/geojson.cpp | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/geojson_osmlr.cpp b/src/geojson_osmlr.cpp index 59fe8a9..065222d 100644 --- a/src/geojson_osmlr.cpp +++ b/src/geojson_osmlr.cpp @@ -53,7 +53,7 @@ void output_segment(std::ostringstream& out, } first = false; out << "{\"type\":\"Feature\",\"geometry\":"; - out << "{\"type\":\"MultiLineString\",\"coordinates\":["; + out << "{\"type\":\"LineString\",\"coordinates\":["; out << "["; bool first_pt = true; for (const auto pt : shape) { @@ -64,7 +64,7 @@ void output_segment(std::ostringstream& out, bool oneway = (edge->reverseaccess() & vb::kVehicularAccess) == 0; out << "]},\"properties\":{" - << "\"tile_id\":" << osmlr_id.tileid() << "," + << "\"tile_id\":" << osmlr_id.tileid() << "," << "\"level\":" << osmlr_id.level() << "," << "\"id\":" << osmlr_id.id() << "," << "\"osmlr_id\":" << osmlr_id.value << "," @@ -117,9 +117,17 @@ const vb::DirectedEdge* follow_segment(const vb::TrafficSegment& seg, if (next_seg.begin_percent_ > 0.0f || next_seg.end_percent_ < 1.0f) { auto partial_shape = vm::trim_polyline(next_shape.begin(), next_shape.end(), next_seg.begin_percent_, next_seg.end_percent_); - std::copy(partial_shape.begin(), partial_shape.end(), std::back_inserter(shape)); + if (partial_shape.front() == shape.back()) { + std::copy(partial_shape.begin()+1, partial_shape.end(), std::back_inserter(shape)); + } else { + std::copy(partial_shape.begin(), partial_shape.end(), std::back_inserter(shape)); + } } else { - std::copy(next_shape.begin(), next_shape.end(), std::back_inserter(shape)); + if (next_shape.front() == shape.back()) { + std::copy(next_shape.begin()+1, next_shape.end(), std::back_inserter(shape)); + } else { + std::copy(next_shape.begin(), next_shape.end(), std::back_inserter(shape)); + } } // Matched segment has been found. Return nullptr if this edge ends @@ -183,6 +191,7 @@ void create_geojson(std::queue& tilequeue, out << "{\"type\":\"FeatureCollection\",\"properties\":{" << "\"creation_time\":" << creation_date << "," << "\"creation_date\":\"" << date_str << "\"," + << "\"description\":\"" << tile_id << "\"," << "\"changeset_id\":" << osm_changeset_id << "},"; out << "\"features\":["; diff --git a/src/output/geojson.cpp b/src/output/geojson.cpp index c91ea87..5e0318d 100644 --- a/src/output/geojson.cpp +++ b/src/output/geojson.cpp @@ -155,15 +155,14 @@ void geojson::output_segment(const vb::merge::path &p) { } out << "{\"type\":\"Feature\",\"geometry\":"; - out << "{\"type\":\"MultiLineString\",\"coordinates\":["; + out << "{\"type\":\"LineString\",\"coordinates\":["; - bool first = true; + bool first_pt = true; bool oneway = false; bool drive_on_right = false; vb::RoadClass best_frc = vb::RoadClass::kServiceOther; + vm::PointLL prev_pt; for (auto edge_id : p.m_edges) { - if (first) { first = false; } else { out << ","; }; - const auto *tile = m_reader.GetGraphTile(edge_id); const auto* directededge = tile->directededge(edge_id); oneway = is_oneway(directededge); @@ -180,13 +179,14 @@ void geojson::output_segment(const vb::merge::path &p) { } // Serialize the shape - out << "["; - bool first_pt = true; for (const auto& pt : shape) { + if (pt == prev_pt) { + continue; + } if (first_pt) { first_pt = false; } else { out << ","; } out << "[" << pt.lng() << "," << pt.lat() << "]"; + prev_pt = pt; } - out << "]"; } // Add properties for this OSMLR segment @@ -219,6 +219,7 @@ void geojson::output_segment(const std::vector& shape, out << "{\"type\":\"FeatureCollection\",\"properties\":{" << "\"creation_time\":" << m_creation_date << "," << "\"creation_date\":\"" << m_date_str << "\"," + << "\"description\":\"" << tile_id << "\"," << "\"changeset_id\":" << m_osm_changeset_id << "},"; out << "\"features\":["; std::tie(tile_path_itr, std::ignore) = m_tile_path_ids.emplace(tile_id, 0); @@ -227,14 +228,13 @@ void geojson::output_segment(const std::vector& shape, } out << "{\"type\":\"Feature\",\"geometry\":"; - out << "{\"type\":\"MultiLineString\",\"coordinates\":["; - out << "["; + out << "{\"type\":\"LineString\",\"coordinates\":["; + bool first_pt = true; for (const auto pt : shape) { if (first_pt) { first_pt = false; } else { out << ","; } out << "[" << pt.lng() << "," << pt.lat() << "]"; } - out << "]"; vb::GraphId osmlr_id(tile_id.tileid(), tile_id.level(), tile_path_itr->second); bool first = true; From 17b6b2c8678047b9bb9e6be2d04802ce2b2edbc6 Mon Sep 17 00:00:00 2001 From: dnesbitt Date: Tue, 12 Sep 2017 10:22:11 -0400 Subject: [PATCH 2/3] Whitespace change --- src/geojson_osmlr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/geojson_osmlr.cpp b/src/geojson_osmlr.cpp index 065222d..e9a1d81 100644 --- a/src/geojson_osmlr.cpp +++ b/src/geojson_osmlr.cpp @@ -64,7 +64,7 @@ void output_segment(std::ostringstream& out, bool oneway = (edge->reverseaccess() & vb::kVehicularAccess) == 0; out << "]},\"properties\":{" - << "\"tile_id\":" << osmlr_id.tileid() << "," + << "\"tile_id\":" << osmlr_id.tileid() << "," << "\"level\":" << osmlr_id.level() << "," << "\"id\":" << osmlr_id.id() << "," << "\"osmlr_id\":" << osmlr_id.value << "," From 7bd4dce6a76070b0c0f25072c8927e8c8c88f9fa Mon Sep 17 00:00:00 2001 From: dnesbitt Date: Wed, 13 Sep 2017 10:11:08 -0400 Subject: [PATCH 3/3] Remove tile Id and level within each segment (can get this from the FeatureCollection properties). Update geojson_osmlr to compare count of segments found vs. those defined in the pbf OSMLR tile. --- src/geojson_osmlr.cpp | 33 ++++++++++++++++++++++++++++----- src/output/geojson.cpp | 18 ++++-------------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/geojson_osmlr.cpp b/src/geojson_osmlr.cpp index e9a1d81..3ef8acb 100644 --- a/src/geojson_osmlr.cpp +++ b/src/geojson_osmlr.cpp @@ -54,18 +54,14 @@ void output_segment(std::ostringstream& out, first = false; out << "{\"type\":\"Feature\",\"geometry\":"; out << "{\"type\":\"LineString\",\"coordinates\":["; - out << "["; bool first_pt = true; for (const auto pt : shape) { if (first_pt) { first_pt = false; } else { out << ","; } out << "[" << pt.lng() << "," << pt.lat() << "]"; } - out << "]"; bool oneway = (edge->reverseaccess() & vb::kVehicularAccess) == 0; out << "]},\"properties\":{" - << "\"tile_id\":" << osmlr_id.tileid() << "," - << "\"level\":" << osmlr_id.level() << "," << "\"id\":" << osmlr_id.id() << "," << "\"osmlr_id\":" << osmlr_id.value << "," << "\"best_frc\":\"" << vb::to_string(edge->classification()) << "\"," @@ -185,6 +181,17 @@ void create_geojson(std::queue& tilequeue, std::string date_str = std::string(mbstr); uint64_t osm_changeset_id = pbf_tile.changeset_id(); + // Create a map of valid Ids within this tile - we will record those that + // we find in the traffic-enabled Valhalla tile + uint32_t id = 0; + std::unordered_map segment_map; + for (const auto& entry : pbf_tile.entries()) { + if (entry.has_segment()) { + segment_map[id] = false; + } + id++; + } + // Create the GeoJSON output stream std::ostringstream out; out.precision(9); @@ -218,6 +225,7 @@ void create_geojson(std::queue& tilequeue, seg.ends_segment_ && seg.end_percent_ == 1.0f) { // Output full segment along this edge output_segment(out, first, seg.segment_id_, edge, shape); + segment_map[seg.segment_id_.id()] = true; } else { if (seg.starts_segment_) { if (seg.end_percent_ == 1.0f) { @@ -227,6 +235,7 @@ void create_geojson(std::queue& tilequeue, ; } output_segment(out, first, seg.segment_id_, first_edge, shape); + segment_map[seg.segment_id_.id()] = true; } else { // Should not see partial, single edges that are not part of a chunk LOG_ERROR("Single partial segment starts on this edge but does not use entire edge?"); @@ -243,6 +252,7 @@ void create_geojson(std::queue& tilequeue, // edge for this segment auto partial_shape = vm::trim_polyline(shape.begin(), shape.end(), seg.begin_percent_, seg.end_percent_); output_segment(out, first, seg.segment_id_, edge, partial_shape); + segment_map[seg.segment_id_.id()] = true; } else { // THIS SHOULD NOT OCCUR! LOG_ERROR("Chunk that does not begin and end a segment"); @@ -254,6 +264,19 @@ void create_geojson(std::queue& tilequeue, // Output to file out << "]}"; writer.write_to(tile_id, out.str()); + + // Log statistics for this tile + uint32_t found = 0; + for (const auto& seg : segment_map) { + if (seg.second) { + found++; + } + } + if (found != segment_map.size()) { + LOG_INFO("Tile: " + std::to_string(tile_id.level()) + "/" + std::to_string(tile_id.tileid()) + + " Found " + std::to_string(found) + " of " + std::to_string(segment_map.size()) + + " OSMLR segments"); + } } } @@ -370,7 +393,7 @@ int main(int argc, char** argv) { thread->join(); } /* - // Check all of the outcomes, to see about maximum density (km/km2) + // Check all of the outcomes enhancer_stats stats{std::numeric_limits::min(), 0}; for (auto& result : results) { // If something bad went down this will rethrow it diff --git a/src/output/geojson.cpp b/src/output/geojson.cpp index 5e0318d..dca8bea 100644 --- a/src/output/geojson.cpp +++ b/src/output/geojson.cpp @@ -192,8 +192,6 @@ void geojson::output_segment(const vb::merge::path &p) { // Add properties for this OSMLR segment vb::GraphId osmlr_id(tile_id.tileid(), tile_id.level(), tile_path_itr->second); out << "]},\"properties\":{" - << "\"tile_id\":" << tile_id.tileid() << "," - << "\"level\":" << tile_id.level() << "," << "\"id\":" << tile_path_itr->second << "," << "\"osmlr_id\":" << osmlr_id.value << "," << "\"best_frc\":\"" << vb::to_string(best_frc) << "\"," @@ -238,21 +236,13 @@ void geojson::output_segment(const std::vector& shape, vb::GraphId osmlr_id(tile_id.tileid(), tile_id.level(), tile_path_itr->second); bool first = true; - bool oneway = is_oneway(edge); - bool drive_on_right = edge->drive_on_right(); - vb::RoadClass best_frc = edge->classification(); out << "]},\"properties\":{" - << "\"tile_id\":" << tile_id.tileid() << "," - << "\"level\":" << tile_id.level() << "," << "\"id\":" << tile_path_itr->second << "," << "\"osmlr_id\":" << osmlr_id.value << "," - << "\"best_frc\":\"" << vb::to_string(best_frc) << "\"," - << "\"oneway\":" << oneway << "," - << "\"drive_on_right\":" << drive_on_right << "," - << "\"original_edges\":\""; - - out << edgeid; - out << "\"}}"; + << "\"best_frc\":\"" << vb::to_string(edge->classification()) << "\"," + << "\"oneway\":" << is_oneway(edge) << "," + << "\"drive_on_right\":" << edge->drive_on_right(); + out << "}}"; m_writer.write_to(tile_id, out.str()); tile_path_itr->second += 1;