Skip to content

Commit

Permalink
Done with supporting matching gps data stored in file in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
cyang-kth committed Jul 20, 2020
1 parent d173beb commit 982834e
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 45 deletions.
123 changes: 87 additions & 36 deletions example/notebook/fmm_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,7 +25,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -44,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -70,14 +70,14 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"k = 4\n",
"radius = 0.4\n",
"gps_error = 0.5\n",
"config = FastMapMatchConfig(k,radius,gps_error)"
"fmm_config = FastMapMatchConfig(k,radius,gps_error)"
]
},
{
Expand All @@ -89,7 +89,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -98,16 +98,16 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"result = model.match_wkt(wkt,config)"
"result = model.match_wkt(wkt,fmm_config)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -117,8 +117,8 @@
"Matched path: [8, 11, 13, 18, 20, 24]\n",
"Matched edge for each point: [8, 11, 18, 18, 20, 24]\n",
"Matched edge index [0, 1, 3, 3, 4, 5]\n",
"Matched geometry: LINESTRING(0.200812 2,1 2,2 2,3 2,3 3,4 3,4 2.62338)\n",
"Matched point LINESTRING(0.200812 2,1.44262 2,3 2.16066,3 2.71038,3.70872 3,4 2.62338)\n"
"Matched geometry: LINESTRING(0.20081215 2,1 2,2 2,3 2,3 3,4 3,4 2.6233757)\n",
"Matched point LINESTRING(0.20081215 2,1.4426201 2,3 2.1606638,3 2.7103814,3.7087218 3,4 2.6233757)\n"
]
}
],
Expand All @@ -139,7 +139,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -148,49 +148,87 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"gps_file = \"../data/trips.csv\"\n",
"id_name = \"id\"\n",
"geom_name = \"geom\"\n",
"x_name = \"\"\n",
"y_name = \"\"\n",
"timestamp_name = \"\"\n",
"gps_point = False\n",
"input_config = GPSConfig()\n",
"input_config.file=gps_file\n",
"gps_file,id_name,geom_name,x_name,y_name,timestamp_name,gps_point"
"input_config.file = \"../data/trips.csv\"\n",
"input_config.id = \"id\""
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"gps file : ../data/trips.csv\n",
"id column : id\n",
"geom column : geom\n",
"timestamp column : timestamp\n",
"x column : x\n",
"y column : y\n",
"GPS point : false\n",
"\n"
]
}
],
"source": [
"print input_config.to_string()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Result file : ../data/mr.txt\n",
"Output fields: opath cpath mgeom \n"
]
}
],
"source": [
"result_config = ResultConfig()\n",
"result_config.file = \"../data/mr.txt\"\n",
"result_config.output_config.write_opath = True\n",
"print result_config.to_string()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"output_config = ResultConfig()"
"status = model.match_gps_file(input_config, result_config, fmm_config)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"Time takes 0.05 seconds\n",
"Total points 17 matched 17\n",
"Map match speed 340 points/s \n",
"\n"
]
}
],
"source": [
"GPSConfig."
"print status"
]
},
{
Expand All @@ -217,7 +255,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.15"
"version": "2.7.16"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
}
},
"nbformat": 4,
Expand Down
2 changes: 2 additions & 0 deletions python/fmm.i
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
%ignore operator<<(std::ostream& os, const LineString& rhs);
%ignore FMM::MM::STMATCHConfig::print() const;
%ignore FMM::MM::FastMapMatchConfig::print() const;
%ignore FMM::CONFIG::GPSConfig::print() const;
%ignore FMM::CONFIG::ResultConfig::print() const;

%{
/* Put header files here or function declarations like below */
Expand Down
12 changes: 12 additions & 0 deletions src/config/gps_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ void FMM::CONFIG::GPSConfig::print() const{
}
};

std::string FMM::CONFIG::GPSConfig::to_string() const{
std::ostringstream oss;
oss << "gps file : " << file << "\n";
oss << "id column : " << id << "\n";
oss << "geom column : " << geom << "\n";
oss << "timestamp column : " << timestamp << "\n";
oss << "x column : " << x << "\n";
oss << "y column : " << y << "\n";
oss << "GPS point : " << (gps_point?"true":"false") << "\n";
return oss.str();
};

FMM::CONFIG::GPSConfig FMM::CONFIG::GPSConfig::load_from_xml(
const boost::property_tree::ptree &xml_data){
GPSConfig config;
Expand Down
19 changes: 10 additions & 9 deletions src/config/gps_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ namespace CONFIG {
* GPS configuration class for reading data from a file.
*/
struct GPSConfig {
GPSConfig(){};
GPSConfig(const std::string &file_arg,
const std::string &id_arg,
const std::string &geom_arg,
const std::string &x_arg,
const std::string &y_arg,
const std::string &timestamp_arg,
bool gps_point_arg) :
GPSConfig(const std::string &file_arg="",
const std::string &id_arg="id",
const std::string &geom_arg="geom",
const std::string &x_arg="x",
const std::string &y_arg="y",
const std::string &timestamp_arg="timestamp",
bool gps_point_arg = false) :
file(file_arg), id(id_arg), geom(geom_arg),
x(x_arg),y(y_arg),timestamp(timestamp_arg),
gps_point(gps_point_arg)
Expand All @@ -42,7 +41,7 @@ struct GPSConfig {
std::string x; /**< x field/column name */
std::string y; /**< y field/column name */
std::string timestamp; /**< timestamp field/column name */
bool gps_point = false; /**< gps point stored or not */
bool gps_point; /**< gps point stored or not */
/**
* Validate the GPS configuration for file existence, parameter validation
* @return true if validate success, otherwise false returned
Expand All @@ -60,6 +59,8 @@ struct GPSConfig {
* format.
*/
int get_gps_format() const;

std::string to_string() const;
/**
* Load GPSConfig from XML data.
*
Expand Down
33 changes: 33 additions & 0 deletions src/config/result_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,39 @@ void FMM::CONFIG::ResultConfig::print() const {
SPDLOG_INFO("Fields: {}",ss.str());
};

std::string FMM::CONFIG::ResultConfig::to_string() const{
std::ostringstream oss;
oss << "Result file : " << file << "\n";
oss << "Output fields: ";
if (output_config.write_opath)
oss << "opath ";
if (output_config.write_pgeom)
oss << "pgeom ";
if (output_config.write_offset)
oss << "offset ";
if (output_config.write_error)
oss << "error ";
if (output_config.write_spdist)
oss << "spdist ";
if (output_config.write_cpath)
oss << "cpath ";
if (output_config.write_tpath)
oss << "tpath ";
if (output_config.write_mgeom)
oss << "mgeom ";
if (output_config.write_ep)
oss << "ep ";
if (output_config.write_tp)
oss << "tp ";
if (output_config.write_length)
oss << "length ";
if (output_config.write_duration)
oss << "duration ";
if (output_config.write_speed)
oss << "speed ";
return oss.str();
};

FMM::CONFIG::ResultConfig FMM::CONFIG::ResultConfig::load_from_xml(
const boost::property_tree::ptree &xml_data) {
ResultConfig config;
Expand Down
1 change: 1 addition & 0 deletions src/config/result_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct ResultConfig {
* Print the configuration information
*/
void print() const;
std::string to_string() const;
/**
* Parse a string separated by , into a set of strings.
*
Expand Down

0 comments on commit 982834e

Please sign in to comment.