-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
651b249
commit ef7e9bc
Showing
8 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
|
||
#include "geo/latlng.h" | ||
|
||
struct tg_geom; | ||
|
||
namespace motis::odm { | ||
|
||
struct bounds { | ||
explicit bounds(std::filesystem::path const&); | ||
~bounds(); | ||
|
||
bool contains(geo::latlng const&) const; | ||
|
||
tg_geom* geom_{nullptr}; | ||
}; | ||
|
||
} // namespace motis::odm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "motis/odm/bounds.h" | ||
|
||
#include "tg.h" | ||
|
||
#include "fmt/std.h" | ||
|
||
#include "utl/verify.h" | ||
|
||
#include "cista/mmap.h" | ||
|
||
namespace fs = std::filesystem; | ||
|
||
namespace motis::odm { | ||
|
||
bounds::bounds(fs::path const& p) { | ||
auto const f = | ||
cista::mmap{p.generic_string().c_str(), cista::mmap::protection::READ}; | ||
|
||
geom_ = tg_parse_geojsonn(f.view().data(), f.size()); | ||
|
||
if (tg_geom_error(geom_)) { | ||
const char* err = tg_geom_error(geom_); | ||
fmt::println("Error parsing ODM Bounds GeoJSON: {}", err); | ||
tg_geom_free(geom_); | ||
throw utl::fail("unable to parse {}: {}", p, err); | ||
} | ||
|
||
return; | ||
} | ||
|
||
bounds::~bounds() { tg_geom_free(geom_); } | ||
|
||
bool bounds::contains(geo::latlng const& x) const { | ||
auto const point = tg_geom_new_point(tg_point{x.lng(), x.lat()}); | ||
auto const result = tg_geom_within(point, geom_); | ||
tg_geom_free(point); | ||
return result; | ||
} | ||
|
||
} // namespace motis::odm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters