Skip to content

Commit

Permalink
🐛 Fix wrong order of lng lat in h3 functions and add a feature to exc…
Browse files Browse the repository at this point in the history
…lude the same hexagon returned from two consecutive observations
  • Loading branch information
cyang-kth committed Jul 8, 2021
1 parent 6b43a16 commit 9eaa303
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 22 deletions.
2 changes: 2 additions & 0 deletions python/fmm.i
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
%ignore operator<<(std::ostream& os, const LineString& rhs);
%ignore FMM::MM::STMATCHConfig::print() const;
%ignore FMM::MM::FastMapMatchConfig::print() const;
%ignore FMM::MM::H3MMConfig::print() const;
%ignore FMM::MM::H3MatchResultConfig::print() const;
%ignore FMM::CONFIG::GPSConfig::print() const;
%ignore FMM::CONFIG::ResultConfig::print() const;

Expand Down
1 change: 1 addition & 0 deletions src/mm/h3mm/h3_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace FMM{
namespace MM{

typedef unsigned long long HexIndex;

struct H3MatchResult {
int traj_id;
std::vector<HexIndex> hexs;
Expand Down
25 changes: 15 additions & 10 deletions src/mm/h3mm/h3_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,40 @@ std::string hexs2wkt(const std::vector<HexIndex> &hexs, int precision=12){
oss << "((";
h3ToGeoBoundary(hexs[i], &boundary);
for (int v = 0; v < boundary.numVerts; v++) {
oss << std::setprecision(precision) << radsToDegs(boundary.verts[v].lat)
<< " " << radsToDegs(boundary.verts[v].lon) << ",";
oss << std::setprecision(precision) << radsToDegs(boundary.verts[v].lon)
<< " " << radsToDegs(boundary.verts[v].lat) << ",";
}
oss << std::setprecision(precision) << radsToDegs(boundary.verts[0].lat)
<< " " << radsToDegs(boundary.verts[0].lon);
oss << std::setprecision(precision) << radsToDegs(boundary.verts[0].lon)
<< " " << radsToDegs(boundary.verts[0].lat);
oss << "))" << (i<hexs.size()-1?",":"");
}
oss << ")";
return oss.str();
};

HexIndex xy2hex(double px, double py, int level){
HexIndex latlng2hex(double lat, double lng, int level){
GeoCoord location;
setGeoDegs(&location, px, py);
setGeoDegs(&location, lat, lng);
HexIndex indexed = geoToH3(&location,level);
return (HexIndex) indexed;
};

// The x is lng and y is the lat
HexIndex xy2hex(double x, double y, int level){
return latlng2hex(y,x,level);
};

std::string hex2wkt(const HexIndex &index, int precision=12){
std::ostringstream oss;
GeoBoundary boundary;
oss << "POLYGON(";
h3ToGeoBoundary(index, &boundary);
for (int v = 0; v < boundary.numVerts; v++) {
oss << std::setprecision(precision) << radsToDegs(boundary.verts[v].lat)
<< " " << radsToDegs(boundary.verts[v].lon) << ",";
oss << std::setprecision(precision) << radsToDegs(boundary.verts[v].lon)
<< " " << radsToDegs(boundary.verts[v].lat) << ",";
}
oss << std::setprecision(precision) << radsToDegs(boundary.verts[0].lat)
<< " " << radsToDegs(boundary.verts[0].lon);
oss << std::setprecision(precision) << radsToDegs(boundary.verts[0].lon)
<< " " << radsToDegs(boundary.verts[0].lat);
oss << ")";
return oss.str();
};
Expand Down
21 changes: 16 additions & 5 deletions src/mm/h3mm/h3mm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ struct H3MMConfig {
h3level = h3level_arg;
interpolate = interpolate_arg;
};
int h3level;
bool interpolate;
bool validate() const {
return (h3level<=15 && h3level>=0);
};
std::string to_string() const{
std::ostringstream oss;
oss << "h3 level : " << h3level << "\n";
oss << "interpolate : " << (interpolate?"true":"false") << "\n";
return oss.str();
};
void print() const {
SPDLOG_INFO("h3level: {} ",h3level);
SPDLOG_INFO("interpolate: {} ",(interpolate?"true":"false"));
Expand Down Expand Up @@ -56,6 +60,8 @@ struct H3MMConfig {
oss<<"--h3level (optional) <int>: level of hex (15)\n";
oss<<"--interpolate (optional): if specified, interpolate between points\n";
};
int h3level;
bool interpolate;
};


Expand Down Expand Up @@ -119,12 +125,17 @@ class H3MM {
}
} else {
SPDLOG_DEBUG("No interpolate");
HexIndex prev_hex=0;
for (int i = 0; i < NumberPoints; ++i) {
// SPDLOG_DEBUG("Search candidates for point index {}",i);
// Construct a bounding boost_box
double px = traj.geom.get_x(i);
double py = traj.geom.get_y(i);
hexs.push_back(xy2hex(px,py,config.h3level));
HexIndex hex = xy2hex(px,py,config.h3level);
if (i==0 || hex!=prev_hex){
hexs.push_back(hex);
}
prev_hex = hex;
}
}
} else {
Expand All @@ -135,8 +146,8 @@ class H3MM {
};
static std::string match_gps_file(
const FMM::CONFIG::GPSConfig &gps_config,
const H3MMConfig &config,
const H3MatchResultConfig &output_config,
const FMM::MM::H3MMConfig &config,
const FMM::MM::H3MatchResultConfig &output_config,
bool use_omp = true){
std::ostringstream oss;
std::string status;
Expand Down
10 changes: 5 additions & 5 deletions src/mm/h3mm/h3mm_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ class H3MMAppConfig
};

void print() const {
SPDLOG_INFO("---- Print configuration ----");
SPDLOG_INFO("---- Print configuration ----")
gps_config.print();
result_config.print();
h3mm_config.print();
SPDLOG_INFO("Log level {}", UTIL::LOG_LEVESLS[log_level]);
SPDLOG_INFO("Step {}", step);
SPDLOG_INFO("Use omp {}", (use_omp ? "true" : "false"));
SPDLOG_INFO("---- Print configuration done ----");
SPDLOG_INFO("Log level {}",UTIL::LOG_LEVESLS[log_level])
SPDLOG_INFO("Step {}",step)
SPDLOG_INFO("Use omp {}",(use_omp ? "true" : "false"))
SPDLOG_INFO("---- Print configuration done ----")
};

bool validate() const {
Expand Down
13 changes: 11 additions & 2 deletions src/mm/h3mm/h3mm_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ struct H3MatchResultConfig {
file = "";
write_geom = false;
};
H3MatchResultConfig(const std::string &filename, bool write_geom_arg) :
file(filename),write_geom(write_geom_arg){
};
std::string file; /**< Output file to write the result */
bool write_geom;
/**
* Check the validation of the configuration
* @return true if valid otherwise false
*/
bool validate() const {
if (file.empty()){
if (file.empty()) {
SPDLOG_CRITICAL("Output file not specified");
return false;
}
Expand All @@ -42,7 +45,13 @@ struct H3MatchResultConfig {
SPDLOG_INFO("File: {}",file);
SPDLOG_INFO("Write geom: {}",write_geom);
};

std::string to_string() const{
std::ostringstream oss;
oss << "H3MatchResultConfig\n";
oss << "result file : " << file << "\n";
oss << "write geom : " << (write_geom?"true":"false") << "\n";
return oss.str();
};
/**
* Load result configuration from argument data
* @param arg_data argument data generated by reading arguments
Expand Down

0 comments on commit 9eaa303

Please sign in to comment.