Skip to content

Commit

Permalink
Merge pull request #49 from opentraffic/gk
Browse files Browse the repository at this point in the history
added logic for updates
  • Loading branch information
gknisely authored Nov 13, 2017
2 parents e2e4493 + dac0a32 commit 295e8a8
Show file tree
Hide file tree
Showing 12 changed files with 505 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ src/proto/%.pb.cc: proto/%.proto
bin_PROGRAMS = osmlr geojson_osmlr
osmlr_SOURCES = src/osmlr.cpp src/proto/segment.pb.cc src/proto/tile.pb.cc src/output/output.cpp src/output/geojson.cpp src/output/tiles.cpp src/util/tile_writer.cpp
osmlr_CPPFLAGS = $(DEPS_CFLAGS) $(VALHALLA_DEPS_CFLAGS) @BOOST_CPPFLAGS@
osmlr_LDADD = $(DEPS_LIBS) $(VALHALLA_DEPS_LIBS) $(BOOST_PROGRAM_OPTIONS_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_THREAD_LIB)
osmlr_LDADD = $(DEPS_LIBS) $(VALHALLA_DEPS_LIBS) $(BOOST_PROGRAM_OPTIONS_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_REGEX_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_THREAD_LIB)
geojson_osmlr_SOURCES = src/geojson_osmlr.cpp src/proto/segment.pb.cc src/proto/tile.pb.cc src/util/tile_writer.cpp
geojson_osmlr_CPPFLAGS = $(DEPS_CFLAGS) $(VALHALLA_DEPS_CFLAGS) @BOOST_CPPFLAGS@
geojson_osmlr_LDADD = $(DEPS_LIBS) $(VALHALLA_DEPS_LIBS) $(BOOST_PROGRAM_OPTIONS_LIB) $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_THREAD_LIB)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ LD_LIBRARY_PATH=/usr/lib:/usr/local/lib osmlr -m 1 -T ${PWD}/osmlr_tiles valhall
# -j 2 uses two threads for association process (use more or fewer as available cores permit)
valhalla_associate_segments -t ${PWD}/osmlr_tiles -j 2 --config valhalla.json

# rebuild tar with traffic segement associated tiles
#rebuild tar with traffic segement associated tiles
find valhalla_tiles | sort -n | tar rf tiles.tar --no-recursion -T -

#Update OSMLR segments.
This will copy your existing pbf and geojson tiles to their equivalent output directories and update the tiles as needed. Features will be removed add added from the feature collection in the geojson tiles. Moreover, segements that no longer exist in the valhalla tiles will be cleared and a deletion date will be set.
./osmlr -u -m 2 -f 256 -P ./<old_tiles>/pbf -G ./<old_tiles>/geojson -J ./<new_tiles>/geojson -T ./<new_tiles>/pbf --config valhalla.json

#HAVE FUN!
```

Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ AX_BOOST_PROGRAM_OPTIONS
AX_BOOST_SYSTEM
AX_BOOST_THREAD
AX_BOOST_FILESYSTEM
AX_BOOST_REGEX
AC_SUBST(BOOST_CPPFLAGS, "$BOOST_CPPFLAGS -DBOOST_SPIRIT_THREADSAFE -DBOOST_NO_CXX11_SCOPED_ENUMS")

# check pkg-config dependencies
Expand Down
6 changes: 5 additions & 1 deletion include/osmlr/output/geojson.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace output {

struct geojson : public output {
geojson(valhalla::baldr::GraphReader &reader, std::string base_dir, size_t max_fds,
time_t creation_date, const uint64_t osm_changeset_id);
time_t creation_date, const uint64_t osm_changeset_id,
const std::unordered_map<valhalla::baldr::GraphId, uint32_t> tile_index);
virtual ~geojson();

void add_path(const valhalla::baldr::merge::path &);
Expand All @@ -21,11 +22,14 @@ struct geojson : public output {
const valhalla::baldr::DirectedEdge* edge,
const valhalla::baldr::GraphId& edgeid);
void split_path(const valhalla::baldr::merge::path& p, const uint32_t total_length);
std::unordered_map<valhalla::baldr::GraphId, uint32_t> update_tiles(
const std::vector<std::string>& tiles);
void finish();

private:
time_t m_creation_date;
std::string m_date_str;
std::unordered_map<valhalla::baldr::GraphId, uint32_t> m_tile_index;
uint64_t m_osm_changeset_id;
valhalla::baldr::GraphReader &m_reader;
util::tile_writer m_writer;
Expand Down
2 changes: 2 additions & 0 deletions include/osmlr/output/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct output {
virtual ~output();

virtual void add_path(const valhalla::baldr::merge::path &) = 0;
virtual std::unordered_map<valhalla::baldr::GraphId, uint32_t> update_tiles(
const std::vector<std::string>& tiles) = 0;
virtual void finish() = 0;
};

Expand Down
2 changes: 2 additions & 0 deletions include/osmlr/output/tiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct tiles : public output {
const valhalla::baldr::GraphId& edgeid,
const bool start_at_node, const bool end_at_node);
void output_segment(std::vector<lrp>& lrps, const valhalla::baldr::GraphId& tile_id);
std::unordered_map<valhalla::baldr::GraphId, uint32_t> update_tiles(
const std::vector<std::string>& tiles);
void finish();

private:
Expand Down
2 changes: 1 addition & 1 deletion include/osmlr/util/tile_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace util {
struct tile_writer {
tile_writer(std::string base_dir, std::string suffix, size_t max_fds);
void write_to(valhalla::baldr::GraphId tile_id, const std::string &data);
std::string get_name_for_tile(valhalla::baldr::GraphId tile_id);
void close_all();

private:
std::string get_name_for_tile(valhalla::baldr::GraphId tile_id);
int get_fd_for(valhalla::baldr::GraphId tile_id);
int make_fd_for(valhalla::baldr::GraphId tile_id);
void evict_last_fd();
Expand Down
111 changes: 111 additions & 0 deletions m4/ax_boost_regex.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_boost_regex.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_BOOST_REGEX
#
# DESCRIPTION
#
# Test for Regex library from the Boost C++ libraries. The macro requires
# a preceding call to AX_BOOST_BASE. Further documentation is available at
# <http://randspringer.de/boost/index.html>.
#
# This macro calls:
#
# AC_SUBST(BOOST_REGEX_LIB)
#
# And sets:
#
# HAVE_BOOST_REGEX
#
# LICENSE
#
# Copyright (c) 2008 Thomas Porschberg <[email protected]>
# Copyright (c) 2008 Michael Tindal
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 22

AC_DEFUN([AX_BOOST_REGEX],
[
AC_ARG_WITH([boost-regex],
AS_HELP_STRING([--with-boost-regex@<:@=special-lib@:>@],
[use the Regex library from boost - it is possible to specify a certain library for the linker
e.g. --with-boost-regex=boost_regex-gcc-mt-d-1_33_1 ]),
[
if test "$withval" = "no"; then
want_boost="no"
elif test "$withval" = "yes"; then
want_boost="yes"
ax_boost_user_regex_lib=""
else
want_boost="yes"
ax_boost_user_regex_lib="$withval"
fi
],
[want_boost="yes"]
)
if test "x$want_boost" = "xyes"; then
AC_REQUIRE([AC_PROG_CC])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_CACHE_CHECK(whether the Boost::Regex library is available,
ax_cv_boost_regex,
[AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/regex.hpp>
]],
[[boost::regex r(); return 0;]])],
ax_cv_boost_regex=yes, ax_cv_boost_regex=no)
AC_LANG_POP([C++])
])
if test "x$ax_cv_boost_regex" = "xyes"; then
AC_DEFINE(HAVE_BOOST_REGEX,,[define if the Boost::Regex library is available])
BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
if test "x$ax_boost_user_regex_lib" = "x"; then
for libextension in `ls $BOOSTLIBDIR/libboost_regex*.so* $BOOSTLIBDIR/libboost_regex*.dylib* $BOOSTLIBDIR/libboost_regex*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_regex.*\)\.so.*$;\1;' -e 's;^lib\(boost_regex.*\)\.dylib.*;\1;' -e 's;^lib\(boost_regex.*\)\.a.*$;\1;'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_REGEX_LIB="-l$ax_lib"; AC_SUBST(BOOST_REGEX_LIB) link_regex="yes"; break],
[link_regex="no"])
done
if test "x$link_regex" != "xyes"; then
for libextension in `ls $BOOSTLIBDIR/boost_regex*.dll* $BOOSTLIBDIR/boost_regex*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_regex.*\)\.dll.*$;\1;' -e 's;^\(boost_regex.*\)\.a.*$;\1;'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_REGEX_LIB="-l$ax_lib"; AC_SUBST(BOOST_REGEX_LIB) link_regex="yes"; break],
[link_regex="no"])
done
fi
else
for ax_lib in $ax_boost_user_regex_lib boost_regex-$ax_boost_user_regex_lib; do
AC_CHECK_LIB($ax_lib, main,
[BOOST_REGEX_LIB="-l$ax_lib"; AC_SUBST(BOOST_REGEX_LIB) link_regex="yes"; break],
[link_regex="no"])
done
fi
if test "x$ax_lib" = "x"; then
AC_MSG_ERROR(Could not find a version of the Boost::Regex library!)
fi
if test "x$link_regex" != "xyes"; then
AC_MSG_ERROR(Could not link against $ax_lib !)
fi
fi
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
fi
])
2 changes: 2 additions & 0 deletions src/geojson_osmlr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ void create_geojson(std::queue<vb::GraphId>& tilequeue,
vb::GraphReader reader(hierarchy_properties);

// Create a tile writer
lock.lock();
util::tile_writer writer(output_dir, "json", 1);
lock.unlock();

// Iterate through the tiles in the queue and perform enhancements
while (true) {
Expand Down
Loading

0 comments on commit 295e8a8

Please sign in to comment.