├── tools ├── query_grid │ ├── autoscan.log │ ├── grid_info │ ├── common.h │ ├── Makefile.am │ ├── configure.ac │ ├── common.cpp │ ├── test.cpp │ ├── query_grid.h │ ├── autom4te.cache │ │ └── requests │ ├── missing │ ├── compile │ └── .deps │ │ ├── test.Po │ │ └── common.Po ├── distill_roads │ ├── road_list │ └── distill_roads.php ├── bash │ ├── get_deviation │ │ ├── deviation │ │ ├── fake.pos │ │ ├── real.pos │ │ └── get_deviation.sh │ ├── fix_road_network │ │ ├── deviation │ │ └── fix_road_network.sh │ └── gen_segs │ │ ├── short.sh │ │ └── gen_segs.sh ├── gps_preprocess │ ├── stamp-h1 │ ├── common.h │ ├── Makefile.am │ ├── configure.ac │ ├── test.cpp │ ├── config.h.in │ ├── config.h │ ├── common.cpp │ ├── gps_preprocess.h │ └── gps_preprocess.cpp ├── distill_position │ ├── num_list │ └── distill_position.php ├── gen_grid │ ├── common.h │ ├── Makefile.am │ ├── test.cpp │ ├── configure.ac │ ├── common.cpp │ └── gen_grid.h └── gen_distance_table │ ├── end_lng_table.txt │ ├── start_lng_table.txt │ ├── Makefile.am │ ├── gen_distance_table.cpp │ ├── configure.in │ ├── lat_table.txt │ ├── gen_distance_table.h │ └── .deps │ └── gen_distance_table.Po ├── src ├── iter-map-matching │ ├── stamp-h1 │ ├── iter_map_matcher │ ├── common.h │ ├── Makefile.am │ ├── configure.ac │ ├── test.cpp │ ├── config.h.in │ ├── common.cpp │ ├── config.h │ ├── iter_matcher.h │ └── iter_matcher.cpp ├── simple-map-matching │ ├── stamp-h1 │ ├── grid_info │ ├── simple_map_matcher │ ├── common.h │ ├── Makefile.am │ ├── configure.ac │ ├── config.h.in │ ├── config.h │ ├── common.cpp │ ├── test.cpp │ ├── simple_matcher.h │ └── simple_matcher.cpp ├── map-index │ ├── grid_info │ ├── common.h │ ├── gen_segs.cpp │ ├── Makefile.am │ ├── error.h │ ├── configure.ac │ ├── debug.h │ ├── common.cpp │ ├── logger.h │ ├── serve.cpp │ ├── map_index.h │ ├── query_grid.cpp │ ├── map_index.cpp │ └── gen_grid.cpp └── robust-map-matching │ └── robust-map-matching.cpp ├── papers ├── Multi-track Map Matching.pdf ├── ACM SIGSPATIAL GIS Cup 2012.pdf ├── Quick Map Matching Using Multi-Core CPUs.pdf ├── Concurrent and Robust Topological Map Matching.pdf ├── A Three-step General Map Matching Method in the GIS.pdf ├── A Map Matching Method for GPS Based Real-Time Vehicle Location.pdf └── A GRID-BASED SPATIAL INDEX FOR MATCHING BETWEEN MOVING VEHICLES AND ROAD NETWORK IN A REAL-TIME ENVIRONMENT.pdf ├── datasets ├── 14099164_1.json ├── dump184.json ├── dump10.json └── 14096444_1.json ├── TODO.md ├── .gitignore └── README.md /tools/query_grid/autoscan.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/distill_roads/road_list: -------------------------------------------------------------------------------- 1 | [100041] 2 | -------------------------------------------------------------------------------- /src/iter-map-matching/stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for config.h 2 | -------------------------------------------------------------------------------- /tools/bash/get_deviation/deviation: -------------------------------------------------------------------------------- 1 | 0.006558 0.005791 2 | -------------------------------------------------------------------------------- /tools/gps_preprocess/stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for config.h 2 | -------------------------------------------------------------------------------- /src/simple-map-matching/stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for config.h 2 | -------------------------------------------------------------------------------- /tools/bash/fix_road_network/deviation: -------------------------------------------------------------------------------- 1 | 0.006558 0.005791 2 | -------------------------------------------------------------------------------- /tools/distill_position/num_list: -------------------------------------------------------------------------------- 1 | [184, 185, 186, 187, 188, 189, 190, 191] 2 | -------------------------------------------------------------------------------- /tools/bash/get_deviation/fake.pos: -------------------------------------------------------------------------------- 1 | 116.683575 39.828715 2 | 116.679325 39.825714 3 | -------------------------------------------------------------------------------- /tools/bash/get_deviation/real.pos: -------------------------------------------------------------------------------- 1 | 116.690142 39.834464 2 | 116.685875 39.831548 3 | -------------------------------------------------------------------------------- /tools/bash/gen_segs/short.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | bash ./gen_segs geos.ext segs.ext 4 | 5 | -------------------------------------------------------------------------------- /papers/Multi-track Map Matching.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifulong/map-matching-algorithm/HEAD/papers/Multi-track Map Matching.pdf -------------------------------------------------------------------------------- /src/map-index/grid_info: -------------------------------------------------------------------------------- 1 | start_lng:115.25 2 | start_lat:39.26 3 | end_lng:117.4 4 | end_lat:41.1 5 | lng_gap:0.002 6 | lat_gap:0.002 7 | -------------------------------------------------------------------------------- /tools/query_grid/grid_info: -------------------------------------------------------------------------------- 1 | start_lng:115.25 2 | start_lat:39.26 3 | end_lng:117.4 4 | end_lat:41.1 5 | lng_gap:0.005 6 | lat_gap:0.005 7 | -------------------------------------------------------------------------------- /papers/ACM SIGSPATIAL GIS Cup 2012.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifulong/map-matching-algorithm/HEAD/papers/ACM SIGSPATIAL GIS Cup 2012.pdf -------------------------------------------------------------------------------- /src/iter-map-matching/iter_map_matcher: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifulong/map-matching-algorithm/HEAD/src/iter-map-matching/iter_map_matcher -------------------------------------------------------------------------------- /src/simple-map-matching/grid_info: -------------------------------------------------------------------------------- 1 | start_lng:115.25 2 | start_lat:39.26 3 | end_lng:117.4 4 | end_lat:41.1 5 | lng_gap:0.002 6 | lat_gap:0.002 7 | -------------------------------------------------------------------------------- /src/simple-map-matching/simple_map_matcher: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifulong/map-matching-algorithm/HEAD/src/simple-map-matching/simple_map_matcher -------------------------------------------------------------------------------- /tools/gen_grid/common.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | vector SplitBySep(string str, string sep); 6 | void EchoRunning(); 7 | 8 | -------------------------------------------------------------------------------- /tools/query_grid/common.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | vector SplitBySep(string str, string sep); 6 | void EchoRunning(); 7 | 8 | -------------------------------------------------------------------------------- /papers/Quick Map Matching Using Multi-Core CPUs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifulong/map-matching-algorithm/HEAD/papers/Quick Map Matching Using Multi-Core CPUs.pdf -------------------------------------------------------------------------------- /papers/Concurrent and Robust Topological Map Matching.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifulong/map-matching-algorithm/HEAD/papers/Concurrent and Robust Topological Map Matching.pdf -------------------------------------------------------------------------------- /src/map-index/common.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | vector SplitBySep(string str, string sep); 6 | void EchoRunning(); 7 | 8 | -------------------------------------------------------------------------------- /datasets/14099164_1.json: -------------------------------------------------------------------------------- 1 | [{"lat":"40.004864","lng":"116.410818","gps_type":"baidu","gps_time":1418129582000,"provider":"network","accuracy":2000,"status":1,"milli_timestamp":1418129582.388}] -------------------------------------------------------------------------------- /papers/A Three-step General Map Matching Method in the GIS.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifulong/map-matching-algorithm/HEAD/papers/A Three-step General Map Matching Method in the GIS.pdf -------------------------------------------------------------------------------- /papers/A Map Matching Method for GPS Based Real-Time Vehicle Location.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifulong/map-matching-algorithm/HEAD/papers/A Map Matching Method for GPS Based Real-Time Vehicle Location.pdf -------------------------------------------------------------------------------- /src/map-index/gen_segs.cpp: -------------------------------------------------------------------------------- 1 | #include "map_index.h" 2 | 3 | void MapIndex::genSegs(string geos_file) 4 | { 5 | return ; 6 | } 7 | 8 | void MapIndex::dumpSegs(string segs_file) 9 | { 10 | return ; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /tools/gps_preprocess/common.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | vector SplitBySep(string str, string sep); 6 | void EchoRunning(); 7 | double String2Double(string str); 8 | string Double2String(double val); 9 | 10 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | MapMatch TODO 2 | ============= 3 | 4 | * json | yaml config file support 5 | * local and network logger support 6 | * ST-Matching, HMM model, ... support 7 | * map-index, map-matching service(use ace) support 8 | * auto test support 9 | 10 | 11 | -------------------------------------------------------------------------------- /tools/gen_distance_table/end_lng_table.txt: -------------------------------------------------------------------------------- 1 | lat 0.0001 0.0002 0.0005 0.0010 0.0020 0.0050 0.0100 0.0200 0.0500 0.1000 0.2000 0.5000 1.0000 2 | 41.6000 11.1187 22.2379 55.5948 111.1895 222.3792 555.9479 1111.8958 2223.7915 5559.4789 11118.9577 22237.9154 55594.7886 111189.5772 3 | -------------------------------------------------------------------------------- /tools/gen_distance_table/start_lng_table.txt: -------------------------------------------------------------------------------- 1 | lat 0.0001 0.0002 0.0005 0.0010 0.0020 0.0050 0.0100 0.0200 0.0500 0.1000 0.2000 0.5000 1.0000 2 | 39.4000 11.1191 22.2379 55.5948 111.1896 222.3792 555.9479 1111.8958 2223.7915 5559.4789 11118.9577 22237.9154 55594.7886 111189.5772 3 | -------------------------------------------------------------------------------- /tools/gen_grid/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS=foreign 2 | 3 | bin_PROGRAMS=gen_grid 4 | 5 | gen_grid_SOURCES=common.cpp gen_grid.cpp test.cpp 6 | 7 | gen_grid_LDADD= 8 | 9 | gen_grid_LDFLAGS= 10 | 11 | gen_grid_DEPENDENCIES= 12 | 13 | AM_CXXFLAGS=-Wall -g -O0 14 | 15 | -------------------------------------------------------------------------------- /tools/query_grid/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS=foreign 2 | 3 | bin_PROGRAMS=query_grid 4 | 5 | query_grid_SOURCES=common.cpp query_grid.cpp test.cpp 6 | 7 | query_grid_LDADD= 8 | 9 | query_grid_LDFLAGS= 10 | 11 | query_grid_DEPENDENCIES= 12 | 13 | AM_CXXFLAGS=-Wall -g -O0 14 | 15 | -------------------------------------------------------------------------------- /papers/A GRID-BASED SPATIAL INDEX FOR MATCHING BETWEEN MOVING VEHICLES AND ROAD NETWORK IN A REAL-TIME ENVIRONMENT.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lifulong/map-matching-algorithm/HEAD/papers/A GRID-BASED SPATIAL INDEX FOR MATCHING BETWEEN MOVING VEHICLES AND ROAD NETWORK IN A REAL-TIME ENVIRONMENT.pdf -------------------------------------------------------------------------------- /tools/gen_distance_table/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS=foreign 2 | 3 | bin_PROGRAMS=gen_distance_table 4 | 5 | gen_distance_table_SOURCES=gen_distance_table.cpp 6 | 7 | gen_distance_table_LDADD= 8 | 9 | gen_distance_table_LDFLAGS= 10 | 11 | gen_distance_table_DEPENDENCIES= 12 | 13 | AM_CXXFLAGS=-Wall -g -O0 14 | 15 | -------------------------------------------------------------------------------- /tools/gen_grid/test.cpp: -------------------------------------------------------------------------------- 1 | #include "gen_grid.h" 2 | 3 | void test() 4 | { 5 | GenMapGrid *gen_grid = new GenMapGrid("segs.txt"); 6 | gen_grid->genGrid("segs.txt"); 7 | gen_grid->dumpGrid("grid.txt"); 8 | //gen_grid->dumpGrid(""); 9 | } 10 | 11 | 12 | int main() 13 | { 14 | test(); 15 | return 0; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /tools/gps_preprocess/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS=foreign 2 | 3 | bin_PROGRAMS=gps_preprocess 4 | 5 | gps_preprocess_SOURCES=../../json/json.cc common.cpp gps_preprocess.cpp test.cpp 6 | 7 | gps_preprocess_LDADD= 8 | 9 | gps_preprocess_LDFLAGS= 10 | 11 | gps_preprocess_DEPENDENCIES= 12 | 13 | AM_CXXFLAGS=-Wall -g -O0 -std=c++11 14 | 15 | -------------------------------------------------------------------------------- /src/iter-map-matching/common.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | vector SplitBySep(string str, string sep); 6 | void EchoRunning(); 7 | double String2Double(string str); 8 | string Double2String(double val); 9 | double Min(double val1, double val2); 10 | bool isEqualDouble(double val1, double val2); 11 | 12 | -------------------------------------------------------------------------------- /src/simple-map-matching/common.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | vector SplitBySep(string str, string sep); 6 | void EchoRunning(); 7 | double String2Double(string str); 8 | string Double2String(double val); 9 | double Min(double val1, double val2); 10 | bool isEqualDouble(double val1, double val2); 11 | 12 | -------------------------------------------------------------------------------- /src/map-index/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS=foreign 2 | 3 | bin_PROGRAMS=map_index_serve 4 | 5 | map_index_serve_SOURCES=common.cpp gen_segs.cpp gen_grid.cpp query_grid.cpp map_index.cpp serve.cpp 6 | 7 | map_index_serve_LDADD= 8 | 9 | map_index_serve_LDFLAGS= 10 | 11 | map_index_serve_DEPENDENCIES= 12 | 13 | AM_CXXFLAGS=-Wall -g -O0 -DTEST_MAP_INDEX -std=c++11 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/map-index/error.h: -------------------------------------------------------------------------------- 1 | /** 2 | * impletation of build grid index of road network for map matching 3 | * 4 | * @date: 2014-12-21 5 | * @author: lifulong 6 | **/ 7 | 8 | #include 9 | 10 | class Error { 11 | public: 12 | const static int ERR_OK = 0x0000; 13 | 14 | const static int ERR_PARA = 0x0100; 15 | const static int ERR_OPENFILE = 0x0101; 16 | }; 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/iter-map-matching/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS=foreign 2 | 3 | bin_PROGRAMS=iter_map_matcher 4 | 5 | iter_map_matcher_SOURCES=../../json/json.cc common.cpp ../map-index/gen_segs.cpp ../map-index/gen_grid.cpp ../map-index/query_grid.cpp ../map-index/map_index.cpp iter_matcher.cpp test.cpp 6 | 7 | iter_map_matcher_LDADD= 8 | 9 | iter_map_matcher_LDFLAGS= 10 | 11 | iter_map_matcher_DEPENDENCIES= 12 | 13 | AM_CXXFLAGS=-Wall -g -O0 -std=c++11 14 | 15 | -------------------------------------------------------------------------------- /src/simple-map-matching/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS=foreign 2 | 3 | bin_PROGRAMS=simple_map_matcher 4 | 5 | simple_map_matcher_SOURCES=../../json/json.cc common.cpp ../map-index/gen_segs.cpp ../map-index/gen_grid.cpp ../map-index/query_grid.cpp ../map-index/map_index.cpp simple_matcher.cpp test.cpp 6 | 7 | simple_map_matcher_LDADD= 8 | 9 | simple_map_matcher_LDFLAGS= 10 | 11 | simple_map_matcher_DEPENDENCIES= 12 | 13 | AM_CXXFLAGS=-Wall -g -O0 -std=c++11 14 | 15 | -------------------------------------------------------------------------------- /tools/gen_distance_table/gen_distance_table.cpp: -------------------------------------------------------------------------------- 1 | #include "gen_distance_table.h" 2 | 3 | int main() 4 | { 5 | double bj_start_lat = 39.4, bj_end_lat = 41.6; 6 | //double bj_start_lng = 115.7, bj_end_lng = 117.4; 7 | 8 | GenDistanceTable *genTable = new GenDistanceTable(); 9 | 10 | genTable->genLngDistance(bj_start_lat, bj_end_lat, 0.1, "lat_table.txt"); 11 | 12 | genTable->genLatDistance(116.0, bj_start_lat, "start_lng_table.txt"); 13 | 14 | genTable->genLatDistance(116.0, bj_end_lat, "end_lng_table.txt"); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tools/gen_distance_table/configure.in: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([gen_distance_table], [0.0.0.1], [msl.fulong@gmail.com]) 6 | AM_INIT_AUTOMAKE([1.12 foreign no-define]) 7 | AC_CONFIG_SRCDIR([gen_distance_table.cpp]) 8 | #AC_CONFIG_HEADERS([config.h]) 9 | 10 | # Checks for programs. 11 | AC_PROG_CXX 12 | AC_PROG_CC 13 | 14 | # Checks for libraries. 15 | 16 | # Checks for header files. 17 | 18 | # Checks for typedefs, structures, and compiler characteristics. 19 | 20 | # Checks for library functions. 21 | AC_CHECK_FUNCS([sqrt]) 22 | 23 | AC_OUTPUT(Makefile) 24 | -------------------------------------------------------------------------------- /tools/query_grid/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([query_grid], [0.1], [msl.fulong@gmail.com]) 6 | AM_INIT_AUTOMAKE([1.12 foreign no-define]) 7 | AC_CONFIG_SRCDIR([query_grid.cpp]) 8 | #AC_CONFIG_HEADERS([config.h]) 9 | 10 | # Checks for programs. 11 | AC_PROG_CXX 12 | AC_PROG_CC 13 | 14 | # Checks for libraries. 15 | 16 | # Checks for header files. 17 | AC_CHECK_HEADERS([stdlib.h]) 18 | 19 | # Checks for typedefs, structures, and compiler characteristics. 20 | AC_TYPE_SIZE_T 21 | 22 | # Checks for library functions. 23 | 24 | AC_CONFIG_FILES([Makefile]) 25 | AC_OUTPUT 26 | -------------------------------------------------------------------------------- /tools/gen_grid/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([gen_grid], [0.1], [msl.fulong@gmail.com]) 6 | AM_INIT_AUTOMAKE([1.12 foreign no-define]) 7 | AC_CONFIG_SRCDIR([gen_grid.cpp]) 8 | #AC_CONFIG_HEADERS([config.h]) 9 | 10 | # Checks for programs. 11 | AC_PROG_CXX 12 | AC_PROG_CC 13 | 14 | # Checks for libraries. 15 | 16 | # Checks for header files. 17 | AC_CHECK_HEADERS([stdlib.h string.h]) 18 | 19 | # Checks for typedefs, structures, and compiler characteristics. 20 | AC_TYPE_SIZE_T 21 | 22 | # Checks for library functions. 23 | 24 | AC_CONFIG_FILES([Makefile]) 25 | AC_OUTPUT 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | *.txt 31 | mapdata 32 | 33 | *Makefile.in 34 | *aclocal.m4 35 | *autom4te.cache/ 36 | *autoscan.log 37 | *compile 38 | *config.log 39 | *config.status 40 | *depcomp 41 | *install-sh 42 | *missing 43 | *.deps 44 | *Makefile 45 | *aclocal.m4 46 | *configure 47 | *configure.scan 48 | *diff 49 | tools/gen_distance_table/gen_distance_table 50 | *gen_grid 51 | -------------------------------------------------------------------------------- /tools/gps_preprocess/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([gps_preprocess], [0.1], [msl.fulong@gmail.com]) 6 | #AM_INIT_AUTOMAKE([1.12 foreign no-define]) 7 | AM_INIT_AUTOMAKE() 8 | AC_CONFIG_SRCDIR([common.h]) 9 | AC_CONFIG_HEADERS([config.h]) 10 | 11 | # Checks for programs. 12 | AC_PROG_CXX 13 | AC_PROG_CC 14 | 15 | # Checks for libraries. 16 | 17 | # Checks for header files. 18 | AC_CHECK_HEADERS([stdlib.h]) 19 | 20 | # Checks for typedefs, structures, and compiler characteristics. 21 | AC_TYPE_SIZE_T 22 | 23 | # Checks for library functions. 24 | 25 | AC_CONFIG_FILES([Makefile]) 26 | AC_OUTPUT 27 | -------------------------------------------------------------------------------- /src/map-index/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([map_index_serve], [0.1], [msl.fulong@gmail.com]) 6 | AM_INIT_AUTOMAKE([1.12 foreign no-define]) 7 | AC_CONFIG_SRCDIR([common.cpp]) 8 | #AC_CONFIG_HEADERS([config.h]) 9 | 10 | # Checks for programs. 11 | AC_PROG_CXX 12 | AC_PROG_CC 13 | 14 | # Checks for libraries. 15 | 16 | # Checks for header files. 17 | AC_CHECK_HEADERS([stdlib.h string.h]) 18 | 19 | # Checks for typedefs, structures, and compiler characteristics. 20 | AC_CHECK_HEADER_STDBOOL 21 | AC_TYPE_SIZE_T 22 | 23 | # Checks for library functions. 24 | AC_CHECK_FUNCS([memset sqrt]) 25 | 26 | AC_CONFIG_FILES([Makefile]) 27 | AC_OUTPUT 28 | -------------------------------------------------------------------------------- /src/iter-map-matching/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([iter_map_matcher], [0.1], [msl.fulong@gmail.com]) 6 | AM_INIT_AUTOMAKE([1.12 foreign no-define]) 7 | AC_CONFIG_SRCDIR([iter_matcher.h]) 8 | AC_CONFIG_HEADERS([config.h]) 9 | 10 | # Checks for programs. 11 | AC_PROG_CXX 12 | AC_PROG_CC 13 | 14 | # Checks for libraries. 15 | 16 | # Checks for header files. 17 | AC_CHECK_HEADERS([stdlib.h]) 18 | 19 | # Checks for typedefs, structures, and compiler characteristics. 20 | AC_CHECK_HEADER_STDBOOL 21 | AC_TYPE_SIZE_T 22 | AC_TYPE_UINT32_T 23 | 24 | # Checks for library functions. 25 | AC_CHECK_FUNCS([sqrt]) 26 | 27 | AC_CONFIG_FILES([Makefile]) 28 | AC_OUTPUT 29 | -------------------------------------------------------------------------------- /src/simple-map-matching/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([simple_map_matcher], [0.1], [msl.fulong@gmail.com]) 6 | AM_INIT_AUTOMAKE([1.12 foreign no-define]) 7 | AC_CONFIG_SRCDIR([simple_matcher.h]) 8 | AC_CONFIG_HEADERS([config.h]) 9 | 10 | # Checks for programs. 11 | AC_PROG_CXX 12 | AC_PROG_CC 13 | 14 | # Checks for libraries. 15 | 16 | # Checks for header files. 17 | AC_CHECK_HEADERS([stdlib.h]) 18 | 19 | # Checks for typedefs, structures, and compiler characteristics. 20 | AC_CHECK_HEADER_STDBOOL 21 | AC_TYPE_SIZE_T 22 | AC_TYPE_UINT32_T 23 | 24 | # Checks for library functions. 25 | AC_CHECK_FUNCS([sqrt]) 26 | 27 | AC_CONFIG_FILES([Makefile]) 28 | AC_OUTPUT 29 | -------------------------------------------------------------------------------- /src/map-index/debug.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | //accept c_str as input parameters. 6 | #define debug_2_console(fmt,args...) \ 7 | do{ \ 8 | time_t t_time; \ 9 | time(&t_time); \ 10 | printf("%s", ctime(&t_time)); \ 11 | printf(fmt,##args); \ 12 | }while(0) 13 | 14 | //accept c_str as input parameters. 15 | #define debug_2_file(fmt,args...) \ 16 | do{ \ 17 | FILE* fp; \ 18 | fp = fopen("log", "a+"); \ 19 | fprintf(fp, fmt, ##args); \ 20 | fclose(fp); \ 21 | }while(0) 22 | 23 | #define DEBUG_2_CONSOLE 24 | 25 | #ifdef DEBUG_2_FILE 26 | #define debug_msg(fmt,args...) debug_2_file(fmt,##args) 27 | #elif defined DEBUG_2_CONSOLE 28 | #define debug_msg(fmt,args...) debug_2_console(fmt,##args) 29 | #else 30 | #define debug_msg(fmt,args...) do{} while(0) 31 | #endif 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/iter-map-matching/test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace std; 5 | 6 | #include "iter_matcher.h" 7 | 8 | #define USAGE(method) ("Usage:\n"+method+"\tfilename\n") 9 | 10 | void test(string filename) 11 | { 12 | size_t pos; 13 | string dumpfile, basename, ext; 14 | 15 | pos = filename.find_last_of("."); 16 | if(string::npos == pos) 17 | { 18 | basename = filename; 19 | ext = ""; 20 | dumpfile = basename + "_append"; 21 | } 22 | else 23 | { 24 | basename = filename.substr(0, pos); 25 | ext = filename.substr(pos+1); 26 | dumpfile = basename + "_append" + "." + ext; 27 | } 28 | 29 | } 30 | 31 | int main(int argc ,char *argv[]) 32 | { 33 | string filename; 34 | 35 | if(1 != argc && 2 != argc) { 36 | string usage = USAGE(string(argv[0])); 37 | debug_msg("%s", usage.c_str()); 38 | return 1; 39 | } 40 | 41 | if(2 == argc) 42 | filename = string(argv[1]); 43 | else 44 | filename = "./../../datasets/9710356_1.json"; 45 | 46 | test(filename); 47 | 48 | return 0; 49 | } 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/map-index/common.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | #include "common.h" 10 | 11 | vector SplitBySep(string str, string sep) 12 | { 13 | size_t pos, old_pos=0; 14 | string t_str; 15 | vector result; 16 | result.clear(); 17 | 18 | if(str.empty()) 19 | return result; 20 | 21 | if(sep.empty()) { 22 | result.push_back(str); 23 | return result; 24 | } 25 | 26 | pos = str.find(sep, 0); 27 | 28 | while(pos != string::npos) 29 | { 30 | t_str = str.substr(old_pos, pos-old_pos); 31 | result.push_back(t_str); 32 | old_pos = pos+1; 33 | pos = str.find(sep, old_pos); 34 | } 35 | 36 | t_str = str.substr(old_pos); 37 | result.push_back(t_str); 38 | 39 | return result; 40 | } 41 | 42 | void EchoRunning() 43 | { 44 | static int i = 0; 45 | 46 | int j = i % 4; 47 | 48 | switch(j) 49 | { 50 | case 0: 51 | printf("\b\b\b---"); 52 | break; 53 | case 1: 54 | printf("\b\b\b\\\\\\"); 55 | break; 56 | case 2: 57 | printf("\b\b\b|||"); 58 | break; 59 | case 3: 60 | printf("\b\b\b///"); 61 | break; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /tools/gen_grid/common.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | #include "common.h" 10 | 11 | vector SplitBySep(string str, string sep) 12 | { 13 | size_t pos, old_pos=0; 14 | string t_str; 15 | vector result; 16 | result.clear(); 17 | 18 | if(str.empty()) 19 | return result; 20 | 21 | if(sep.empty()) { 22 | result.push_back(str); 23 | return result; 24 | } 25 | 26 | pos = str.find(sep, 0); 27 | 28 | while(pos != string::npos) 29 | { 30 | t_str = str.substr(old_pos, pos-old_pos); 31 | result.push_back(t_str); 32 | old_pos = pos+1; 33 | pos = str.find(sep, old_pos); 34 | } 35 | 36 | t_str = str.substr(old_pos); 37 | result.push_back(t_str); 38 | 39 | return result; 40 | } 41 | 42 | void EchoRunning() 43 | { 44 | static int i = 0; 45 | 46 | int j = i % 4; 47 | 48 | switch(j) 49 | { 50 | case 0: 51 | printf("\b\b\b---"); 52 | break; 53 | case 1: 54 | printf("\b\b\b\\\\\\"); 55 | break; 56 | case 2: 57 | printf("\b\b\b|||"); 58 | break; 59 | case 3: 60 | printf("\b\b\b///"); 61 | break; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /tools/query_grid/common.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | #include "common.h" 10 | 11 | vector SplitBySep(string str, string sep) 12 | { 13 | size_t pos, old_pos=0; 14 | string t_str; 15 | vector result; 16 | result.clear(); 17 | 18 | if(str.empty()) 19 | return result; 20 | 21 | if(sep.empty()) { 22 | result.push_back(str); 23 | return result; 24 | } 25 | 26 | pos = str.find(sep, 0); 27 | 28 | while(pos != string::npos) 29 | { 30 | t_str = str.substr(old_pos, pos-old_pos); 31 | result.push_back(t_str); 32 | old_pos = pos+1; 33 | pos = str.find(sep, old_pos); 34 | } 35 | 36 | t_str = str.substr(old_pos); 37 | result.push_back(t_str); 38 | 39 | return result; 40 | } 41 | 42 | void EchoRunning() 43 | { 44 | static int i = 0; 45 | 46 | int j = i % 4; 47 | 48 | switch(j) 49 | { 50 | case 0: 51 | printf("\b\b\b---"); 52 | break; 53 | case 1: 54 | printf("\b\b\b\\\\\\"); 55 | break; 56 | case 2: 57 | printf("\b\b\b|||"); 58 | break; 59 | case 3: 60 | printf("\b\b\b///"); 61 | break; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /datasets/dump184.json: -------------------------------------------------------------------------------- 1 | [{"lat":"39.929855","lng":"116.578234","gps_type":"baidu","gps_time":1418778848000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418778848.4},{"lat":"39.929866","lng":"116.577471","gps_type":"baidu","gps_time":1418778853000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418778853.404},{"lat":"39.929863","lng":"116.576868","gps_type":"baidu","gps_time":1418778858000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418778858.404},{"lat":"39.929797","lng":"116.57594","gps_type":"baidu","gps_time":1418778863000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418778863.403},{"lat":"39.929788","lng":"116.575251","gps_type":"baidu","gps_time":1418778868000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418778868.406},{"lat":"39.929795","lng":"116.574108","gps_type":"baidu","gps_time":1418778873000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418778873.409},{"lat":"39.929814","lng":"116.57328","gps_type":"baidu","gps_time":1418778878000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418778878.408},{"lat":"39.929812","lng":"116.572036","gps_type":"baidu","gps_time":1418778883000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418778883.408}] -------------------------------------------------------------------------------- /datasets/dump10.json: -------------------------------------------------------------------------------- 1 | [{"lat":"39.919616","lng":"116.585945","gps_type":"baidu","gps_time":1418777594000,"provider":"network","accuracy":61.581451416016,"status":1,"milli_timestamp":1418777593.054},{"lat":"39.920135","lng":"116.587911","gps_type":"baidu","gps_time":1418777678000,"provider":"gps","accuracy":17,"status":1,"milli_timestamp":1418777678.72},{"lat":"39.919378","lng":"116.591603","gps_type":"baidu","gps_time":1418777711000,"provider":"network","accuracy":70.107040405273,"status":1,"milli_timestamp":1418777709.86},{"lat":"39.918465","lng":"116.594909","gps_type":"baidu","gps_time":1418777739000,"provider":"gps","accuracy":5,"status":1,"milli_timestamp":1418777739.258},{"lat":"39.918146","lng":"116.596048","gps_type":"baidu","gps_time":1418777769000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418777769.25},{"lat":"39.918071","lng":"116.59604","gps_type":"baidu","gps_time":1418777799000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418777799.256},{"lat":"39.91803","lng":"116.596059","gps_type":"baidu","gps_time":1418777822000,"provider":"network","accuracy":59.853755950928,"status":1,"milli_timestamp":1418777821.871},{"lat":"39.917985","lng":"116.59644","gps_type":"baidu","gps_time":1418777880000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418777880.732}] -------------------------------------------------------------------------------- /src/map-index/logger.h: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @date: 2014-12-21 4 | * @author: lifulong 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | #include 13 | 14 | #define LOG_EMEGE 0x01 15 | #define LOG_ERROR 0x02 16 | #define LOG_WARN 0x03 17 | #define LOG_INFO 0x04 18 | 19 | #define WITH_TIME 20 | 21 | 22 | class Logger { 23 | 24 | public: 25 | 26 | Logger(string file = "", int level = LOG_INFO) 27 | { 28 | if(file == "") 29 | { 30 | _fp = stdout; 31 | } 32 | else 33 | { 34 | _fp = fopen(file.c_str(), "w+"); 35 | if(!_fp) 36 | cout << "Init Logger File " + file + " Error."; 37 | } 38 | this->_level = level; 39 | } 40 | 41 | void Log(string str) 42 | { 43 | time_t raw_time; 44 | struct tm *timeinfo; 45 | 46 | time(&raw_time); 47 | timeinfo = localtime(&raw_time); 48 | string timestr = asctime(timeinfo); 49 | 50 | #ifdef WITH_TIME 51 | str = timestr + str + "\n"; 52 | #endif 53 | fwrite(str.c_str(), str.length(), 1, _fp); 54 | } 55 | 56 | void Info(string str) 57 | { 58 | if(this->_level < LOG_INFO) 59 | return; 60 | this->Log("[INFO]" + str); 61 | } 62 | 63 | private: 64 | //Levels: EMEGE,ERROR,WARN,INFO 65 | FILE* _fp; 66 | int _level; 67 | 68 | }; 69 | -------------------------------------------------------------------------------- /tools/distill_position/distill_position.php: -------------------------------------------------------------------------------- 1 | 3 | 4 | using namespace std; 5 | 6 | #include "gps_preprocess.h" 7 | 8 | #define USAGE(method) ("Usage:\n"+method+"\tfilename\n") 9 | 10 | void test(string filename) 11 | { 12 | size_t pos; 13 | string dumpfile, basename, ext; 14 | 15 | pos = filename.find_last_of("."); 16 | if(string::npos == pos) 17 | { 18 | basename = filename; 19 | ext = ""; 20 | dumpfile = basename + "_append"; 21 | } 22 | else 23 | { 24 | basename = filename.substr(0, pos); 25 | ext = filename.substr(pos+1); 26 | dumpfile = basename + "_append" + "." + ext; 27 | } 28 | 29 | 30 | GpsPreprocess *gp = new GpsPreprocess(); 31 | //gp->loadJsonGps("./../../datasets/14099164_1.json"); //1 line 32 | gp->loadJsonGps(filename); //many line 33 | gp->appendLineHeading(); //many line 34 | gp->appendLongSpeed(); //many line 35 | //gp->dumpJsonGps(); 36 | gp->dumpJsonGpsBeauty(dumpfile); 37 | } 38 | 39 | int main(int argc ,char *argv[]) 40 | { 41 | string filename; 42 | 43 | if(1 != argc && 2 != argc) { 44 | string usage = USAGE(string(argv[0])); 45 | debug_msg("%s", usage.c_str()); 46 | return 1; 47 | } 48 | 49 | if(2 == argc) 50 | filename = string(argv[1]); 51 | else 52 | filename = "./../../datasets/9710356_1.json"; 53 | 54 | test(filename); 55 | 56 | return 0; 57 | } 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /tools/query_grid/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "query_grid.h" 5 | 6 | using namespace std; 7 | 8 | void test() 9 | { 10 | vector maps; 11 | maps.clear(); 12 | 13 | QueryGrid *query_grid = new QueryGrid("segs.txt", "grid_info", "grid.txt"); 14 | //query_grid->loadGrid("grid_ifo", "grid.txt"); 15 | printf("begin query grid segs......\n"); 16 | maps = query_grid->getGridSegs(115.714691, 39.570098, 200); 17 | 18 | printf("maps_size: %d\n", maps.size()); 19 | for(vector::iterator iter = maps.begin(); iter != maps.end(); iter++) 20 | { 21 | printf("Map:\n"); 22 | printf("seg_id:\t%d\n", iter->seg_id); 23 | printf("edge_id:\t%d\n", iter->edge_id); 24 | printf("start_lng:\t%f\n", iter->start_lng); 25 | printf("start_lat:\t%f\n", iter->start_lat); 26 | printf("end_lng:\t%f\n", iter->end_lng); 27 | printf("end_lat:\t%f\n", iter->end_lat); 28 | printf("lng:\t%f\n", iter->lng); 29 | printf("lat:\t%f\n", iter->lat); 30 | printf("map_lng:\t%f\n", iter->map_lng); 31 | printf("map_lat:\t%f\n", iter->map_lat); 32 | printf("distance:\t%f\n", iter->distance); 33 | printf("min_distance:\t%f\n", iter->min_distance); 34 | printf("on_seg:\t%d\n", iter->on_seg); 35 | printf("\n"); 36 | } 37 | } 38 | 39 | 40 | int main() 41 | { 42 | test(); 43 | return 0; 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /tools/bash/gen_segs/gen_segs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # @input: road edge file 4 | # edge_id lat1 lng1 lat2 lng2 ... 5 | # @output: road network segments file 6 | # seg_id lat lng edge_id 7 | # @author: lifulong 8 | 9 | Usage="Usage: $0 road_file output_segs_file\t" 10 | 11 | [ $# -ne 2 ] && { echo -e "$Usage"; exit 1; } 12 | edges_file=$1 13 | segs_file=$2 14 | 15 | function gen_segs() 16 | { 17 | echo -e "[INFO]\tStart gen_segs... ..." 18 | 19 | local edge_file=$1 20 | local seg_file=$2 21 | let seg_id=0 22 | 23 | [ -f $seg_file ] && { rm -f $seg_file; } 24 | 25 | exec 3<> $edge_file 26 | 27 | while read line 28 | do 29 | let label=$seg_id%4 30 | 31 | case $label in 32 | 0) echo -n -e "\b\b\b---";; 33 | 1) echo -n -e "\b\b\b\\\\\\";; 34 | 2) echo -n -e "\b\b\b|||";; 35 | 3) echo -n -e "\b\b\b///";; 36 | esac 37 | 38 | read edge_id rest<<-EOF 39 | $line 40 | EOF 41 | 42 | #Fix:set lat and lng to "" while read an new line 43 | lat="" 44 | lng="" 45 | last_lat="" 46 | last_lng="" 47 | 48 | while [ "$rest" != "" ]; 49 | do 50 | last_lat=$lat 51 | last_lng=$lng 52 | read lat lng rest<<-EOF 53 | $rest 54 | EOF 55 | if [ "$last_lat" == "" -o "$last_lng" == "" ]; then 56 | continue 57 | fi 58 | let seg_id=$seg_id+1 59 | # if [ "$last_lat" != "" -a "$last_lng" != "" ]; then 60 | # echo -e "$seg_id\t$last_lng\t$last_lat\t$lng\t$lat\t$edge_id" | tee -a $seg_file 61 | echo -e "$seg_id\t$last_lng\t$last_lat\t$lng\t$lat\t$edge_id" >> $seg_file 62 | # fi 63 | done 64 | 65 | done<&3 66 | 67 | exec 3<&- 68 | exec 3>&- 69 | 70 | echo -e "[INFO]\tFinish gen_segs... ..." 71 | } 72 | 73 | gen_segs $edges_file $segs_file 74 | 75 | 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | map-matching-algorithm 2 | ====================== 3 | 4 | 5 | ###Description 6 | 7 | Here is some open source map matching algorithms for map vehicle track to real road network. 8 | 9 | 10 | ###Features 11 | 12 | 1. Use map grid to speed up map point to road. 13 | 2. Build map index speed up by multi_thread and store preprocess result in the first index time. 14 | 3. Use ACE as server framework. 15 | 4. Works as an http server, and json as communication format. 16 | 5. Multi algorithms support. 17 | 18 | ###References 19 | 20 | 1. [Multi-track Map Matching](./papers/Multi-track Map Matching.pdf) 21 | 2. [Quick Map Matching Using Multi-Core CPUs](./papers/Quick Map Matching Using Multi-Core CPUs.pdf) 22 | 3. [A Map Matching Method for GPS Based Real-Time Vehicle Location](./papers/A Map Matching Method for GPS Based Real-Time Vehicle Location.pdf) 23 | 4. [ACM SIGSPATIAL GIS Cup 2012](./papers/ACM SIGSPATIAL GIS Cup 2012.pdf) 24 | 5. [A Three-step General Map Matching Method in the GIS](./papers/A Three-step General Map Matching Method in the GIS.pdf) 25 | 6. [A GRID-BASED SPATIAL INDEX FOR MATCHING BETWEEN MOVING VEHICLES AND ROAD NETWORK IN A REAL-TIME ENVIRONMENT](./papers/A GRID-BASED SPATIAL INDEX FOR MATCHING BETWEEN MOVING VEHICLES AND ROAD NETWORK IN A REAL-TIME ENVIRONMENT.pdf) 26 | 27 | 28 | ###Develop Plan 29 | 30 | 1. Map Index Support 31 | 2. Iter MapMatching Support 32 | 3. ST,HMM Map Match Support 33 | 4. Working as a service base on Ace framework 34 | 5. Service config support 35 | 6. Performance optimize 36 | 37 | ###Develop Status 38 | 39 | * Develop ing ... 40 | 41 | ###Thanks for 42 | 43 | ###Authors 44 | 45 | * [lifulong](https://github.com/lifulong) [msl.fulong@gmail.com](mailto:msl.fulong@gmail.com) 46 | 47 | 48 | -------------------------------------------------------------------------------- /tools/gps_preprocess/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_INTTYPES_H 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_MEMORY_H 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_STDINT_H 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_STDLIB_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_STRINGS_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_STRING_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_SYS_STAT_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_SYS_TYPES_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_UNISTD_H 29 | 30 | /* Name of package */ 31 | #undef PACKAGE 32 | 33 | /* Define to the address where bug reports for this package should be sent. */ 34 | #undef PACKAGE_BUGREPORT 35 | 36 | /* Define to the full name of this package. */ 37 | #undef PACKAGE_NAME 38 | 39 | /* Define to the full name and version of this package. */ 40 | #undef PACKAGE_STRING 41 | 42 | /* Define to the one symbol short name of this package. */ 43 | #undef PACKAGE_TARNAME 44 | 45 | /* Define to the home page for this package. */ 46 | #undef PACKAGE_URL 47 | 48 | /* Define to the version of this package. */ 49 | #undef PACKAGE_VERSION 50 | 51 | /* Define to 1 if you have the ANSI C header files. */ 52 | #undef STDC_HEADERS 53 | 54 | /* Version number of package */ 55 | #undef VERSION 56 | 57 | /* Define to `unsigned int' if does not define. */ 58 | #undef size_t 59 | -------------------------------------------------------------------------------- /tools/gps_preprocess/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_INTTYPES_H 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_MEMORY_H 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_STDINT_H 1 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_STDLIB_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_STRINGS_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_STRING_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_SYS_STAT_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_SYS_TYPES_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_UNISTD_H 1 30 | 31 | /* Name of package */ 32 | #define PACKAGE "gps_preprocess" 33 | 34 | /* Define to the address where bug reports for this package should be sent. */ 35 | #define PACKAGE_BUGREPORT "msl.fulong@gmail.com" 36 | 37 | /* Define to the full name of this package. */ 38 | #define PACKAGE_NAME "gps_preprocess" 39 | 40 | /* Define to the full name and version of this package. */ 41 | #define PACKAGE_STRING "gps_preprocess 0.1" 42 | 43 | /* Define to the one symbol short name of this package. */ 44 | #define PACKAGE_TARNAME "gps_preprocess" 45 | 46 | /* Define to the home page for this package. */ 47 | #define PACKAGE_URL "" 48 | 49 | /* Define to the version of this package. */ 50 | #define PACKAGE_VERSION "0.1" 51 | 52 | /* Define to 1 if you have the ANSI C header files. */ 53 | #define STDC_HEADERS 1 54 | 55 | /* Version number of package */ 56 | #define VERSION "0.1" 57 | 58 | /* Define to `unsigned int' if does not define. */ 59 | /* #undef size_t */ 60 | -------------------------------------------------------------------------------- /tools/gps_preprocess/common.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | #include "common.h" 12 | 13 | vector SplitBySep(string str, string sep) 14 | { 15 | size_t pos, old_pos=0; 16 | string t_str; 17 | vector result; 18 | result.clear(); 19 | 20 | if(str.empty()) 21 | return result; 22 | 23 | if(sep.empty()) { 24 | result.push_back(str); 25 | return result; 26 | } 27 | 28 | pos = str.find(sep, 0); 29 | 30 | while(pos != string::npos) 31 | { 32 | t_str = str.substr(old_pos, pos-old_pos); 33 | result.push_back(t_str); 34 | old_pos = pos+1; 35 | pos = str.find(sep, old_pos); 36 | } 37 | 38 | t_str = str.substr(old_pos); 39 | result.push_back(t_str); 40 | 41 | return result; 42 | } 43 | 44 | void EchoRunning() 45 | { 46 | static int i = 0; 47 | 48 | int j = i % 4; 49 | 50 | switch(j) 51 | { 52 | case 0: 53 | printf("\b\b\b---"); 54 | break; 55 | case 1: 56 | printf("\b\b\b\\\\\\"); 57 | break; 58 | case 2: 59 | printf("\b\b\b|||"); 60 | break; 61 | case 3: 62 | printf("\b\b\b///"); 63 | break; 64 | } 65 | } 66 | 67 | double String2Double(string str) 68 | { 69 | size_t i, len; 70 | size_t first_pos, last_pos; 71 | 72 | if("" == str) 73 | return 0.0; 74 | 75 | first_pos = str.find_first_of("\""); 76 | last_pos = str.find_last_of("\""); 77 | 78 | if(string::npos != first_pos && string::npos != last_pos && first_pos != last_pos) 79 | str = str.substr(first_pos+1, last_pos-1); 80 | 81 | len = str.length(); 82 | for(i = 0; i < len; i++) 83 | { 84 | if(!isdigit(str[i]) && '.' != str[i]) 85 | return 0.0; 86 | } 87 | 88 | return strtold(str.c_str(), NULL); 89 | } 90 | 91 | 92 | string Double2String(double val) 93 | { 94 | stringstream ss; 95 | string str; 96 | 97 | ss << val; 98 | str = ss.str(); 99 | 100 | return str; 101 | } 102 | 103 | 104 | -------------------------------------------------------------------------------- /tools/bash/get_deviation/get_deviation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | Usage="Usage: $0 real_pos_file fake_pos_file" 4 | 5 | [ $# -ne 2 ] && { echo "$Usage"; exit 1; } 6 | 7 | _DEBUG="true" 8 | function DEBUG() 9 | { 10 | if [ "$_DEBUG" == "true" ];then 11 | $@ 12 | fi 13 | } 14 | 15 | real_pos_file=$1 16 | fake_pos_file=$2 17 | result_file="deviation" 18 | 19 | declare -a real_pos_array 20 | declare -a fake_pos_array 21 | 22 | function load_pos() 23 | { 24 | pos_file=$1 25 | flag=$2 26 | 27 | let i=0 28 | while read line 29 | do 30 | #read lng lat <<-EOF 31 | # $line 32 | #EOF 33 | case $flag in 34 | "real") 35 | real_pos_array[$i]=$line;; 36 | "fake") 37 | fake_pos_array[$i]=$line;; 38 | esac 39 | let i=$i+1 40 | done<$pos_file 41 | } 42 | 43 | function get_deviation() 44 | { 45 | if [ ${#real_pos_array[*]} != ${#fake_pos_array[*]} ];then 46 | echo -e "[Error]:real pos count not equal fake pos count\n" 47 | return 48 | fi 49 | 50 | count=${#real_pos_array[*]} 51 | total_lng=0 52 | total_lat=0 53 | average_lng=0 54 | average_lat=0 55 | let i=0 56 | while true 57 | do 58 | if [ $i -ge $count ];then 59 | average_lng=`echo "scale=6;$total_lng/$count" | bc` 60 | average_lat=`echo "scale=6;$total_lat/$count" | bc` 61 | pos=`expr index $average_lng .` 62 | [ $pos -eq 1 ] && { average_lng="0"$average_lng; } 63 | pos=`expr index $average_lat .` 64 | [ $pos -eq 1 ] && { average_lat="0"$average_lat; } 65 | echo -e "$average_lng\t$average_lat" | tee $result_file 66 | return 67 | fi 68 | 69 | real_lng_lat=${real_pos_array[$i]} 70 | fake_lng_lat=${fake_pos_array[$i]} 71 | 72 | read real_lng real_lat <<-EOF 73 | $real_lng_lat 74 | EOF 75 | read fake_lng fake_lat <<-EOF 76 | $fake_lng_lat 77 | EOF 78 | 79 | dev_lng=`scale=6;echo $real_lng-$fake_lng | bc` 80 | dev_lat=`scale=6;echo $real_lat-$fake_lat | bc` 81 | total_lng=`scale=6;echo $total_lng+$dev_lng | bc` 82 | total_lat=`scale=6;echo $total_lat+$dev_lat | bc` 83 | DEBUG echo "total_lng:$total_lng" 84 | DEBUG echo "total_lat:$total_lat" 85 | 86 | let i=$i+1 87 | done 88 | } 89 | 90 | load_pos $real_pos_file "real" 91 | load_pos $fake_pos_file "fake" 92 | 93 | get_deviation 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/iter-map-matching/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_INTTYPES_H 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_MEMORY_H 8 | 9 | /* Define to 1 if you have the `sqrt' function. */ 10 | #undef HAVE_SQRT 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_STDINT_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_STDLIB_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_STRINGS_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_STRING_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_SYS_STAT_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_SYS_TYPES_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_UNISTD_H 32 | 33 | /* Define to 1 if the system has the type `_Bool'. */ 34 | #undef HAVE__BOOL 35 | 36 | /* Define to the address where bug reports for this package should be sent. */ 37 | #undef PACKAGE_BUGREPORT 38 | 39 | /* Define to the full name of this package. */ 40 | #undef PACKAGE_NAME 41 | 42 | /* Define to the full name and version of this package. */ 43 | #undef PACKAGE_STRING 44 | 45 | /* Define to the one symbol short name of this package. */ 46 | #undef PACKAGE_TARNAME 47 | 48 | /* Define to the home page for this package. */ 49 | #undef PACKAGE_URL 50 | 51 | /* Define to the version of this package. */ 52 | #undef PACKAGE_VERSION 53 | 54 | /* Define to 1 if you have the ANSI C header files. */ 55 | #undef STDC_HEADERS 56 | 57 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 58 | , or is not used. If the typedef were allowed, the 59 | #define below would cause a syntax error. */ 60 | #undef _UINT32_T 61 | 62 | /* Define to `unsigned int' if does not define. */ 63 | #undef size_t 64 | 65 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 66 | such a type exists and the standard includes do not define it. */ 67 | #undef uint32_t 68 | -------------------------------------------------------------------------------- /src/simple-map-matching/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_INTTYPES_H 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_MEMORY_H 8 | 9 | /* Define to 1 if you have the `sqrt' function. */ 10 | #undef HAVE_SQRT 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_STDINT_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_STDLIB_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_STRINGS_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_STRING_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_SYS_STAT_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_SYS_TYPES_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_UNISTD_H 32 | 33 | /* Define to 1 if the system has the type `_Bool'. */ 34 | #undef HAVE__BOOL 35 | 36 | /* Define to the address where bug reports for this package should be sent. */ 37 | #undef PACKAGE_BUGREPORT 38 | 39 | /* Define to the full name of this package. */ 40 | #undef PACKAGE_NAME 41 | 42 | /* Define to the full name and version of this package. */ 43 | #undef PACKAGE_STRING 44 | 45 | /* Define to the one symbol short name of this package. */ 46 | #undef PACKAGE_TARNAME 47 | 48 | /* Define to the home page for this package. */ 49 | #undef PACKAGE_URL 50 | 51 | /* Define to the version of this package. */ 52 | #undef PACKAGE_VERSION 53 | 54 | /* Define to 1 if you have the ANSI C header files. */ 55 | #undef STDC_HEADERS 56 | 57 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 58 | , or is not used. If the typedef were allowed, the 59 | #define below would cause a syntax error. */ 60 | #undef _UINT32_T 61 | 62 | /* Define to `unsigned int' if does not define. */ 63 | #undef size_t 64 | 65 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 66 | such a type exists and the standard includes do not define it. */ 67 | #undef uint32_t 68 | -------------------------------------------------------------------------------- /tools/gps_preprocess/gps_preprocess.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | #include "../../json/json.h" 10 | 11 | //accept c_str as input parameters. 12 | #define debug_2_console(fmt,args...) \ 13 | do{ \ 14 | time_t t_time; \ 15 | time(&t_time); \ 16 | printf("%s", ctime(&t_time)); \ 17 | printf(fmt,##args); \ 18 | }while(0) 19 | 20 | //accept c_str as input parameters. 21 | #define debug_2_file(fmt,args...) \ 22 | do{ \ 23 | FILE* fp; \ 24 | fp = fopen("log", "a+"); \ 25 | fprintf(fp, fmt, ##args); \ 26 | fclose(fp); \ 27 | }while(0) 28 | 29 | #define DEBUG_2_CONSOLE 30 | 31 | #ifdef DEBUG_2_FILE 32 | #define debug_msg(fmt,args...) debug_2_file(fmt,##args) 33 | #elif defined DEBUG_2_CONSOLE 34 | #define debug_msg(fmt,args...) debug_2_console(fmt,##args) 35 | #else 36 | #define debug_msg(fmt,args...) do{} while(0) 37 | #endif 38 | 39 | 40 | 41 | class GpsPreprocess { 42 | 43 | public: 44 | 45 | GpsPreprocess(string data_file=""); 46 | int getErrno(); 47 | string getErrMsg(); 48 | 49 | void loadJsonGps(string gps_file); 50 | void dumpJsonGps(string dump_file=""); 51 | void dumpJsonGpsBeauty(string dump_file=""); 52 | void appendLongSpeed(); 53 | void appendShortSpeed(); 54 | void appendLineHeading(); 55 | 56 | private: 57 | 58 | static constexpr double DEF_PI = 3.14159265359; // PI 59 | static constexpr double DEF_2PI = 6.28318530712; // 2*PI 60 | static constexpr double DEF_PI180 = 0.01745329252; // PI/180.0 61 | static constexpr double DEF_R = 6370693.5; // radius of earth 62 | 63 | json js; 64 | FILE *_logger; 65 | int errno; 66 | string errmsg; 67 | 68 | void init(string data_file); 69 | bool isEqualDouble(double val1, double val2); 70 | double calLineDistance(double start_lng, double start_lat, double end_lng, double end_lat); 71 | double calShortDistance(double lon1, double lat1, double lon2, double lat2); 72 | double calLongDistance(double lon1, double lat1, double lon2, double lat2); 73 | double calShortSpeed(double lon1, double lat1, double lon2, double lat2, double last_time, double time); 74 | double calLongSpeed(double lon1, double lat1, double lon2, double lat2, double last_time, double time); 75 | double calLineHeading(double lon1, double lat1, double lon2, double lat2); 76 | }; 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/iter-map-matching/common.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | #include "common.h" 13 | 14 | vector SplitBySep(string str, string sep) 15 | { 16 | size_t pos, old_pos=0; 17 | string t_str; 18 | vector result; 19 | result.clear(); 20 | 21 | if(str.empty()) 22 | return result; 23 | 24 | if(sep.empty()) { 25 | result.push_back(str); 26 | return result; 27 | } 28 | 29 | pos = str.find(sep, 0); 30 | 31 | while(pos != string::npos) 32 | { 33 | t_str = str.substr(old_pos, pos-old_pos); 34 | result.push_back(t_str); 35 | old_pos = pos+1; 36 | pos = str.find(sep, old_pos); 37 | } 38 | 39 | t_str = str.substr(old_pos); 40 | result.push_back(t_str); 41 | 42 | return result; 43 | } 44 | 45 | void EchoRunning() 46 | { 47 | static int i = 0; 48 | 49 | int j = i % 4; 50 | 51 | switch(j) 52 | { 53 | case 0: 54 | printf("\b\b\b---"); 55 | break; 56 | case 1: 57 | printf("\b\b\b\\\\\\"); 58 | break; 59 | case 2: 60 | printf("\b\b\b|||"); 61 | break; 62 | case 3: 63 | printf("\b\b\b///"); 64 | break; 65 | } 66 | } 67 | 68 | double String2Double(string str) 69 | { 70 | size_t i, len; 71 | size_t first_pos, last_pos; 72 | 73 | if("" == str) 74 | return 0.0; 75 | 76 | first_pos = str.find_first_of("\""); 77 | last_pos = str.find_last_of("\""); 78 | 79 | if(string::npos != first_pos && string::npos != last_pos && first_pos != last_pos) 80 | str = str.substr(first_pos+1, last_pos-1); 81 | 82 | len = str.length(); 83 | for(i = 0; i < len; i++) 84 | { 85 | if(!isdigit(str[i]) && '.' != str[i]) 86 | return 0.0; 87 | } 88 | 89 | return strtold(str.c_str(), NULL); 90 | } 91 | 92 | 93 | string Double2String(double val) 94 | { 95 | stringstream ss; 96 | string str; 97 | 98 | ss << val; 99 | str = ss.str(); 100 | 101 | return str; 102 | } 103 | 104 | double Min(double val1, double val2) 105 | { 106 | if(val1 <= val2) 107 | return val1; 108 | return val2; 109 | } 110 | 111 | #define DEVIATION 1.E-10 112 | bool isEqualDouble(double val1, double val2) 113 | { 114 | if(fabs(val1-val2) <= DEVIATION) 115 | return true; 116 | return false; 117 | } 118 | 119 | -------------------------------------------------------------------------------- /src/iter-map-matching/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_INTTYPES_H 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_MEMORY_H 1 9 | 10 | /* Define to 1 if you have the `sqrt' function. */ 11 | /* #undef HAVE_SQRT */ 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_STDINT_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_STDLIB_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_STRINGS_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_STRING_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_SYS_STAT_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_SYS_TYPES_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_UNISTD_H 1 33 | 34 | /* Define to 1 if the system has the type `_Bool'. */ 35 | #define HAVE__BOOL 1 36 | 37 | /* Define to the address where bug reports for this package should be sent. */ 38 | #define PACKAGE_BUGREPORT "msl.fulong@gmail.com" 39 | 40 | /* Define to the full name of this package. */ 41 | #define PACKAGE_NAME "iter_map_matcher" 42 | 43 | /* Define to the full name and version of this package. */ 44 | #define PACKAGE_STRING "iter_map_matcher 0.1" 45 | 46 | /* Define to the one symbol short name of this package. */ 47 | #define PACKAGE_TARNAME "iter_map_matcher" 48 | 49 | /* Define to the home page for this package. */ 50 | #define PACKAGE_URL "" 51 | 52 | /* Define to the version of this package. */ 53 | #define PACKAGE_VERSION "0.1" 54 | 55 | /* Define to 1 if you have the ANSI C header files. */ 56 | #define STDC_HEADERS 1 57 | 58 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 59 | , or is not used. If the typedef were allowed, the 60 | #define below would cause a syntax error. */ 61 | /* #undef _UINT32_T */ 62 | 63 | /* Define to `unsigned int' if does not define. */ 64 | /* #undef size_t */ 65 | 66 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 67 | such a type exists and the standard includes do not define it. */ 68 | /* #undef uint32_t */ 69 | -------------------------------------------------------------------------------- /src/simple-map-matching/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_INTTYPES_H 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_MEMORY_H 1 9 | 10 | /* Define to 1 if you have the `sqrt' function. */ 11 | /* #undef HAVE_SQRT */ 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_STDINT_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_STDLIB_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_STRINGS_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_STRING_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_SYS_STAT_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_SYS_TYPES_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_UNISTD_H 1 33 | 34 | /* Define to 1 if the system has the type `_Bool'. */ 35 | #define HAVE__BOOL 1 36 | 37 | /* Define to the address where bug reports for this package should be sent. */ 38 | #define PACKAGE_BUGREPORT "msl.fulong@gmail.com" 39 | 40 | /* Define to the full name of this package. */ 41 | #define PACKAGE_NAME "simple_map_matcher" 42 | 43 | /* Define to the full name and version of this package. */ 44 | #define PACKAGE_STRING "simple_map_matcher 0.1" 45 | 46 | /* Define to the one symbol short name of this package. */ 47 | #define PACKAGE_TARNAME "simple_map_matcher" 48 | 49 | /* Define to the home page for this package. */ 50 | #define PACKAGE_URL "" 51 | 52 | /* Define to the version of this package. */ 53 | #define PACKAGE_VERSION "0.1" 54 | 55 | /* Define to 1 if you have the ANSI C header files. */ 56 | #define STDC_HEADERS 1 57 | 58 | /* Define for Solaris 2.5.1 so the uint32_t typedef from , 59 | , or is not used. If the typedef were allowed, the 60 | #define below would cause a syntax error. */ 61 | /* #undef _UINT32_T */ 62 | 63 | /* Define to `unsigned int' if does not define. */ 64 | /* #undef size_t */ 65 | 66 | /* Define to the type of an unsigned integer type of width exactly 32 bits if 67 | such a type exists and the standard includes do not define it. */ 68 | /* #undef uint32_t */ 69 | -------------------------------------------------------------------------------- /tools/distill_roads/distill_roads.php: -------------------------------------------------------------------------------- 1 | $road_segs[$i], 'lng' => $road_segs[$i+1]); 58 | $positions[] = $position; 59 | } 60 | $road_positions[$road_id] = $positions; 61 | 62 | } 63 | return $road_positions; 64 | } 65 | 66 | function load_num_list($num_list_file) 67 | { 68 | $num_list_string = file_get_contents($num_list_file); 69 | $num_list = json_decode($num_list_string, True); 70 | return $num_list; 71 | } 72 | 73 | function dump_road_positions($road_positions, $dumpfile) 74 | { 75 | //while(list($road_id, $positions) = each($road_positions)) 76 | foreach($road_positions as $positions) 77 | { 78 | $json_string = json_encode($positions); 79 | file_put_contents($dumpfile, $json_string."\n", FILE_APPEND); 80 | } 81 | } 82 | 83 | 84 | function main() 85 | { 86 | echo "Staring distill ... ...\n"; 87 | 88 | $roads = load_roads("geos.txt"); 89 | $num_list = load_num_list("road_list"); 90 | $road_positions = distill_roads($roads, $num_list); 91 | if(!empty($road_positions)) 92 | dump_road_positions($road_positions, "road_positions"); 93 | 94 | echo "Done.\n"; 95 | } 96 | 97 | 98 | main(); 99 | 100 | -------------------------------------------------------------------------------- /src/simple-map-matching/common.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | #include "common.h" 14 | 15 | vector SplitBySep(string str, string sep) 16 | { 17 | size_t pos, old_pos=0; 18 | string t_str; 19 | vector result; 20 | result.clear(); 21 | 22 | if(str.empty()) 23 | return result; 24 | 25 | if(sep.empty()) { 26 | result.push_back(str); 27 | return result; 28 | } 29 | 30 | pos = str.find(sep, 0); 31 | 32 | while(pos != string::npos) 33 | { 34 | t_str = str.substr(old_pos, pos-old_pos); 35 | result.push_back(t_str); 36 | old_pos = pos+1; 37 | pos = str.find(sep, old_pos); 38 | } 39 | 40 | t_str = str.substr(old_pos); 41 | result.push_back(t_str); 42 | 43 | return result; 44 | } 45 | 46 | void EchoRunning() 47 | { 48 | static int i = 0; 49 | 50 | int j = i % 4; 51 | 52 | switch(j) 53 | { 54 | case 0: 55 | printf("\b\b\b---"); 56 | break; 57 | case 1: 58 | printf("\b\b\b\\\\\\"); 59 | break; 60 | case 2: 61 | printf("\b\b\b|||"); 62 | break; 63 | case 3: 64 | printf("\b\b\b///"); 65 | break; 66 | } 67 | } 68 | 69 | double String2Double(string str) 70 | { 71 | size_t i, len; 72 | size_t first_pos, last_pos; 73 | 74 | if("" == str) 75 | return 0.0; 76 | 77 | first_pos = str.find_first_of("\""); 78 | last_pos = str.find_last_of("\""); 79 | 80 | if(string::npos != first_pos && string::npos != last_pos && first_pos != last_pos) 81 | str = str.substr(first_pos+1, last_pos-1); 82 | 83 | len = str.length(); 84 | for(i = 0; i < len; i++) 85 | { 86 | if(!isdigit(str[i]) && '.' != str[i]) 87 | return 0.0; 88 | } 89 | 90 | return strtold(str.c_str(), NULL); 91 | } 92 | 93 | 94 | string Double2String(double val) 95 | { 96 | /* 97 | stringstream ss; 98 | string str; 99 | 100 | ss.precision(10); 101 | ss << val; 102 | str = ss.str(); 103 | */ 104 | 105 | string str; 106 | #define DOUBLE_BUF_LEN 64 107 | char buffer[DOUBLE_BUF_LEN]; 108 | memset(buffer, 0, DOUBLE_BUF_LEN); 109 | sprintf(buffer, "%f", val); 110 | str = string(buffer); 111 | 112 | return str; 113 | } 114 | 115 | double Min(double val1, double val2) 116 | { 117 | if(val1 <= val2) 118 | return val1; 119 | return val2; 120 | } 121 | 122 | #define DEVIATION 1.E-10 123 | bool isEqualDouble(double val1, double val2) 124 | { 125 | if(fabs(val1-val2) <= DEVIATION) 126 | return true; 127 | return false; 128 | } 129 | 130 | -------------------------------------------------------------------------------- /src/robust-map-matching/robust-map-matching.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * impletation of robust map match algorithm. 3 | * 4 | * @date: 2014-12-21 5 | * @author: lifulong 6 | **/ 7 | 8 | #include 9 | 10 | using namespace std; 11 | 12 | #define NUM_ROADS_THRESHOLD 5 13 | #define MinNumOfMatchesThreshold 5 14 | 15 | struct r_point { 16 | double lat; 17 | double lng; 18 | }; 19 | 20 | 21 | struct r_trajectory { 22 | struct r_point point; 23 | int timestamp; 24 | }; 25 | 26 | 27 | struct r_edge { 28 | struct start_point; 29 | struct end_point; 30 | }; 31 | 32 | 33 | struct r_road { 34 | }; 35 | 36 | struct match { 37 | struct point raw_point; 38 | int timestamp; 39 | struct point map_point; 40 | struct edge edge; 41 | }; 42 | 43 | 44 | /** 45 | * 46 | * 47 | * 48 | */ 49 | ProcessTransitions(vector roads, struct match match, vector prev) 50 | { 51 | vector match_set; 52 | 53 | //match_set = {m | m -> prev && m connected to match} 54 | 55 | if(match_set.length() < MinNumOfMatchesThreshold) 56 | match_set = prev; 57 | 58 | order(match_set) by desc cost(m) 59 | 60 | for(vector::iterator iter = match_set.start(); iter < match_set.end(); iter++) 61 | { 62 | if(cost(iter->second) > cost(match)) 63 | break; 64 | tc = cost(iter->second) + TransitionsCost(iter->second, match); 65 | if(tc < cost(match)) 66 | { 67 | cost(match) = tc; 68 | list(match) = l(iter->second) U [iter->second] 69 | } 70 | } 71 | } 72 | 73 | 74 | /** 75 | * 76 | * 77 | * 78 | */ 79 | vector MapMatcher(vector roads, vector trajectorys) 80 | { 81 | int i, j, points_num; 82 | double distance; 83 | double cost[points_num][NUM_ROADS_THRESHOLD]; 84 | struct point map_point; 85 | vector list; 86 | vector prev, next; 87 | vector nearby; 88 | 89 | list.clear(); 90 | prev.clear(); 91 | next.clear(); 92 | points_num = trajectorys.length(); 93 | 94 | for(i = 0; i < points_num; i++) 95 | { 96 | struct point current_point = trajectorys[i]; 97 | nearby.clear(); 98 | while(nearby.length() < NUM_ROADS_THRESHOLD) 99 | { 100 | nearby.push_back(); 101 | distance *= 2; 102 | } 103 | 104 | next.clear(); 105 | 106 | for(j = 1; j < nearby.length(); j++) 107 | { 108 | current_edge = nearby[j]; 109 | map_point = projection(current_point, current_edge); 110 | struct match match = {}; 111 | next.push_back(match); 112 | if(i > 1) 113 | { 114 | cost[i][j] = MAX_VALUE; 115 | ProcessTransition(roads, match, prev); 116 | } 117 | else 118 | { 119 | cost[i][j] = 0; 120 | list = {}; 121 | } 122 | } 123 | 124 | prev = next; 125 | } 126 | 127 | 128 | return list; 129 | } 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /tools/bash/fix_road_network/fix_road_network.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | fix_file=deviation 4 | 5 | edges_file=edges.txt 6 | geos_file=geos.txt 7 | vertices_file=vertices.txt 8 | 9 | edges_fix_file=${edges_file%"."}"_valid.txt" 10 | geos_fix_file=${geos_file%"."}"_valid.txt" 11 | vertices_fix_file=${vertices_file%"."}"_valid.txt" 12 | 13 | fix_lat="" 14 | fix_lng="" 15 | 16 | function load_fix_info() 17 | { 18 | echo `date +%H:%M:%S`"[INFO] start load fix info ..." 19 | fix_info_file=$1 20 | 21 | while read line 22 | do 23 | read fix_lng fix_lat<<-EOF 24 | $line 25 | EOF 26 | return 27 | done<$fix_info_file 28 | 29 | if [ "$fix_lng" == "" -o "$fix_lat" == "" ];then 30 | echo -e "load fix info error.\texited.\n"; 31 | exit 1; 32 | fi 33 | echo `date +%H:%M:%S`"[INFO] end load fix info ..." 34 | } 35 | 36 | function fix_edges() 37 | { 38 | return 39 | } 40 | 41 | function fix_vertices() 42 | { 43 | echo `date +%H:%M:%S`"[INFO] start fix vertices ..." 44 | local vertices_file=$1 45 | local vertices_fix_file=$2 46 | 47 | [ -f $vertices_fix_file ] && { rm -f $vertices_fix_file; } 48 | 49 | let i=0 50 | while read line 51 | do 52 | 53 | let i=$i+1 54 | let label=$i%4 55 | 56 | case $label in 57 | 0) echo -n -e "\b\b\b---";; 58 | 1) echo -n -e "\b\b\b\\\\\\";; 59 | 2) echo -n -e "\b\b\b|||";; 60 | 3) echo -n -e "\b\b\b///";; 61 | esac 62 | 63 | read node_id lat lng<<-EOF 64 | $line 65 | EOF 66 | 67 | lat=`echo "scale=6;$lat+$fix_lat" | bc` 68 | lng=`echo "scale=6;$lng+$fix_lng" | bc` 69 | echo -e "$node_id\t$lat\t$lng" >> $vertices_fix_file 70 | 71 | done<$vertices_file 72 | echo `date +%H:%M:%S`"[INFO] end fix vertices ..." 73 | } 74 | 75 | 76 | function fix_geos() 77 | { 78 | echo `date +%H:%M:%S`"[INFO] start fix geos ..." 79 | local geos_file=$1 80 | local geos_fix_file=$2 81 | 82 | [ -f $geos_fix_file ] && { rm -f $geos_fix_file; } 83 | 84 | let i=0 85 | while read line 86 | do 87 | 88 | let i=$i+1 89 | let label=$i%4 90 | 91 | case $label in 92 | 0) echo -n -e "\b\b\b---";; 93 | 1) echo -n -e "\b\b\b\\\\\\";; 94 | 2) echo -n -e "\b\b\b|||";; 95 | 3) echo -n -e "\b\b\b///";; 96 | esac 97 | 98 | read seg_id rest<<-EOF 99 | $line 100 | EOF 101 | 102 | new_road="$seg_id" 103 | while [ "$rest" != "" ] 104 | do 105 | read lat lng rest<<-EOF 106 | $rest 107 | EOF 108 | lat=`echo "scale=6;$lat+$fix_lat" | bc` 109 | lng=`echo "scale=6;$lng+$fix_lng" | bc` 110 | new_road=${new_road}"\t"${lat}"\t"${lng} 111 | done 112 | 113 | echo -e "$new_road" >> $geos_fix_file 114 | 115 | done<$geos_file 116 | echo `date +%H:%M:%S`"[INFO] end fix geos ..." 117 | } 118 | 119 | 120 | load_fix_info $fix_file 121 | #fix_vertices $vertices_file $vertices_fix_file 122 | fix_geos $geos_file $geos_fix_file 123 | 124 | -------------------------------------------------------------------------------- /src/map-index/serve.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Use Ace. 4 | * 5 | * 6 | * 7 | ***/ 8 | 9 | #include "map_index.h" 10 | 11 | #ifdef TEST_MAP_INDEX 12 | 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | #include 19 | 20 | void dumpMapPoints(vector maps, string dumpfile) 21 | { 22 | FILE *fp; 23 | 24 | if("" == dumpfile) 25 | return; 26 | 27 | if((fp = fopen(dumpfile.c_str(), "w")) == NULL) 28 | { 29 | debug_msg("dumpMapPoints:open %s error.\n", dumpfile.c_str()); 30 | return; 31 | } 32 | 33 | for(vector::iterator iter = maps.begin(); iter != maps.end(); iter++) 34 | { 35 | fprintf(fp, "%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", iter->start_lng, iter->start_lat, iter->end_lng, iter->end_lat, iter->lng, iter->lat, iter->map_lng, iter->map_lat); 36 | } 37 | 38 | fclose(fp); 39 | } 40 | 41 | void dumpMapSegs(vector maps, string dumpfile) 42 | { 43 | FILE *fp; 44 | 45 | if("" == dumpfile) 46 | return; 47 | 48 | if((fp = fopen(dumpfile.c_str(), "w")) == NULL) 49 | { 50 | debug_msg("dumpMapPoints:open %s error.\n", dumpfile.c_str()); 51 | return; 52 | } 53 | 54 | for(vector::iterator iter = maps.begin(); iter != maps.end(); iter++) 55 | { 56 | fprintf(fp, "%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%d\t%f\t%f\n", iter->seg_id, iter->start_lng, iter->start_lat, iter->end_lng, iter->end_lat, iter->lng, iter->lat, iter->map_lng, iter->map_lat, iter->on_seg, iter->distance, iter->min_distance); 57 | } 58 | 59 | fclose(fp); 60 | } 61 | 62 | void test() 63 | { 64 | vector maps; 65 | maps.clear(); 66 | 67 | MapIndex *map_index = new MapIndex("", "", "", "segs.txt", "grid_info", "grid.txt"); 68 | printf("begin query grid segs......\n"); 69 | maps = map_index->getGridSegs(116.578234, 39.929855, 100); 70 | 71 | printf("maps_size: %u\n", maps.size()); 72 | for(vector::iterator iter = maps.begin(); iter != maps.end(); iter++) 73 | { 74 | printf("Map:\n"); 75 | printf("seg_id:\t%d\n", iter->seg_id); 76 | printf("edge_id:\t%d\n", iter->edge_id); 77 | printf("start_lng:\t%f\n", iter->start_lng); 78 | printf("start_lat:\t%f\n", iter->start_lat); 79 | printf("end_lng:\t%f\n", iter->end_lng); 80 | printf("end_lat:\t%f\n", iter->end_lat); 81 | printf("lng:\t%f\n", iter->lng); 82 | printf("lat:\t%f\n", iter->lat); 83 | printf("map_lng:\t%f\n", iter->map_lng); 84 | printf("map_lat:\t%f\n", iter->map_lat); 85 | printf("distance:\t%f\n", iter->distance); 86 | printf("min_distance:\t%f\n", iter->min_distance); 87 | printf("on_seg:\t%d\n", iter->on_seg); 88 | printf("\n"); 89 | } 90 | 91 | dumpMapSegs(maps, "dump_map_segs.txt"); 92 | dumpMapPoints(maps, "dump_map_points.txt"); 93 | } 94 | 95 | int main() 96 | { 97 | test(); 98 | return 0; 99 | } 100 | 101 | #else 102 | 103 | int main() 104 | { 105 | return 0; 106 | } 107 | 108 | #endif 109 | 110 | -------------------------------------------------------------------------------- /tools/gen_grid/gen_grid.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | //accept c_str as input parameters. 10 | #define debug_2_console(fmt,args...) \ 11 | do{ \ 12 | time_t t_time; \ 13 | time(&t_time); \ 14 | printf("%s", ctime(&t_time)); \ 15 | printf(fmt,##args); \ 16 | }while(0) 17 | 18 | //accept c_str as input parameters. 19 | #define debug_2_file(fmt,args...) \ 20 | do{ \ 21 | FILE* fp; \ 22 | fp = fopen("log", "a+"); \ 23 | fprintf(fp, fmt, ##args); \ 24 | fclose(fp); \ 25 | }while(0) 26 | 27 | #define DEBUG_2_CONSOLE 28 | 29 | #ifdef DEBUG_2_FILE 30 | #define debug_msg(fmt,args...) debug_2_file(fmt,##args) 31 | #elif defined DEBUG_2_CONSOLE 32 | #define debug_msg(fmt,args...) debug_2_console(fmt,##args) 33 | #else 34 | #define debug_msg(fmt,args...) do{} while(0) 35 | #endif 36 | 37 | 38 | #define BJ_START_LNG 115.25 39 | #define BJ_START_LAT 39.26 40 | #define BJ_END_LNG 117.4 41 | #define BJ_END_LAT 41.1 42 | 43 | #define LNG_GAP 0.005 44 | #define LAT_GAP 0.005 45 | 46 | #define START_LNG BJ_START_LNG 47 | #define START_LAT BJ_START_LAT 48 | #define END_LNG BJ_END_LNG 49 | #define END_LAT BJ_END_LAT 50 | 51 | struct seg { 52 | int seg_id; 53 | int edge_id; 54 | double start_lng; 55 | double start_lat; 56 | double end_lng; 57 | double end_lat; 58 | }; 59 | 60 | struct grid_index { 61 | int i, j; 62 | }; 63 | 64 | struct grid_node { 65 | double start_lng, end_lng; 66 | double start_lat, end_lat; 67 | vector node_segs; 68 | }; 69 | 70 | class GenMapGrid { 71 | 72 | public: 73 | 74 | GenMapGrid(string segs_file); 75 | int getErrno(); 76 | string getErrMsg(); 77 | void genGrid(string segs_file); 78 | void dumpGrid(string dump_file); 79 | 80 | private: 81 | 82 | FILE *_logger; 83 | struct grid_node **grid; 84 | double start_lat, end_lat, start_lng, end_lng, lat_gap, lng_gap; 85 | int lat_num, lng_num; 86 | int errno; 87 | string errmsg; 88 | 89 | void _init(); 90 | double _round(double val, double mod, char type); 91 | void _preprocess(string type); 92 | void _initGrid(); 93 | struct grid_index getGridIndexByPoint(double lng, double lat); 94 | void updateGrid(struct grid_index index, struct seg seg); 95 | void updateHorizontalGrids(double k, double start_lng, double start_lat, 96 | double end_lng, double end_lat, struct seg seg); 97 | void updateVerticalGrids(double k, double start_lng, double start_lat, 98 | double end_lng, double end_lat, struct seg seg); 99 | void updateHorizOrientGrids(double k, double start_lng, double start_lat, 100 | double end_lng, double end_lat, struct seg seg); 101 | void updateVertOrientGrids(double k, double start_lng, double start_lat, 102 | double end_lng, double end_lat, struct seg seg); 103 | void updateGrids(struct seg seg); 104 | }; 105 | 106 | 107 | -------------------------------------------------------------------------------- /tools/gen_distance_table/lat_table.txt: -------------------------------------------------------------------------------- 1 | lat 0.0001 0.0002 0.0005 0.0010 0.0020 0.0050 0.0100 0.0200 0.0500 0.1000 0.2000 0.5000 1.0000 2 | 39.4000 8.5921 17.1840 42.9600 85.9199 171.8399 429.5996 859.1992 1718.3984 4295.9959 8591.9915 17183.9804 42959.9047 85919.4800 3 | 39.5000 8.5796 17.1594 42.8983 85.7966 171.5932 428.9831 857.9661 1715.9322 4289.8305 8579.6607 17159.3187 42898.2505 85796.1706 4 | 39.6000 8.5664 17.1341 42.8364 85.6730 171.3461 428.3652 856.7304 1713.4608 4283.6520 8567.3037 17134.6048 42836.4656 85672.5999 5 | 39.7000 8.5554 17.1099 42.7747 85.5492 171.0984 427.7461 855.4921 1710.9842 4277.4605 8554.9207 17109.8387 42774.5502 85548.7682 6 | 39.8000 8.5427 17.0852 42.7126 85.4252 170.8503 427.1256 854.2512 1708.5024 4271.2560 8542.5116 17085.0205 42712.5046 85424.6759 7 | 39.9000 8.5300 17.0601 42.6504 85.3008 170.6015 426.5038 853.0077 1706.0154 4265.0384 8530.0764 17060.1502 42650.3288 85300.3234 8 | 40.0000 8.5174 17.0350 42.5880 85.1761 170.3523 425.8808 851.7616 1703.5231 4258.8078 8517.6153 17035.2280 42588.0230 85175.7111 9 | 40.1000 8.5052 17.0104 42.5257 85.0513 170.1026 425.2564 850.5129 1701.0257 4252.5643 8505.1283 17010.2539 42525.5876 85050.8393 10 | 40.2000 8.4925 16.9852 42.4630 84.9261 169.8523 424.6308 849.2616 1698.5231 4246.3078 8492.6153 16985.2279 42463.0226 84925.7084 11 | 40.3000 8.4802 16.9602 42.4005 84.8008 169.6016 424.0038 848.0077 1696.0154 4240.0384 8480.0765 16960.1502 42400.3283 84800.3189 12 | 40.4000 8.4680 16.9352 42.3376 84.6752 169.3503 423.3756 846.7512 1693.5024 4233.7561 8467.5118 16935.0209 42337.5048 84674.6710 13 | 40.5000 8.4552 16.9099 42.2747 84.5492 169.0985 422.7461 845.4922 1690.9844 4227.4608 8454.9213 16909.8399 42274.5523 84548.7652 14 | 40.6000 8.4424 16.8849 42.2116 84.4231 168.8461 422.1153 844.2306 1688.4611 4221.1527 8442.3051 16884.6075 42211.4711 84422.6018 15 | 40.7000 8.4296 16.8592 42.1483 84.2966 168.5933 421.4832 842.9664 1685.9327 4214.8318 8429.6632 16859.3236 42148.2613 84296.1813 16 | 40.8000 8.4168 16.8338 42.0848 84.1699 168.3399 420.8498 841.6996 1683.3992 4208.4980 8416.9956 16833.9884 42084.9231 84169.5041 17 | 40.9000 8.4045 16.8086 42.0216 84.0431 168.0861 420.2151 840.4303 1680.8606 4202.1513 8404.3023 16808.6019 42021.4567 84042.5704 18 | 41.0000 8.3921 16.7834 41.9580 83.9159 167.8317 419.5792 839.1584 1678.3168 4195.7919 8391.5835 16783.1642 41957.8623 83915.3807 19 | 41.1000 8.3787 16.7576 41.8941 83.7883 167.5768 418.9420 837.8839 1675.7679 4189.4197 8378.8390 16757.6753 41894.1400 83787.9354 20 | 41.2000 8.3663 16.7321 41.8303 83.6607 167.3214 418.3035 836.6070 1673.2139 4183.0347 8366.0691 16732.1354 41830.2902 83660.2349 21 | 41.3000 8.3534 16.7067 41.7664 83.5328 167.0655 417.6637 835.3274 1670.6548 4176.6370 8353.2737 16706.5446 41766.3130 83532.2795 22 | 41.4000 8.3404 16.6808 41.7023 83.4045 166.8091 417.0227 834.0453 1668.0907 4170.2266 8340.4528 16680.9028 41702.2085 83404.0697 23 | 41.5000 8.3280 16.6554 41.6381 83.2761 166.5522 416.3804 832.7607 1665.5214 4163.8034 8327.6065 16655.2103 41637.9770 83275.6059 24 | -------------------------------------------------------------------------------- /src/simple-map-matching/test.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace std; 5 | 6 | #include "../../json/json.h" 7 | #include "common.h" 8 | #include "simple_matcher.h" 9 | 10 | #define USAGE(method) ("Usage:\n"+method+"\tfilename\n") 11 | 12 | json loadJsonGps(string gps_file) 13 | { 14 | json js; 15 | string json_string = ""; 16 | ifstream infile; 17 | #undef LINE_BUFFER_LEN 18 | #define LINE_BUFFER_LEN 1*1024*1024 19 | char buffer[LINE_BUFFER_LEN]; 20 | 21 | js.clear(); 22 | infile.open(gps_file, ios_base::in); 23 | if(!infile.good()) 24 | return js; 25 | 26 | while(infile.getline(buffer, LINE_BUFFER_LEN).good()) 27 | { 28 | json_string += string(buffer); 29 | } 30 | json_string += string(buffer); 31 | 32 | infile.close(); 33 | 34 | js = json::parse(json_string); 35 | 36 | //debug_msg("json_size:%d.\n", js.size()); 37 | 38 | return js; 39 | } 40 | 41 | void dumpJsonGps(json js, string dump_file) 42 | { 43 | string json_string = ""; 44 | FILE *fp; 45 | 46 | if("" != dump_file) { 47 | fp = fopen(dump_file.c_str(), "w"); 48 | //FIXME: log the error here. 49 | if(NULL == fp) 50 | fp = stdout; 51 | } 52 | else 53 | fp = stdout; 54 | 55 | json_string = js.to_string(); 56 | 57 | fwrite(json_string.c_str(), json_string.length(), 1, fp); 58 | 59 | if(stdout != fp) 60 | fclose(fp); 61 | } 62 | 63 | 64 | void test(string filename) 65 | { 66 | unsigned int i, len; 67 | size_t pos; 68 | struct position position; 69 | vector points; 70 | string dumpfile, basename, ext; 71 | json js; 72 | Matcher *matcher = new Matcher(); 73 | 74 | pos = filename.find_last_of("."); 75 | if(string::npos == pos) 76 | { 77 | basename = filename; 78 | ext = ""; 79 | dumpfile = basename + "_valid"; 80 | } 81 | else 82 | { 83 | basename = filename.substr(0, pos); 84 | ext = filename.substr(pos+1); 85 | dumpfile = basename + "_valid" + "." + ext; 86 | } 87 | 88 | js = loadJsonGps(filename); 89 | len = js.size(); 90 | for(i = 0; i < len; i++) 91 | { 92 | position.lat = String2Double(js[i]["lat"]); 93 | position.lng = String2Double(js[i]["lng"]); 94 | points = matcher->match(0, position); 95 | if(points.size() > 0) { 96 | js[i]["lat"] = Double2String(points[0].lat); 97 | js[i]["lng"] = Double2String(points[0].lng); 98 | } else { 99 | debug_msg("points size error:%u\n", points.size()); 100 | } 101 | /* 102 | for(vector::iterator iter=points.begin(); iter != points.end(); iter++) 103 | { 104 | js[i]["lat"] = Double2String(iter->lat); 105 | js[i]["lng"] = Double2String(iter->lng); 106 | } 107 | */ 108 | } 109 | 110 | dumpJsonGps(js, dumpfile); 111 | } 112 | 113 | int main(int argc ,char *argv[]) 114 | { 115 | string filename; 116 | 117 | if(1 != argc && 2 != argc) { 118 | string usage = USAGE(string(argv[0])); 119 | debug_msg("%s", usage.c_str()); 120 | return 1; 121 | } 122 | 123 | if(2 == argc) 124 | filename = string(argv[1]); 125 | else 126 | filename = "./../../datasets/9710356_1.json"; 127 | 128 | test(filename); 129 | 130 | return 0; 131 | } 132 | 133 | 134 | -------------------------------------------------------------------------------- /tools/query_grid/query_grid.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | //accept c_str as input parameters. 10 | #define debug_2_console(fmt,args...) \ 11 | do{ \ 12 | time_t t_time; \ 13 | time(&t_time); \ 14 | printf("%s", ctime(&t_time)); \ 15 | printf(fmt,##args); \ 16 | }while(0) 17 | 18 | //accept c_str as input parameters. 19 | #define debug_2_file(fmt,args...) \ 20 | do{ \ 21 | FILE* fp; \ 22 | fp = fopen("log", "a+"); \ 23 | fprintf(fp, fmt, ##args); \ 24 | fclose(fp); \ 25 | }while(0) 26 | 27 | #define DEBUG_2_CONSOLE 28 | 29 | #ifdef DEBUG_2_FILE 30 | #define debug_msg(fmt,args...) debug_2_file(fmt,##args) 31 | #elif defined DEBUG_2_CONSOLE 32 | #define debug_msg(fmt,args...) debug_2_console(fmt,##args) 33 | #else 34 | #define debug_msg(fmt,args...) do{} while(0) 35 | #endif 36 | 37 | 38 | #define BJ_START_LNG 115.25 39 | #define BJ_START_LAT 39.26 40 | #define BJ_END_LNG 117.4 41 | #define BJ_END_LAT 41.1 42 | 43 | #define LNG_GAP 0.005 44 | #define LAT_GAP 0.005 45 | 46 | #define START_LNG BJ_START_LNG 47 | #define START_LAT BJ_START_LAT 48 | #define END_LNG BJ_END_LNG 49 | #define END_LAT BJ_END_LAT 50 | 51 | struct seg { 52 | int seg_id; 53 | int edge_id; 54 | double start_lng; 55 | double start_lat; 56 | double end_lng; 57 | double end_lat; 58 | }; 59 | 60 | struct seg_point_map { 61 | int seg_id; 62 | int edge_id; 63 | double start_lng; 64 | double start_lat; 65 | double end_lng; 66 | double end_lat; 67 | 68 | double lng; 69 | double lat; 70 | double map_lng; 71 | double map_lat; 72 | double distance; 73 | double min_distance; 74 | bool on_seg; 75 | }; 76 | 77 | struct grid_index { 78 | int i, j; 79 | }; 80 | 81 | struct grid_node { 82 | double start_lng, end_lng; 83 | double start_lat, end_lat; 84 | double gap_lng, gap_lat; 85 | vector node_segs; 86 | }; 87 | 88 | class QueryGrid { 89 | 90 | public: 91 | 92 | QueryGrid(string segs_file, string grid_info, string grid_file); 93 | int getErrno(); 94 | string getErrMsg(); 95 | void loadSegs(string segs_file); 96 | void loadGrid(string grid_info, string grid_file); 97 | void setValue(string key, string value); 98 | vector getGridSegs(double lng, double lat, double distance=0); 99 | 100 | private: 101 | 102 | static const double DEF_PI = 3.14159265359; // PI 103 | static const double DEF_2PI = 6.28318530712; // 2*PI 104 | static const double DEF_PI180 = 0.01745329252; // PI/180.0 105 | static const double DEF_R = 6370693.5; // radius of earth 106 | 107 | FILE *_logger; 108 | vector segs; 109 | //map(index_stru, grid_node) 110 | struct grid_node **grid; 111 | double start_lat, end_lat, start_lng, end_lng, lat_gap, lng_gap; 112 | int lat_num, lng_num; 113 | int errno; 114 | string errmsg; 115 | 116 | void init(); 117 | void loadGridInfo(string grid_info); 118 | void dumpGridInfo(); 119 | void loadGridData(string grid_file); 120 | struct grid_index getGridIndexByPoint(double lng, double lat); 121 | double cal_line_distance(double start_lng, double start_lat, double end_lng, double end_lat); 122 | double cal_short_distance(double lon1, double lat1, double lon2, double lat2); 123 | double cal_long_distance(double lon1, double lat1, double lon2, double lat2); 124 | bool on_seg(double lng, double lat, double start_lng, double start_lat, double end_lng, double end_lat); 125 | seg_point_map mapGridSeg(double lng, double lat, seg seg); 126 | vector mapGridSegs(double lng, double lat, double distance, vector segs); 127 | }; 128 | 129 | 130 | -------------------------------------------------------------------------------- /src/simple-map-matching/simple_matcher.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @Thanks : The algothrim here base on 3 | * "A Map Matching Method for GPS Based Real-Time Vehicle Location" 4 | * Author : G. R. Jagadeesh, T. Srikanthan and X. D. Zhang 5 | * Nanyang Technological University, Singapore 6 | * Email : jagadeesh@pmail.ntu.edu.sg 7 | * 8 | * @Description : 9 | * 10 | * @Author : lifulong 11 | * @Email : msl.fulong@gmail.com 12 | * @Date : 2015-01-05 13 | **/ 14 | 15 | 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | #include 22 | 23 | #include "../map-index/map_index.h" 24 | 25 | 26 | //accept c_str as input parameters. 27 | #define debug_2_console(fmt,args...) \ 28 | do{ \ 29 | time_t t_time; \ 30 | time(&t_time); \ 31 | printf("%s", ctime(&t_time)); \ 32 | printf(fmt,##args); \ 33 | }while(0) 34 | 35 | //accept c_str as input parameters. 36 | #define debug_2_file(fmt,args...) \ 37 | do{ \ 38 | FILE* fp; \ 39 | fp = fopen("log", "a+"); \ 40 | fprintf(fp, fmt, ##args); \ 41 | fclose(fp); \ 42 | }while(0) 43 | 44 | #define DEBUG_2_CONSOLE 45 | 46 | #ifdef DEBUG_2_FILE 47 | #define debug_msg(fmt,args...) debug_2_file(fmt,##args) 48 | #elif defined DEBUG_2_CONSOLE 49 | #define debug_msg(fmt,args...) debug_2_console(fmt,##args) 50 | #else 51 | #define debug_msg(fmt,args...) do{} while(0) 52 | #endif 53 | 54 | 55 | /* 56 | struct point { 57 | double lng; 58 | double lat; 59 | }; 60 | 61 | struct seg { 62 | int seg_id; 63 | int edge_id; 64 | double start_lng; 65 | double start_lat; 66 | double end_lng; 67 | double end_lat; 68 | }; 69 | 70 | struct seg_point_map { 71 | int seg_id; 72 | int edge_id; 73 | double start_lng; 74 | double start_lat; 75 | double end_lng; 76 | double end_lat; 77 | 78 | double lng; 79 | double lat; 80 | double map_lng; 81 | double map_lat; 82 | double distance; 83 | double min_distance; 84 | bool on_seg; 85 | }; 86 | */ 87 | 88 | 89 | struct position { 90 | int timestamp; 91 | int gps_time; 92 | double lng; 93 | double lat; 94 | double accuracy; 95 | //string gps_type; 96 | }; 97 | 98 | struct map_point { 99 | int seg_id; 100 | int edge_id; 101 | double lng; 102 | double lat; 103 | double dis_deviation; //deviation 104 | double heading_deviation; //deviation 105 | }; 106 | 107 | struct trajectory { 108 | int uniq_id; 109 | vector positions; 110 | }; 111 | 112 | struct seg_candidate { 113 | struct seg seg; 114 | double seg_heading; 115 | double dis_deviation; //average distance 116 | double heading_deviation; //average heading 117 | int orientation; //在当前路段的行驶方向[0(unkown),1,-1] 118 | int map_point_num; 119 | }; 120 | 121 | struct map_track { 122 | int uniq_id; 123 | double last_lng; 124 | double last_lat; 125 | double last_dis; 126 | double last_heading; 127 | struct seg_candidate current_seg; 128 | //vector adjacent; //update by orientation 129 | #define MAX_CANDIDATE_LEN 5 130 | vector candidates; 131 | vector points; 132 | }; 133 | 134 | class Matcher { 135 | 136 | public: 137 | 138 | Matcher(); 139 | 140 | int initMatcher(); 141 | uint32_t genUniqId(); 142 | vector doMatch(struct position position, struct map_track map_track); 143 | vector match(uint32_t id, struct position position); 144 | vector batch_match(struct trajectory trajectory); 145 | 146 | private: 147 | 148 | static constexpr double DEF_PI = 3.14159265359; // PI 149 | static constexpr double DEF_2PI = 6.28318530712; // 2*PI 150 | static constexpr double DEF_PI180 = 0.01745329252; // PI/180.0 151 | static constexpr double DEF_R = 6370693.5; // radius of earth 152 | 153 | uint32_t current_id; 154 | uint32_t max_id; //assign it with (uint32_t)-1 155 | double query_distance; 156 | map track_map; 157 | //Logger *logger; 158 | 159 | //FIXME: temp map-index here, use map-index service later 160 | MapIndex *map_index; 161 | 162 | double calDistance(double lng1, double lat1, double lng2, double lat2); 163 | }; 164 | 165 | 166 | -------------------------------------------------------------------------------- /src/iter-map-matching/iter_matcher.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @Thanks : The algothrim here base on 3 | * "A Map Matching Method for GPS Based Real-Time Vehicle Location" 4 | * Author : G. R. Jagadeesh, T. Srikanthan and X. D. Zhang 5 | * Nanyang Technological University, Singapore 6 | * Email : jagadeesh@pmail.ntu.edu.sg 7 | * 8 | * @Description : 9 | * 10 | * @Author : lifulong 11 | * @Email : msl.fulong@gmail.com 12 | * @Date : 2015-01-05 13 | **/ 14 | 15 | 16 | #include 17 | #include 18 | 19 | using namespace std; 20 | 21 | #include "../map-index/map_index.h" 22 | 23 | 24 | //accept c_str as input parameters. 25 | #define debug_2_console(fmt,args...) \ 26 | do{ \ 27 | time_t t_time; \ 28 | time(&t_time); \ 29 | printf("%s", ctime(&t_time)); \ 30 | printf(fmt,##args); \ 31 | }while(0) 32 | 33 | //accept c_str as input parameters. 34 | #define debug_2_file(fmt,args...) \ 35 | do{ \ 36 | FILE* fp; \ 37 | fp = fopen("log", "a+"); \ 38 | fprintf(fp, fmt, ##args); \ 39 | fclose(fp); \ 40 | }while(0) 41 | 42 | #define DEBUG_2_CONSOLE 43 | 44 | #ifdef DEBUG_2_FILE 45 | #define debug_msg(fmt,args...) debug_2_file(fmt,##args) 46 | #elif defined DEBUG_2_CONSOLE 47 | #define debug_msg(fmt,args...) debug_2_console(fmt,##args) 48 | #else 49 | #define debug_msg(fmt,args...) do{} while(0) 50 | #endif 51 | 52 | 53 | /* 54 | struct point { 55 | double lng; 56 | double lat; 57 | }; 58 | 59 | struct seg { 60 | int seg_id; 61 | int edge_id; 62 | double start_lng; 63 | double start_lat; 64 | double end_lng; 65 | double end_lat; 66 | }; 67 | 68 | struct seg_point_map { 69 | int seg_id; 70 | int edge_id; 71 | double start_lng; 72 | double start_lat; 73 | double end_lng; 74 | double end_lat; 75 | 76 | double lng; 77 | double lat; 78 | double map_lng; 79 | double map_lat; 80 | double distance; 81 | double min_distance; 82 | bool on_seg; 83 | }; 84 | */ 85 | 86 | 87 | struct position { 88 | int timestamp; 89 | int gps_time; 90 | double lng; 91 | double lat; 92 | double accuracy; 93 | //string gps_type; 94 | }; 95 | 96 | struct map_point { 97 | int seg_id; 98 | int edge_id; 99 | double lng; 100 | double lat; 101 | double dis_deviation; //deviation 102 | double heading_deviation; //deviation 103 | }; 104 | 105 | struct trajectory { 106 | int uniq_id; 107 | vector positions; 108 | }; 109 | 110 | struct seg_candidate { 111 | struct seg seg; 112 | double seg_heading; 113 | double dis_deviation; //average distance 114 | double heading_deviation; //average heading 115 | int orientation; //在当前路段的行驶方向[0(unkown),1,-1] 116 | int map_point_num; 117 | }; 118 | 119 | struct map_track { 120 | int uniq_id; 121 | double last_lng; 122 | double last_lat; 123 | double last_dis; 124 | double last_heading; 125 | struct seg_candidate current_seg; 126 | //vector adjacent; //update by orientation 127 | #define MAX_CANDIDATE_LEN 5 128 | vector candidates; 129 | vector points; 130 | }; 131 | 132 | class Matcher { 133 | 134 | public: 135 | 136 | Matcher(); 137 | 138 | int initMatcher(); 139 | uint32_t genUniqId(); 140 | vector doMatch(struct position position, struct map_track map_track); 141 | vector match(uint32_t id, struct position position); 142 | vector batch_match(struct trajectory trajectory); 143 | 144 | private: 145 | 146 | static constexpr double DEF_PI = 3.14159265359; // PI 147 | static constexpr double DEF_2PI = 6.28318530712; // 2*PI 148 | static constexpr double DEF_PI180 = 0.01745329252; // PI/180.0 149 | static constexpr double DEF_R = 6370693.5; // radius of earth 150 | 151 | uint32_t current_id; 152 | uint32_t max_id; //assign it with (uint32_t)-1 153 | double query_distance; 154 | map track_map; 155 | //Logger *logger; 156 | 157 | //FIXME: temp map-index here, use map-index service later 158 | MapIndex *map_index; 159 | 160 | double calDistance(double lng1, double lat1, double lng2, double lat2); 161 | double calHeading(double lng1, double lat1, double lng2, double lat2); 162 | double headingResemblance(double seg_heading, double heading); 163 | double distanceResemblance(double average_distance, double distance); 164 | }; 165 | 166 | 167 | -------------------------------------------------------------------------------- /src/simple-map-matching/simple_matcher.cpp: -------------------------------------------------------------------------------- 1 | #define _ISOC99_SOURCE 2 | #include 3 | 4 | #include "common.h" 5 | #include "simple_matcher.h" 6 | 7 | /* 8 | struct position { 9 | int timestamp; 10 | int gps_time; 11 | double lng; 12 | double lat; 13 | double accuracy; 14 | //string gps_type; 15 | }; 16 | 17 | struct map_point { 18 | int seg_id; 19 | int edge_id; 20 | double lng; 21 | double lat; 22 | double dis_deviation; //deviation 23 | double heading_deviation; //deviation 24 | }; 25 | 26 | struct trajectory { 27 | int uniq_id; 28 | vector positions; 29 | }; 30 | 31 | struct map_track { 32 | int uniq_id; 33 | double curr_lng; 34 | double curr_lat; 35 | double curr_dis_deviation; 36 | double curr_heading_deviation; 37 | double dis_deviation; 38 | double heading_deviation; 39 | vector points; 40 | }; 41 | */ 42 | 43 | /* 44 | uint32_t current_id; 45 | uint32_t max_id; //assign it with (uint32_t)-1 46 | map track_hash; 47 | */ 48 | 49 | 50 | Matcher::Matcher() 51 | { 52 | this->initMatcher(); 53 | } 54 | 55 | int Matcher::initMatcher() 56 | { 57 | this->max_id = (uint32_t)-1; 58 | this->current_id = 0; 59 | this->query_distance = 100; 60 | this->map_index = new MapIndex("", "", "", "segs.txt", "grid_info", "grid.txt"); 61 | 62 | return 0; 63 | } 64 | 65 | uint32_t Matcher::genUniqId() 66 | { 67 | //Warn: if max_id is not (uint32_t)-1, remeber to fix mod max_id here. 68 | return this->current_id++; 69 | } 70 | 71 | double Matcher::calDistance(double lng1, double lat1, double lng2, double lat2) 72 | { 73 | double sq_distance, distance; 74 | 75 | sq_distance = (lng2-lng1)*(lng2-lng1) + (lat2-lat1)*(lat2-lat1); 76 | distance = sqrt(sq_distance); 77 | 78 | return distance; 79 | } 80 | 81 | /** 82 | * 83 | * @algorithm: 84 | * 1.if the heading diffrence is small and tht distance between the road and the current gps estimated position is 85 | * small then resemblance of the road is high 86 | * 2.if the previous resemblance of the road is high and the current resemblance is high then the travel likelihood 87 | * of the road is high 88 | * 3.if the previous maximum resemblance of all roads in the candidate road list is low and the current maximum 89 | * resemblance of all the roads in the list is low then the vehicle is off-road 90 | * 91 | * 4.when run 1/2 the seg , update candidates? 92 | * 93 | * @InfoNeededForMatcher: 94 | * on_road: true or false 95 | * candidate_segs:[vector] 96 | * has update_candidate: true or false 97 | * current_seg: seg_id, distance_ratio_from_begin 98 | * road seg: seg_stru, heading, average_distance, successor_seg 99 | * 100 | **/ 101 | 102 | vector Matcher::doMatch(struct position position, struct map_track map_track) 103 | { 104 | double lng, lat; 105 | double map_lng, map_lat; 106 | struct point map_point; 107 | vector seg_maps; 108 | vector map_points; 109 | 110 | lng = position.lng; 111 | lat = position.lat; 112 | map_lng = map_lat = 0.0; 113 | map_points.clear(); 114 | 115 | //first time map point to road, map it to the latest road 116 | double tmp = INFINITY; 117 | seg_maps = this->map_index->getGridSegs(lng, lat, this->query_distance); 118 | //update candidates 119 | for(vector::iterator iter = seg_maps.begin(); iter != seg_maps.end(); iter++) 120 | { 121 | if(!iter->on_seg) 122 | continue; 123 | if(!iter->on_seg && iter->min_distance > this->query_distance) 124 | continue; 125 | if((iter->on_seg && iter->distance < tmp) || (!iter->on_seg && iter->min_distance < tmp)) 126 | { 127 | map_lng = iter->map_lng; 128 | map_lat = iter->map_lat; 129 | if(iter->on_seg) 130 | tmp = iter->distance; 131 | else 132 | tmp = iter->min_distance; 133 | } 134 | } 135 | 136 | if(map_lng == 0 && map_lat == 0) 137 | return map_points; 138 | 139 | debug_msg("lng:%f\tlat:%f\tmap_lng:%f\tmap_lat:%f\tdistance:%f\n", lng, lat, map_lng, map_lat, tmp); 140 | 141 | map_point.lng = map_lng; 142 | map_point.lat = map_lat; 143 | map_points.push_back(map_point); 144 | 145 | return map_points; 146 | } 147 | 148 | vector Matcher::match(uint32_t id, struct position position) 149 | { 150 | vector map_points; 151 | struct map_track map_track; 152 | 153 | map_points.clear(); 154 | 155 | map_track = this->track_map[id]; 156 | 157 | map_points = this->doMatch(position, map_track); 158 | 159 | return map_points; 160 | } 161 | 162 | -------------------------------------------------------------------------------- /tools/gen_distance_table/gen_distance_table.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | #include 8 | 9 | class GenDistanceTable 10 | { 11 | public: 12 | GenDistanceTable() 13 | { 14 | } 15 | 16 | /** 17 | * 在一定的纬度内,固定纬度,计算一定经度间隔的的距离。 18 | * 19 | * @author:lifulong 20 | */ 21 | void genLngDistance(double start_lat, double end_lat, double lat_gap, string file_name = "") 22 | { 23 | int i; 24 | FILE *fp = NULL; 25 | double current_lat = start_lat, distance; 26 | double gaps_array[] = {0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1}; 27 | int gaps_array_len = sizeof(gaps_array) / sizeof(gaps_array[0]); 28 | 29 | if(start_lat > end_lat || lat_gap <= 0) 30 | return; 31 | 32 | if(file_name == "") 33 | fp = stdout; 34 | else { 35 | fp = fopen(file_name.c_str(), "w"); 36 | if(NULL == fp) 37 | { 38 | cout << "[Error]Open " + file_name + "Error.\n" << endl; 39 | return; 40 | } 41 | } 42 | 43 | fprintf(fp, "lat\t"); 44 | for(i = 0; i < gaps_array_len; i++) 45 | fprintf(fp, "%0.4f\t", gaps_array[i]); 46 | fprintf(fp, "\n"); 47 | 48 | while(current_lat <= end_lat) 49 | { 50 | fprintf(fp, "%0.4f\t", current_lat); 51 | for(i = 0; i < gaps_array_len; i++) 52 | { 53 | distance = this->getLongDistance(0, current_lat, gaps_array[i], current_lat); 54 | fprintf(fp, "%0.4f\t", distance); 55 | } 56 | current_lat += lat_gap; 57 | fprintf(fp, "\n"); 58 | } 59 | 60 | if(stdout != fp) 61 | fclose(fp); 62 | 63 | return; 64 | } 65 | 66 | /** 67 | * 固定经度,在某个纬度基数上,计算一定纬度间隔的距离。 68 | * 69 | * 70 | */ 71 | void genLatDistance(double lng, double lat, string file_name="") 72 | { 73 | int i; 74 | FILE *fp = NULL; 75 | double current_lat = lat, distance; 76 | double gaps_array[] = {0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1}; 77 | int gaps_array_len = sizeof(gaps_array) / sizeof(gaps_array[0]); 78 | 79 | if(file_name == "") 80 | fp = stdout; 81 | else { 82 | fp = fopen(file_name.c_str(), "w"); 83 | if(NULL == fp) 84 | { 85 | cout << "[Error]Open " + file_name + "Error.\n" << endl; 86 | return; 87 | } 88 | } 89 | 90 | fprintf(fp, "lat\t"); 91 | for(i = 0; i < gaps_array_len; i++) 92 | fprintf(fp, "%0.4f\t", gaps_array[i]); 93 | fprintf(fp, "\n"); 94 | 95 | fprintf(fp, "%0.4f\t", current_lat); 96 | for(i = 0; i < gaps_array_len; i++) 97 | { 98 | distance = this->getLongDistance(lng, current_lat, lng, current_lat+gaps_array[i]); 99 | fprintf(fp, "%0.4f\t", distance); 100 | } 101 | fprintf(fp, "\n"); 102 | 103 | if(stdout != fp) 104 | fclose(fp); 105 | 106 | return; 107 | } 108 | 109 | private: 110 | static const double DEF_PI = 3.14159265359; // PI 111 | static const double DEF_2PI = 6.28318530712; // 2*PI 112 | static const double DEF_PI180 = 0.01745329252; // PI/180.0 113 | static const double DEF_R = 6370693.5; // radius of earth 114 | 115 | double getShortDistance(double lon1, double lat1, double lon2, double lat2) 116 | { 117 | double ew1, ns1, ew2, ns2; 118 | double dx, dy, dew; 119 | double distance; 120 | // 角度转换为弧度 121 | ew1 = lon1 * DEF_PI180; 122 | ns1 = lat1 * DEF_PI180; 123 | ew2 = lon2 * DEF_PI180; 124 | ns2 = lat2 * DEF_PI180; 125 | // 经度差 126 | dew = ew1 - ew2; 127 | // 若跨东经和西经180 度,进行调整 128 | if (dew > DEF_PI) 129 | dew = DEF_2PI - dew; 130 | else if (dew < -DEF_PI) 131 | dew = DEF_2PI + dew; 132 | dx = DEF_R * cos(ns1) * dew; // 东西方向长度(在纬度圈上的投影长度) 133 | dy = DEF_R * (ns1 - ns2); // 南北方向长度(在经度圈上的投影长度) 134 | // 勾股定理求斜边长 135 | distance = sqrt(dx * dx + dy * dy); 136 | return distance; 137 | } 138 | 139 | double getLongDistance(double lon1, double lat1, double lon2, double lat2) 140 | { 141 | double ew1, ns1, ew2, ns2; 142 | double distance; 143 | // 角度转换为弧度 144 | ew1 = lon1 * DEF_PI180; 145 | ns1 = lat1 * DEF_PI180; 146 | ew2 = lon2 * DEF_PI180; 147 | ns2 = lat2 * DEF_PI180; 148 | // 求大圆劣弧与球心所夹的角(弧度) 149 | distance = sin(ns1) * sin(ns2) + cos(ns1) * cos(ns2) * cos(ew1 - ew2); 150 | // 调整到[-1..1]范围内,避免溢出 151 | if (distance > 1.0) 152 | distance = 1.0; 153 | else if (distance < -1.0) 154 | distance = -1.0; 155 | // 求大圆劣弧长度 156 | distance = DEF_R * acos(distance); 157 | return distance; 158 | } 159 | }; 160 | 161 | -------------------------------------------------------------------------------- /src/map-index/map_index.h: -------------------------------------------------------------------------------- 1 | /** 2 | * implement of build grid index of road network for map matching 3 | * 4 | * @date: 2014-12-21 5 | * @author: lifulong 6 | **/ 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | #include "error.h" 19 | #include "logger.h" 20 | #include "debug.h" 21 | 22 | 23 | #define BJ_START_LNG 115.25 24 | #define BJ_START_LAT 39.26 25 | #define BJ_END_LNG 117.4 26 | #define BJ_END_LAT 41.1 27 | 28 | #define LNG_GAP 0.002 29 | #define LAT_GAP 0.002 30 | 31 | #define START_LNG BJ_START_LNG 32 | #define START_LAT BJ_START_LAT 33 | #define END_LNG BJ_END_LNG 34 | #define END_LAT BJ_END_LAT 35 | 36 | 37 | /* 38 | #define GRID_BY_GAP 39 | #define GRID_BY_LEN 40 | #undef GRID_BY_LEN 41 | */ 42 | 43 | #define LINE_BUFFER_LEN 40960 44 | 45 | struct point { 46 | double lng; 47 | double lat; 48 | }; 49 | 50 | struct inode { 51 | int node_index; 52 | struct point point; 53 | }; 54 | 55 | struct iedge { 56 | int edge_index; 57 | int start_inode_index; 58 | int end_inode_index; 59 | }; 60 | 61 | struct igeo { 62 | int edge_index; 63 | vector points; 64 | }; 65 | 66 | struct seg { 67 | int seg_id; 68 | int edge_id; 69 | double start_lng; 70 | double start_lat; 71 | double end_lng; 72 | double end_lat; 73 | }; 74 | 75 | struct grid_index { 76 | int i, j; 77 | }; 78 | 79 | struct grid_node { 80 | double start_lng, end_lng; 81 | double start_lat, end_lat; 82 | double gap_lng, gap_lat; 83 | vector node_segs; 84 | }; 85 | 86 | struct seg_point_map { 87 | int seg_id; 88 | int edge_id; 89 | double start_lng; 90 | double start_lat; 91 | double end_lng; 92 | double end_lat; 93 | 94 | double lng; 95 | double lat; 96 | double map_lng; 97 | double map_lat; 98 | double distance; 99 | double min_distance; 100 | bool on_seg; 101 | }; 102 | 103 | 104 | class MapIndex { 105 | 106 | public: 107 | 108 | MapIndex(string nodes_file, string edges_file, string geos_file, string segs_file, 109 | string grid_info, string grid_file, string logfile=""); 110 | 111 | int getErrno(); 112 | string getErrMsg(); 113 | 114 | vector getGridSegs(double lng, double lat, double distance=0); 115 | 116 | seg_point_map mapGridSeg(double lng, double lat, seg seg); 117 | vector mapGridSegs(double lng, double lat, double distance, vector segs); 118 | 119 | private: 120 | static constexpr double DEF_PI = 3.14159265359; // PI 121 | static constexpr double DEF_2PI = 6.28318530712; // 2*PI 122 | static constexpr double DEF_PI180 = 0.01745329252; // PI/180.0 123 | static constexpr double DEF_R = 6370693.5; // radius of earth 124 | 125 | string init_mode; 126 | double map_start_lng, map_end_lng, map_start_lat, map_end_lat; 127 | double map_lat_gap, map_lng_gap; 128 | int map_lat_num, map_lng_num; 129 | //int grid_lat_len, grid_lng_len; 130 | int _errno; 131 | string errMsg; 132 | Logger *logger; 133 | vector inodes; 134 | vector iedges; 135 | vector igeos; 136 | vector segs; 137 | //FIXME: use map(index_stru, grid_node) instead 138 | struct grid_node **grid; 139 | 140 | 141 | void loadNodes(string nodes_file); 142 | void loadEdges(string edges_file); 143 | void loadGeos(string geos_file); 144 | void loadSegs(string segs_file); 145 | void setValue(string key, string value); 146 | void loadGridInfo(string grid_info); 147 | void dumpGridInfo(); 148 | void loadGridData(string grid_file); 149 | 150 | void initGrid(); 151 | 152 | void initMapIndex(); 153 | 154 | //gen segs 155 | void genSegs(string geos_file=""); 156 | void dumpSegs(string segs_file=""); 157 | 158 | //gen grid 159 | double round(double val, double mod, char type); 160 | void preprocessGridInfo(string type); 161 | 162 | void initGenGrid(); 163 | struct grid_index getGridIndexByPoint(double lng, double lat); 164 | void updateGrid(struct grid_index index, struct seg seg); 165 | void updateHorizontalGrids(double k, double start_lng, double start_lat, 166 | double end_lng, double end_lat, struct seg seg); 167 | void updateVerticalGrids(double k, double start_lng, double start_lat, 168 | double end_lng, double end_lat, struct seg seg); 169 | void updateHorizOrientGrids(double k, double start_lng, double start_lat, 170 | double end_lng, double end_lat, struct seg seg); 171 | void updateVertOrientGrids(double k, double start_lng, double start_lat, 172 | double end_lng, double end_lat, struct seg seg); 173 | void updateGrids(struct seg seg); 174 | void genGrid(string segs_file=""); 175 | void dumpGrid(string dump_file); 176 | 177 | //query grid 178 | double calLineDistance(double start_lng, double start_lat, double end_lng, double end_lat); 179 | double calShortDistance(double lon1, double lat1, double lon2, double lat2); 180 | double calLongDistance(double lon1, double lat1, double lon2, double lat2); 181 | bool onSeg(double lng, double lat, double start_lng, double start_lat, double end_lng, double end_lat); 182 | }; 183 | 184 | -------------------------------------------------------------------------------- /datasets/14096444_1.json: -------------------------------------------------------------------------------- 1 | [{"lat":"39.9317","lng":"116.491225","gps_type":"baidu","gps_time":1418128958000,"provider":"network","accuracy":58.411998748779,"status":1,"milli_timestamp":1418128973.881},{"lat":"39.9317","lng":"116.491225","gps_type":"baidu","gps_time":1418128958000,"provider":"network","accuracy":58.411998748779,"status":1,"milli_timestamp":1418129004.222},{"lat":"39.931626","lng":"116.491074","gps_type":"baidu","gps_time":1418129017000,"provider":"gps","accuracy":14,"status":1,"milli_timestamp":1418129017.599},{"lat":"39.931765","lng":"116.491179","gps_type":"baidu","gps_time":1418129047000,"provider":"gps","accuracy":13,"status":1,"milli_timestamp":1418129047.452},{"lat":"39.931767","lng":"116.491175","gps_type":"baidu","gps_time":1418129077000,"provider":"gps","accuracy":13,"status":1,"milli_timestamp":1418129077.468},{"lat":"39.931766","lng":"116.49117","gps_type":"baidu","gps_time":1418129107000,"provider":"gps","accuracy":11,"status":1,"milli_timestamp":1418129107.478},{"lat":"39.931713","lng":"116.49137","gps_type":"baidu","gps_time":1418129137000,"provider":"gps","accuracy":4,"status":1,"milli_timestamp":1418129137.482},{"lat":"39.931737","lng":"116.491361","gps_type":"baidu","gps_time":1418129167000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418129167.497},{"lat":"39.931774","lng":"116.491365","gps_type":"baidu","gps_time":1418129197000,"provider":"gps","accuracy":3,"status":1,"milli_timestamp":1418129197.55},{"lat":"39.931746","lng":"116.491359","gps_type":"baidu","gps_time":1418129227000,"provider":"gps","accuracy":9,"status":1,"milli_timestamp":1418129227.596},{"lat":"39.931744","lng":"116.491357","gps_type":"baidu","gps_time":1418129257000,"provider":"gps","accuracy":114,"status":1,"milli_timestamp":1418129257.603},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129287000,"provider":"gps","accuracy":162,"status":1,"milli_timestamp":1418129287.605},{"lat":"39.9317","lng":"116.491225","gps_type":"baidu","gps_time":1418128958000,"provider":"network","accuracy":58.411998748779,"status":1,"milli_timestamp":1418129318.126},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129347000,"provider":"gps","accuracy":72,"status":1,"milli_timestamp":1418129347.592},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129377000,"provider":"gps","accuracy":226,"status":1,"milli_timestamp":1418129377.613},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129407000,"provider":"gps","accuracy":28,"status":1,"milli_timestamp":1418129407.571},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129437000,"provider":"gps","accuracy":27,"status":1,"milli_timestamp":1418129437.655},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129467000,"provider":"gps","accuracy":36,"status":1,"milli_timestamp":1418129467.666},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129497000,"provider":"gps","accuracy":22,"status":1,"milli_timestamp":1418129497.688},{"lat":"39.9317","lng":"116.491225","gps_type":"baidu","gps_time":1418128958000,"provider":"network","accuracy":58.411998748779,"status":1,"milli_timestamp":1418129528.235},{"lat":"39.9317","lng":"116.491225","gps_type":"baidu","gps_time":1418128958000,"provider":"network","accuracy":58.411998748779,"status":1,"milli_timestamp":1418129588.969},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129617000,"provider":"gps","accuracy":151,"status":1,"milli_timestamp":1418129617.673},{"lat":"39.9317","lng":"116.491225","gps_type":"baidu","gps_time":1418128958000,"provider":"network","accuracy":58.411998748779,"status":1,"milli_timestamp":1418129648.274},{"lat":"39.9317","lng":"116.491225","gps_type":"baidu","gps_time":1418128958000,"provider":"network","accuracy":58.411998748779,"status":1,"milli_timestamp":1418129708.361},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129767000,"provider":"gps","accuracy":249,"status":1,"milli_timestamp":1418129767.761},{"lat":"39.9317","lng":"116.491225","gps_type":"baidu","gps_time":1418128958000,"provider":"network","accuracy":58.411998748779,"status":1,"milli_timestamp":1418129798.283},{"lat":"39.931745","lng":"116.491358","gps_type":"baidu","gps_time":1418129827000,"provider":"gps","accuracy":216,"status":1,"milli_timestamp":1418129827.739},{"lat":"39.931746","lng":"116.491359","gps_type":"baidu","gps_time":1418129857000,"provider":"gps","accuracy":245,"status":1,"milli_timestamp":1418129857.759},{"lat":"39.931754","lng":"116.491236","gps_type":"baidu","gps_time":1418129884000,"provider":"network","accuracy":56.517265319824,"status":1,"milli_timestamp":1418129884.096},{"lat":"39.93173","lng":"116.491224","gps_type":"baidu","gps_time":1418129889000,"provider":"network","accuracy":56.054672241211,"status":1,"milli_timestamp":1418129888.536},{"lat":"39.93173","lng":"116.491224","gps_type":"baidu","gps_time":1418129889000,"provider":"network","accuracy":56.054672241211,"status":1,"milli_timestamp":1418129918.648},{"lat":"39.931783","lng":"116.491251","gps_type":"baidu","gps_time":1418129922000,"provider":"gps","accuracy":20,"status":1,"milli_timestamp":1418129922.95},{"lat":"39.931763","lng":"116.491236","gps_type":"baidu","gps_time":1418129927000,"provider":"gps","accuracy":15,"status":1,"milli_timestamp":1418129927.944},{"lat":"39.931726","lng":"116.491282","gps_type":"baidu","gps_time":1418129933000,"provider":"network","accuracy":59.080341339111,"status":1,"milli_timestamp":1418129933.344}] -------------------------------------------------------------------------------- /src/map-index/query_grid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "common.h" 8 | #include "map_index.h" 9 | 10 | #define READ_BUFFER_LEN 40960 11 | 12 | 13 | double MapIndex::calLineDistance(double start_lng, double start_lat, double end_lng, double end_lat) 14 | { 15 | double distance, sq_distance; 16 | 17 | sq_distance = (end_lng - start_lng)*(end_lng - start_lng) + (end_lat - start_lat)*(end_lat - start_lat); 18 | distance = sqrt(sq_distance); 19 | 20 | return distance; 21 | } 22 | 23 | double MapIndex::calShortDistance(double lon1, double lat1, double lon2, double lat2) 24 | { 25 | double ew1, ns1, ew2, ns2; 26 | double dx, dy, dew; 27 | double distance; 28 | // 角度转换为弧度 29 | ew1 = lon1 * DEF_PI180; 30 | ns1 = lat1 * DEF_PI180; 31 | ew2 = lon2 * DEF_PI180; 32 | ns2 = lat2 * DEF_PI180; 33 | // 经度差 34 | dew = ew1 - ew2; 35 | // 若跨东经和西经180 度,进行调整 36 | if (dew > DEF_PI) 37 | dew = DEF_2PI - dew; 38 | else if (dew < -DEF_PI) 39 | dew = DEF_2PI + dew; 40 | dx = DEF_R * cos(ns1) * dew; // 东西方向长度(在纬度圈上的投影长度) 41 | dy = DEF_R * (ns1 - ns2); // 南北方向长度(在经度圈上的投影长度) 42 | // 勾股定理求斜边长 43 | distance = sqrt(dx * dx + dy * dy); 44 | return distance; 45 | } 46 | 47 | double MapIndex::calLongDistance(double lon1, double lat1, double lon2, double lat2) 48 | { 49 | double ew1, ns1, ew2, ns2; 50 | double distance; 51 | // 角度转换为弧度 52 | ew1 = lon1 * DEF_PI180; 53 | ns1 = lat1 * DEF_PI180; 54 | ew2 = lon2 * DEF_PI180; 55 | ns2 = lat2 * DEF_PI180; 56 | // 求大圆劣弧与球心所夹的角(弧度) 57 | distance = sin(ns1) * sin(ns2) + cos(ns1) * cos(ns2) * cos(ew1 - ew2); 58 | // 调整到[-1..1]范围内,避免溢出 59 | if (distance > 1.0) 60 | distance = 1.0; 61 | else if (distance < -1.0) 62 | distance = -1.0; 63 | // 求大圆劣弧长度 64 | distance = DEF_R * acos(distance); 65 | return distance; 66 | } 67 | 68 | bool MapIndex::onSeg(double lng, double lat, double start_lng, double start_lat, double end_lng, double end_lat) 69 | { 70 | if(((start_lng - lng)*(end_lng - lng) <= 0) && ((start_lat - lat)*(end_lat - lat) <= 0)) 71 | return true; 72 | return false; 73 | } 74 | 75 | /** 76 | * + P3 77 | * . 78 | * . 79 | * . 80 | * . 81 | * . )theta 82 | * P1 +----------+-----------+ P2 83 | * P0 84 | * 85 | * (P3-P1)(P2-P1) = |P3-P1|*|P2-P1|*cos(theta) 86 | * ms_distance = distance(P0,P1) = |P3-P1|*cos(theta) 87 | * es_distance = distance(P2,P1) = |P2-P1| 88 | * distance = distance(P3,P0) = |P3-P1|*sin(theta) 89 | * lng(P0) = (ms_distance*(lng(P2)-lng(P1))*sign_flag + lng(P1)*|P2-P1|) / es_distance 90 | * lat(P0) = (ms_distance*(lat(P2)-lat(P1))*sign_flag + lat(P1)*|P2-P1|) / es_distance 91 | */ 92 | seg_point_map MapIndex::mapGridSeg(double lng, double lat, seg seg) 93 | { 94 | bool on_seg; 95 | int sign_flag = 1; 96 | double cos_theta; 97 | //double theta, cos_theta, sin_theta; 98 | double map_lng, map_lat; 99 | double start_lng, start_lat, end_lng, end_lat; 100 | //es_distance:end to start ps_distance: point to start 101 | double es_distance, ps_distance, ms_distance; 102 | double ps_short_distance, pe_short_distance, short_distance, min_short_distance; 103 | seg_point_map map; 104 | 105 | start_lng = seg.start_lng; 106 | start_lat = seg.start_lat; 107 | end_lng = seg.end_lng; 108 | end_lat = seg.end_lat; 109 | 110 | //FIXME:point is start_point or end_point 111 | es_distance = this->calLineDistance(start_lng, start_lat, end_lng, end_lat); 112 | ps_distance = this->calLineDistance(start_lng, start_lat, lng, lat); 113 | if(ps_distance == 0) 114 | cos_theta = 1; 115 | else 116 | cos_theta = ((end_lng-start_lng)*(lng-start_lng)+(end_lat-start_lat)*(lat-start_lat))/(es_distance*ps_distance); 117 | sign_flag = (cos_theta>=0) ? 1 : -1; 118 | ms_distance = fabs(cos_theta) * ps_distance; 119 | //distance = ps_distance * fabs(sin(acos(cos_theta))); 120 | map_lng = (ms_distance*(end_lng - start_lng)*sign_flag + es_distance*start_lng)/es_distance; 121 | map_lat = (ms_distance*(end_lat - start_lat)*sign_flag + es_distance*start_lat)/es_distance; 122 | 123 | ps_short_distance = this->calShortDistance(start_lng, start_lat, lng, lat); 124 | pe_short_distance = this->calShortDistance(end_lng, end_lat, lng, lat); 125 | short_distance = this->calShortDistance(map_lng, map_lat, lng, lat); 126 | min_short_distance = ps_short_distance > pe_short_distance ? pe_short_distance : ps_short_distance; 127 | on_seg = this->onSeg(map_lng, map_lat, start_lng, start_lat, end_lng, end_lat); 128 | 129 | map.seg_id = seg.seg_id; 130 | map.edge_id = seg.edge_id; 131 | map.start_lng = seg.start_lng; 132 | map.start_lat = seg.start_lat; 133 | map.end_lng = seg.end_lng; 134 | map.end_lat = seg.end_lat; 135 | 136 | map.lng = lng; 137 | map.lat = lat; 138 | map.map_lng = map_lng; 139 | map.map_lat = map_lat; 140 | map.distance = short_distance; 141 | map.min_distance = min_short_distance; 142 | map.on_seg = on_seg; 143 | 144 | return map; 145 | } 146 | 147 | vector MapIndex::mapGridSegs(double lng, double lat, double distance, vector segs) 148 | { 149 | struct seg_point_map map; 150 | vector seg_point_maps; 151 | 152 | seg_point_maps.clear(); 153 | 154 | for(vector::iterator iter = segs.begin(); iter != segs.end(); iter++) 155 | { 156 | map = this->mapGridSeg(lng, lat, *iter); 157 | if(0 != distance) { 158 | 159 | if((map.on_seg == true && map.distance < distance) || (map.on_seg == false && map.min_distance < distance)) 160 | seg_point_maps.push_back(map); 161 | } else { 162 | 163 | seg_point_maps.push_back(map); 164 | } 165 | } 166 | 167 | return seg_point_maps; 168 | } 169 | 170 | vector MapIndex::getGridSegs(double lng, double lat, double distance) 171 | { 172 | int i, j, index_i, index_j, tmp_i, tmp_j; 173 | struct grid_index index; 174 | vector segs; 175 | vector seg_point_maps; 176 | 177 | segs.clear(); 178 | seg_point_maps.clear(); 179 | 180 | index = this->getGridIndexByPoint(lng, lat); 181 | 182 | if(index.i == -1 || index.j == -1) { 183 | debug_msg("get grid index by point error, %d, %d.\n", index.i, index.j); 184 | return seg_point_maps; 185 | } 186 | index_i = index.i - 1; 187 | index_j = index.j - 1; 188 | 189 | for(i = 0; i < 3; i++) 190 | for(j = 0; j < 3; j++) 191 | { 192 | tmp_i = index_i + i; 193 | tmp_j = index_j + j; 194 | 195 | if(tmp_i < 0 || tmp_i >= this->map_lng_num) { 196 | continue; 197 | } 198 | 199 | if(tmp_j < 0 || tmp_j >= this->map_lat_num) { 200 | continue; 201 | } 202 | 203 | for(vector::iterator iter = this->grid[tmp_i][tmp_j].node_segs.begin(); 204 | iter != this->grid[tmp_i][tmp_j].node_segs.end(); iter++) { 205 | 206 | vector::iterator iter2; 207 | for(iter2 = segs.begin(); iter2 != segs.end(); iter2++) { 208 | if(iter->seg_id == iter2->seg_id) 209 | break; 210 | } 211 | 212 | if(iter2 == segs.end()) 213 | segs.push_back(*iter); 214 | } 215 | } 216 | 217 | return this->mapGridSegs(lng, lat, distance, segs); 218 | } 219 | 220 | 221 | -------------------------------------------------------------------------------- /tools/query_grid/autom4te.cache/requests: -------------------------------------------------------------------------------- 1 | # This file was generated by Autom4te Thu Apr 10 10:06:43 UTC 2014. 2 | # It contains the lists of macros which have been traced. 3 | # It can be safely removed. 4 | 5 | @request = ( 6 | bless( [ 7 | '0', 8 | 1, 9 | [ 10 | '/usr/share/autoconf' 11 | ], 12 | [ 13 | '/usr/share/autoconf/autoconf/autoconf.m4f', 14 | '-', 15 | '/usr/share/aclocal-1.14/internal/ac-config-macro-dirs.m4', 16 | '/usr/share/aclocal-1.14/amversion.m4', 17 | '/usr/share/aclocal-1.14/auxdir.m4', 18 | '/usr/share/aclocal-1.14/cond.m4', 19 | '/usr/share/aclocal-1.14/depend.m4', 20 | '/usr/share/aclocal-1.14/depout.m4', 21 | '/usr/share/aclocal-1.14/init.m4', 22 | '/usr/share/aclocal-1.14/install-sh.m4', 23 | '/usr/share/aclocal-1.14/lead-dot.m4', 24 | '/usr/share/aclocal-1.14/make.m4', 25 | '/usr/share/aclocal-1.14/missing.m4', 26 | '/usr/share/aclocal-1.14/options.m4', 27 | '/usr/share/aclocal-1.14/prog-cc-c-o.m4', 28 | '/usr/share/aclocal-1.14/runlog.m4', 29 | '/usr/share/aclocal-1.14/sanity.m4', 30 | '/usr/share/aclocal-1.14/silent.m4', 31 | '/usr/share/aclocal-1.14/strip.m4', 32 | '/usr/share/aclocal-1.14/substnot.m4', 33 | '/usr/share/aclocal-1.14/tar.m4', 34 | 'configure.ac' 35 | ], 36 | { 37 | 'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1, 38 | 'AC_CONFIG_MACRO_DIR_TRACE' => 1, 39 | 'AM_AUTOMAKE_VERSION' => 1, 40 | '_AM_SET_OPTIONS' => 1, 41 | '_AM_PROG_TAR' => 1, 42 | 'AM_SET_DEPDIR' => 1, 43 | 'AU_DEFUN' => 1, 44 | 'AM_PROG_INSTALL_SH' => 1, 45 | 'm4_pattern_forbid' => 1, 46 | 'AM_PROG_INSTALL_STRIP' => 1, 47 | '_m4_warn' => 1, 48 | 'AM_PROG_CC_C_O' => 1, 49 | '_AM_SUBST_NOTMAKE' => 1, 50 | '_AM_IF_OPTION' => 1, 51 | '_AM_DEPENDENCIES' => 1, 52 | 'AM_SANITY_CHECK' => 1, 53 | 'm4_include' => 1, 54 | 'include' => 1, 55 | '_AC_AM_CONFIG_HEADER_HOOK' => 1, 56 | 'AM_MISSING_HAS_RUN' => 1, 57 | '_AM_PROG_CC_C_O' => 1, 58 | 'AM_OUTPUT_DEPENDENCY_COMMANDS' => 1, 59 | 'AM_RUN_LOG' => 1, 60 | 'm4_pattern_allow' => 1, 61 | 'AM_SILENT_RULES' => 1, 62 | 'AM_MISSING_PROG' => 1, 63 | 'AM_SET_LEADING_DOT' => 1, 64 | '_AM_MANGLE_OPTION' => 1, 65 | '_AM_CONFIG_MACRO_DIRS' => 1, 66 | 'AC_DEFUN' => 1, 67 | 'AM_DEP_TRACK' => 1, 68 | 'AC_CONFIG_MACRO_DIR' => 1, 69 | '_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1, 70 | 'AM_SUBST_NOTMAKE' => 1, 71 | 'AM_MAKE_INCLUDE' => 1, 72 | 'AM_INIT_AUTOMAKE' => 1, 73 | 'AM_CONDITIONAL' => 1, 74 | 'AM_AUX_DIR_EXPAND' => 1, 75 | '_AM_SET_OPTION' => 1, 76 | 'AC_DEFUN_ONCE' => 1, 77 | '_AM_AUTOCONF_VERSION' => 1 78 | } 79 | ], 'Autom4te::Request' ), 80 | bless( [ 81 | '1', 82 | 1, 83 | [ 84 | '/usr/share/autoconf' 85 | ], 86 | [ 87 | '/usr/share/autoconf/autoconf/autoconf.m4f', 88 | 'aclocal.m4', 89 | 'configure.ac' 90 | ], 91 | { 92 | 'AM_SILENT_RULES' => 1, 93 | 'm4_pattern_allow' => 1, 94 | 'AC_CONFIG_HEADERS' => 1, 95 | '_AM_MAKEFILE_INCLUDE' => 1, 96 | 'AC_PROG_LIBTOOL' => 1, 97 | 'AM_POT_TOOLS' => 1, 98 | 'AC_LIBSOURCE' => 1, 99 | 'AM_NLS' => 1, 100 | 'AM_PROG_MKDIR_P' => 1, 101 | 'AC_DEFINE_TRACE_LITERAL' => 1, 102 | 'sinclude' => 1, 103 | 'AM_PROG_MOC' => 1, 104 | 'AC_FC_PP_SRCEXT' => 1, 105 | 'AC_SUBST' => 1, 106 | 'AC_CONFIG_LIBOBJ_DIR' => 1, 107 | '_AM_COND_ELSE' => 1, 108 | 'AM_CONDITIONAL' => 1, 109 | 'AM_GNU_GETTEXT_INTL_SUBDIR' => 1, 110 | 'AC_FC_SRCEXT' => 1, 111 | 'AC_CONFIG_LINKS' => 1, 112 | 'AM_INIT_AUTOMAKE' => 1, 113 | 'AC_FC_PP_DEFINE' => 1, 114 | 'LT_INIT' => 1, 115 | 'AM_MAKEFILE_INCLUDE' => 1, 116 | 'AC_CONFIG_FILES' => 1, 117 | 'AC_CANONICAL_BUILD' => 1, 118 | 'AC_SUBST_TRACE' => 1, 119 | 'AM_PATH_GUILE' => 1, 120 | 'AC_CANONICAL_SYSTEM' => 1, 121 | 'AH_OUTPUT' => 1, 122 | 'AM_PROG_FC_C_O' => 1, 123 | 'm4_sinclude' => 1, 124 | 'AC_REQUIRE_AUX_FILE' => 1, 125 | 'LT_CONFIG_LTDL_DIR' => 1, 126 | 'AM_EXTRA_RECURSIVE_TARGETS' => 1, 127 | '_LT_AC_TAGCONFIG' => 1, 128 | 'AM_AUTOMAKE_VERSION' => 1, 129 | 'AC_CANONICAL_TARGET' => 1, 130 | 'AM_MAINTAINER_MODE' => 1, 131 | '_AM_COND_ENDIF' => 1, 132 | 'AC_CANONICAL_HOST' => 1, 133 | 'AC_FC_FREEFORM' => 1, 134 | 'm4_include' => 1, 135 | 'AM_XGETTEXT_OPTION' => 1, 136 | 'LT_SUPPORTED_TAG' => 1, 137 | 'AC_CONFIG_AUX_DIR' => 1, 138 | 'AM_GNU_GETTEXT' => 1, 139 | 'AC_INIT' => 1, 140 | 'AM_ENABLE_MULTILIB' => 1, 141 | 'AC_CONFIG_SUBDIRS' => 1, 142 | 'include' => 1, 143 | 'AM_PROG_F77_C_O' => 1, 144 | '_m4_warn' => 1, 145 | 'm4_pattern_forbid' => 1, 146 | '_AM_COND_IF' => 1, 147 | 'AM_PROG_CXX_C_O' => 1, 148 | '_AM_SUBST_NOTMAKE' => 1, 149 | 'AM_PROG_CC_C_O' => 1, 150 | 'AM_PROG_AR' => 1 151 | } 152 | ], 'Autom4te::Request' ) 153 | ); 154 | 155 | -------------------------------------------------------------------------------- /tools/query_grid/missing: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Common wrapper for a few potentially missing GNU programs. 3 | 4 | scriptversion=2013-10-28.13; # UTC 5 | 6 | # Copyright (C) 1996-2013 Free Software Foundation, Inc. 7 | # Originally written by Fran,cois Pinard , 1996. 8 | 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | if test $# -eq 0; then 28 | echo 1>&2 "Try '$0 --help' for more information" 29 | exit 1 30 | fi 31 | 32 | case $1 in 33 | 34 | --is-lightweight) 35 | # Used by our autoconf macros to check whether the available missing 36 | # script is modern enough. 37 | exit 0 38 | ;; 39 | 40 | --run) 41 | # Back-compat with the calling convention used by older automake. 42 | shift 43 | ;; 44 | 45 | -h|--h|--he|--hel|--help) 46 | echo "\ 47 | $0 [OPTION]... PROGRAM [ARGUMENT]... 48 | 49 | Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due 50 | to PROGRAM being missing or too old. 51 | 52 | Options: 53 | -h, --help display this help and exit 54 | -v, --version output version information and exit 55 | 56 | Supported PROGRAM values: 57 | aclocal autoconf autoheader autom4te automake makeinfo 58 | bison yacc flex lex help2man 59 | 60 | Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and 61 | 'g' are ignored when checking the name. 62 | 63 | Send bug reports to ." 64 | exit $? 65 | ;; 66 | 67 | -v|--v|--ve|--ver|--vers|--versi|--versio|--version) 68 | echo "missing $scriptversion (GNU Automake)" 69 | exit $? 70 | ;; 71 | 72 | -*) 73 | echo 1>&2 "$0: unknown '$1' option" 74 | echo 1>&2 "Try '$0 --help' for more information" 75 | exit 1 76 | ;; 77 | 78 | esac 79 | 80 | # Run the given program, remember its exit status. 81 | "$@"; st=$? 82 | 83 | # If it succeeded, we are done. 84 | test $st -eq 0 && exit 0 85 | 86 | # Also exit now if we it failed (or wasn't found), and '--version' was 87 | # passed; such an option is passed most likely to detect whether the 88 | # program is present and works. 89 | case $2 in --version|--help) exit $st;; esac 90 | 91 | # Exit code 63 means version mismatch. This often happens when the user 92 | # tries to use an ancient version of a tool on a file that requires a 93 | # minimum version. 94 | if test $st -eq 63; then 95 | msg="probably too old" 96 | elif test $st -eq 127; then 97 | # Program was missing. 98 | msg="missing on your system" 99 | else 100 | # Program was found and executed, but failed. Give up. 101 | exit $st 102 | fi 103 | 104 | perl_URL=http://www.perl.org/ 105 | flex_URL=http://flex.sourceforge.net/ 106 | gnu_software_URL=http://www.gnu.org/software 107 | 108 | program_details () 109 | { 110 | case $1 in 111 | aclocal|automake) 112 | echo "The '$1' program is part of the GNU Automake package:" 113 | echo "<$gnu_software_URL/automake>" 114 | echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" 115 | echo "<$gnu_software_URL/autoconf>" 116 | echo "<$gnu_software_URL/m4/>" 117 | echo "<$perl_URL>" 118 | ;; 119 | autoconf|autom4te|autoheader) 120 | echo "The '$1' program is part of the GNU Autoconf package:" 121 | echo "<$gnu_software_URL/autoconf/>" 122 | echo "It also requires GNU m4 and Perl in order to run:" 123 | echo "<$gnu_software_URL/m4/>" 124 | echo "<$perl_URL>" 125 | ;; 126 | esac 127 | } 128 | 129 | give_advice () 130 | { 131 | # Normalize program name to check for. 132 | normalized_program=`echo "$1" | sed ' 133 | s/^gnu-//; t 134 | s/^gnu//; t 135 | s/^g//; t'` 136 | 137 | printf '%s\n' "'$1' is $msg." 138 | 139 | configure_deps="'configure.ac' or m4 files included by 'configure.ac'" 140 | case $normalized_program in 141 | autoconf*) 142 | echo "You should only need it if you modified 'configure.ac'," 143 | echo "or m4 files included by it." 144 | program_details 'autoconf' 145 | ;; 146 | autoheader*) 147 | echo "You should only need it if you modified 'acconfig.h' or" 148 | echo "$configure_deps." 149 | program_details 'autoheader' 150 | ;; 151 | automake*) 152 | echo "You should only need it if you modified 'Makefile.am' or" 153 | echo "$configure_deps." 154 | program_details 'automake' 155 | ;; 156 | aclocal*) 157 | echo "You should only need it if you modified 'acinclude.m4' or" 158 | echo "$configure_deps." 159 | program_details 'aclocal' 160 | ;; 161 | autom4te*) 162 | echo "You might have modified some maintainer files that require" 163 | echo "the 'autom4te' program to be rebuilt." 164 | program_details 'autom4te' 165 | ;; 166 | bison*|yacc*) 167 | echo "You should only need it if you modified a '.y' file." 168 | echo "You may want to install the GNU Bison package:" 169 | echo "<$gnu_software_URL/bison/>" 170 | ;; 171 | lex*|flex*) 172 | echo "You should only need it if you modified a '.l' file." 173 | echo "You may want to install the Fast Lexical Analyzer package:" 174 | echo "<$flex_URL>" 175 | ;; 176 | help2man*) 177 | echo "You should only need it if you modified a dependency" \ 178 | "of a man page." 179 | echo "You may want to install the GNU Help2man package:" 180 | echo "<$gnu_software_URL/help2man/>" 181 | ;; 182 | makeinfo*) 183 | echo "You should only need it if you modified a '.texi' file, or" 184 | echo "any other file indirectly affecting the aspect of the manual." 185 | echo "You might want to install the Texinfo package:" 186 | echo "<$gnu_software_URL/texinfo/>" 187 | echo "The spurious makeinfo call might also be the consequence of" 188 | echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" 189 | echo "want to install GNU make:" 190 | echo "<$gnu_software_URL/make/>" 191 | ;; 192 | *) 193 | echo "You might have modified some files without having the proper" 194 | echo "tools for further handling them. Check the 'README' file, it" 195 | echo "often tells you about the needed prerequisites for installing" 196 | echo "this package. You may also peek at any GNU archive site, in" 197 | echo "case some other package contains this missing '$1' program." 198 | ;; 199 | esac 200 | } 201 | 202 | give_advice "$1" | sed -e '1s/^/WARNING: /' \ 203 | -e '2,$s/^/ /' >&2 204 | 205 | # Propagate the correct exit status (expected to be 127 for a program 206 | # not found, 63 for a program that failed due to version mismatch). 207 | exit $st 208 | 209 | # Local variables: 210 | # eval: (add-hook 'write-file-hooks 'time-stamp) 211 | # time-stamp-start: "scriptversion=" 212 | # time-stamp-format: "%:y-%02m-%02d.%02H" 213 | # time-stamp-time-zone: "UTC" 214 | # time-stamp-end: "; # UTC" 215 | # End: 216 | -------------------------------------------------------------------------------- /src/iter-map-matching/iter_matcher.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "common.h" 5 | #include "iter_matcher.h" 6 | 7 | /* 8 | struct position { 9 | int timestamp; 10 | int gps_time; 11 | double lng; 12 | double lat; 13 | double accuracy; 14 | //string gps_type; 15 | }; 16 | 17 | struct map_point { 18 | int seg_id; 19 | int edge_id; 20 | double lng; 21 | double lat; 22 | double dis_deviation; //deviation 23 | double heading_deviation; //deviation 24 | }; 25 | 26 | struct trajectory { 27 | int uniq_id; 28 | vector positions; 29 | }; 30 | 31 | struct map_track { 32 | int uniq_id; 33 | double curr_lng; 34 | double curr_lat; 35 | double curr_dis_deviation; 36 | double curr_heading_deviation; 37 | double dis_deviation; 38 | double heading_deviation; 39 | vector points; 40 | }; 41 | */ 42 | 43 | 44 | /* 45 | uint32_t current_id; 46 | uint32_t max_id; //assign it with (uint32_t)-1 47 | map track_hash; 48 | */ 49 | 50 | 51 | Matcher::Matcher() 52 | { 53 | this->initMatcher(); 54 | } 55 | 56 | int Matcher::initMatcher() 57 | { 58 | this->max_id = (uint32_t)-1; 59 | this->current_id = 0; 60 | 61 | return 0; 62 | } 63 | 64 | 65 | uint32_t Matcher::genUniqId() 66 | { 67 | //Warn: if max_id is not (uint32_t)-1, remeber to fix mod max_id here. 68 | return this->current_id++; 69 | } 70 | 71 | double Matcher::calDistance(double lng1, double lat1, double lng2, double lat2) 72 | { 73 | double sq_distance, distance; 74 | 75 | sq_distance = (lng2-lng1)*(lng2-lng1) + (lat2-lat1)*(lat2-lat1); 76 | distance = sqrt(sq_distance); 77 | 78 | return distance; 79 | } 80 | 81 | /** 82 | * + P2 83 | * . 84 | * . 85 | * . 86 | * . 87 | * . )theta 88 | * P1 +----------+ P3 89 | * 90 | * 91 | * (P2-P1(P3-P1) = |P2-P1|*|P3-P1|*cos(theta) 92 | */ 93 | 94 | double Matcher::calHeading(double lng1, double lat1, double lng2, double lat2) 95 | { 96 | double theta; 97 | double cos_theta; 98 | double fake_lng, fake_lat; 99 | double distance1, distance2; 100 | 101 | if(isEqualDouble(lng1, lng2)) 102 | return 0.0; 103 | 104 | if(isEqualDouble(lng1, lng2)) { 105 | 106 | if(lat2 > lat1) 107 | theta = DEF_PI/2; 108 | else 109 | theta = -DEF_PI/2; 110 | return theta; 111 | } 112 | 113 | fake_lng = lng1 + fabs(lng2 - lng1); 114 | fake_lat = lat1; 115 | 116 | distance1 = this->calDistance(lng1, lat1, lng2, lat2); 117 | distance2 = this->calDistance(lng1, lat1, fake_lng, fake_lat); 118 | 119 | //FIXME: check if distance1 or distance2 equal zero 120 | if(isEqualDouble(distance1, 0) || isEqualDouble(distance2, 0)) { 121 | debug_msg("dis1:%f\tdis2:%f\n", distance1, distance2); 122 | return 0.0; 123 | } 124 | cos_theta = ((lng2-lng1)*(fake_lng-lng1)+(lat2-lat1)*(fake_lat-lat1)) / (distance1*distance2); 125 | 126 | theta = acos(cos_theta); 127 | if(lat2 < lat1) 128 | theta = DEF_2PI - theta; 129 | //debug_msg("%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", lng2-lng1, fake_lng-lng1, lat2-lat1, fake_lat-lat1, distance1, distance2, cos_theta, theta); 130 | 131 | return theta; 132 | } 133 | 134 | /** 135 | * 136 | * ^ 137 | * | 138 | * 1 |\ 139 | * | \ 140 | * 0.8 |_ \ 141 | * | |\ 142 | * | | \ 143 | * | | \ 144 | * | | \ 145 | * --------------------> degrees 146 | * 0 | 18* 90* 147 | * 148 | * @seg_heading: degree as the parameter 149 | * @heading: degree as the parameter 150 | * 151 | **/ 152 | 153 | double Matcher::headingResemblance(double seg_heading, double heading) 154 | { 155 | double heading_diff; 156 | double resemblance; 157 | 158 | heading_diff = fabs(heading - seg_heading); 159 | 160 | resemblance = (90.0 - heading_diff) / 90.0; 161 | 162 | return resemblance; 163 | } 164 | 165 | /** 166 | * 167 | * ^ 168 | * | 169 | * 1 |\ 170 | * | \ 171 | * 0.7 |_ \ 172 | * | |\ 173 | * | | \ 174 | * | | \ 175 | * | | \ 176 | * --------------------> distance 177 | * 0 | 15m 50m 178 | * 179 | **/ 180 | 181 | double Matcher::distanceResemblance(double average_distance, double distance) 182 | { 183 | double resemblance; 184 | 185 | resemblance = (50 - distance) / 50.0; 186 | 187 | return resemblance; 188 | } 189 | 190 | /** 191 | * 192 | * @algorithm: 193 | * 1.if the heading diffrence is small and tht distance between the road and the current gps estimated position is 194 | * small then resemblance of the road is high 195 | * 2.if the previous resemblance of the road is high and the current resemblance is high then the travel likelihood 196 | * of the road is high 197 | * 3.if the previous maximum resemblance of all roads in the candidate road list is low and the current maximum 198 | * resemblance of all the roads in the list is low then the vehicle is off-road 199 | * 200 | * 4.when run 1/2 the seg , update candidates? 201 | * 202 | * @InfoNeededForMatcher: 203 | * on_road: true or false 204 | * candidate_segs:[vector] 205 | * has update_candidate: true or false 206 | * current_seg: seg_id, distance_ratio_from_begin 207 | * road seg: seg_stru, heading, average_distance, successor_seg 208 | * 209 | **/ 210 | 211 | vector Matcher::doMatch(struct position position, struct map_track map_track) 212 | { 213 | double last_lng, last_lat, lng, lat; 214 | double heading, seg_heading; 215 | double distance; 216 | double heading_resemblance, distance_resemblance; 217 | double max_resemblance; 218 | double map_lng, map_lat; 219 | struct point map_point; 220 | struct seg_point_map seg_map; 221 | struct seg_candidate candidate; 222 | vector seg_maps; 223 | vector candidates; 224 | vector map_points; 225 | 226 | last_lng = map_track.last_lng; 227 | last_lat = map_track.last_lat; 228 | lng = position.lng; 229 | lat = position.lat; 230 | max_resemblance = 0; 231 | map_lng = map_lat = 0.0; 232 | map_points.clear(); 233 | candidates.clear(); 234 | candidates = map_track.candidates; 235 | 236 | //first time map point to road, map it to the latest road 237 | if(0 == candidates.size()) 238 | { 239 | double tmp = INFINITY; 240 | seg_maps = this->map_index->getGridSegs(lng, lat, this->query_distance); 241 | //update candidates 242 | for(vector::iterator iter = seg_maps.begin(); iter != seg_maps.end(); iter++) 243 | { 244 | if(!iter->on_seg && iter->min_distance > this->query_distance) 245 | continue; 246 | seg_heading = this->calHeading(iter->start_lng, iter->start_lat, iter->end_lng, iter->end_lat); 247 | candidate.seg = *iter; 248 | candidate.seg_heading = seg_heading; 249 | candidate.dis_deviation = 0; 250 | candidate.heading_deviation = 0; 251 | candidate.map_point_num = 0; 252 | candidate.orientation = 0; 253 | candidates.push_back(candidate); 254 | if((iter->on_seg && iter->distance < tmp) || (!iter->on_seg && iter->min_distance < tmp)) 255 | { 256 | map_lng = iter->map_lng; 257 | map_lat = iter->map_lat; 258 | } 259 | } 260 | 261 | if(candidates.size() == 0) 262 | return map_points; 263 | 264 | map_track.last_lng = lng; 265 | map_track.last_lat = lat; 266 | map_track.candidates = candidates; 267 | map_point.map_lng = map_lng; 268 | map_point.map_lat = map_lat; 269 | map_points.push_back(map_point); 270 | 271 | return map_points; 272 | } 273 | 274 | heading = this->calHeading(last_lng, last_lat, lng, lat); 275 | 276 | //update map_track candidates 277 | 278 | //seg_maps = this->map_index->batchMapPoint2Seg(); 279 | //TODO: add successor road seg to candidate 280 | // clear out of date segs 281 | 282 | for(vector::iterator iter = candidates.begin(); iter != candidates.end(); iter++) { 283 | 284 | seg_heading = iter->seg_heading; 285 | heading_resemblance = this->headingResemblance(seg_heading, heading); 286 | seg_map = this->map_index->mapGridSeg(lng, lat, iter->seg); 287 | if(seg_map.on_seg) 288 | distance = seg_map.distance; 289 | else 290 | distance = seg_map.min_distance; 291 | distance_resemblance = this->distanceResemblance(distance, distance); 292 | double tmp = Min(heading_resemblance, distance_resemblance); 293 | if(tmp > max_resemblance) { 294 | max_resemblance = tmp; 295 | map_lng = seg_map.map_lng; 296 | map_lat = seg_map.map_lat; 297 | } 298 | } 299 | 300 | map_point.lng = map_lng; 301 | map_point.lat = map_lat; 302 | map_points.push_back(map_point); 303 | 304 | return map_points; 305 | } 306 | 307 | vector Matcher::match(uint32_t id, struct position position) 308 | { 309 | vector map_points; 310 | struct map_track map_track; 311 | 312 | map_points.clear(); 313 | 314 | map_track = this->track_map[id]; 315 | 316 | map_points = this->doMatch(position, map_track); 317 | 318 | //FIXME: update track_map here 319 | /* 320 | for(vector::iterator iter = match_map_points.begin(); iter != match_map_points.end(); iter++) 321 | { 322 | map_points.push_back(*iter); 323 | } 324 | */ 325 | 326 | return map_points; 327 | } 328 | 329 | -------------------------------------------------------------------------------- /tools/query_grid/compile: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for compilers which do not understand '-c -o'. 3 | 4 | scriptversion=2012-10-14.11; # UTC 5 | 6 | # Copyright (C) 1999-2013 Free Software Foundation, Inc. 7 | # Written by Tom Tromey . 8 | # 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | # This file is maintained in Automake, please report 28 | # bugs to or send patches to 29 | # . 30 | 31 | nl=' 32 | ' 33 | 34 | # We need space, tab and new line, in precisely that order. Quoting is 35 | # there to prevent tools from complaining about whitespace usage. 36 | IFS=" "" $nl" 37 | 38 | file_conv= 39 | 40 | # func_file_conv build_file lazy 41 | # Convert a $build file to $host form and store it in $file 42 | # Currently only supports Windows hosts. If the determined conversion 43 | # type is listed in (the comma separated) LAZY, no conversion will 44 | # take place. 45 | func_file_conv () 46 | { 47 | file=$1 48 | case $file in 49 | / | /[!/]*) # absolute file, and not a UNC file 50 | if test -z "$file_conv"; then 51 | # lazily determine how to convert abs files 52 | case `uname -s` in 53 | MINGW*) 54 | file_conv=mingw 55 | ;; 56 | CYGWIN*) 57 | file_conv=cygwin 58 | ;; 59 | *) 60 | file_conv=wine 61 | ;; 62 | esac 63 | fi 64 | case $file_conv/,$2, in 65 | *,$file_conv,*) 66 | ;; 67 | mingw/*) 68 | file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69 | ;; 70 | cygwin/*) 71 | file=`cygpath -m "$file" || echo "$file"` 72 | ;; 73 | wine/*) 74 | file=`winepath -w "$file" || echo "$file"` 75 | ;; 76 | esac 77 | ;; 78 | esac 79 | } 80 | 81 | # func_cl_dashL linkdir 82 | # Make cl look for libraries in LINKDIR 83 | func_cl_dashL () 84 | { 85 | func_file_conv "$1" 86 | if test -z "$lib_path"; then 87 | lib_path=$file 88 | else 89 | lib_path="$lib_path;$file" 90 | fi 91 | linker_opts="$linker_opts -LIBPATH:$file" 92 | } 93 | 94 | # func_cl_dashl library 95 | # Do a library search-path lookup for cl 96 | func_cl_dashl () 97 | { 98 | lib=$1 99 | found=no 100 | save_IFS=$IFS 101 | IFS=';' 102 | for dir in $lib_path $LIB 103 | do 104 | IFS=$save_IFS 105 | if $shared && test -f "$dir/$lib.dll.lib"; then 106 | found=yes 107 | lib=$dir/$lib.dll.lib 108 | break 109 | fi 110 | if test -f "$dir/$lib.lib"; then 111 | found=yes 112 | lib=$dir/$lib.lib 113 | break 114 | fi 115 | if test -f "$dir/lib$lib.a"; then 116 | found=yes 117 | lib=$dir/lib$lib.a 118 | break 119 | fi 120 | done 121 | IFS=$save_IFS 122 | 123 | if test "$found" != yes; then 124 | lib=$lib.lib 125 | fi 126 | } 127 | 128 | # func_cl_wrapper cl arg... 129 | # Adjust compile command to suit cl 130 | func_cl_wrapper () 131 | { 132 | # Assume a capable shell 133 | lib_path= 134 | shared=: 135 | linker_opts= 136 | for arg 137 | do 138 | if test -n "$eat"; then 139 | eat= 140 | else 141 | case $1 in 142 | -o) 143 | # configure might choose to run compile as 'compile cc -o foo foo.c'. 144 | eat=1 145 | case $2 in 146 | *.o | *.[oO][bB][jJ]) 147 | func_file_conv "$2" 148 | set x "$@" -Fo"$file" 149 | shift 150 | ;; 151 | *) 152 | func_file_conv "$2" 153 | set x "$@" -Fe"$file" 154 | shift 155 | ;; 156 | esac 157 | ;; 158 | -I) 159 | eat=1 160 | func_file_conv "$2" mingw 161 | set x "$@" -I"$file" 162 | shift 163 | ;; 164 | -I*) 165 | func_file_conv "${1#-I}" mingw 166 | set x "$@" -I"$file" 167 | shift 168 | ;; 169 | -l) 170 | eat=1 171 | func_cl_dashl "$2" 172 | set x "$@" "$lib" 173 | shift 174 | ;; 175 | -l*) 176 | func_cl_dashl "${1#-l}" 177 | set x "$@" "$lib" 178 | shift 179 | ;; 180 | -L) 181 | eat=1 182 | func_cl_dashL "$2" 183 | ;; 184 | -L*) 185 | func_cl_dashL "${1#-L}" 186 | ;; 187 | -static) 188 | shared=false 189 | ;; 190 | -Wl,*) 191 | arg=${1#-Wl,} 192 | save_ifs="$IFS"; IFS=',' 193 | for flag in $arg; do 194 | IFS="$save_ifs" 195 | linker_opts="$linker_opts $flag" 196 | done 197 | IFS="$save_ifs" 198 | ;; 199 | -Xlinker) 200 | eat=1 201 | linker_opts="$linker_opts $2" 202 | ;; 203 | -*) 204 | set x "$@" "$1" 205 | shift 206 | ;; 207 | *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208 | func_file_conv "$1" 209 | set x "$@" -Tp"$file" 210 | shift 211 | ;; 212 | *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213 | func_file_conv "$1" mingw 214 | set x "$@" "$file" 215 | shift 216 | ;; 217 | *) 218 | set x "$@" "$1" 219 | shift 220 | ;; 221 | esac 222 | fi 223 | shift 224 | done 225 | if test -n "$linker_opts"; then 226 | linker_opts="-link$linker_opts" 227 | fi 228 | exec "$@" $linker_opts 229 | exit 1 230 | } 231 | 232 | eat= 233 | 234 | case $1 in 235 | '') 236 | echo "$0: No command. Try '$0 --help' for more information." 1>&2 237 | exit 1; 238 | ;; 239 | -h | --h*) 240 | cat <<\EOF 241 | Usage: compile [--help] [--version] PROGRAM [ARGS] 242 | 243 | Wrapper for compilers which do not understand '-c -o'. 244 | Remove '-o dest.o' from ARGS, run PROGRAM with the remaining 245 | arguments, and rename the output as expected. 246 | 247 | If you are trying to build a whole package this is not the 248 | right script to run: please start by reading the file 'INSTALL'. 249 | 250 | Report bugs to . 251 | EOF 252 | exit $? 253 | ;; 254 | -v | --v*) 255 | echo "compile $scriptversion" 256 | exit $? 257 | ;; 258 | cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 259 | func_cl_wrapper "$@" # Doesn't return... 260 | ;; 261 | esac 262 | 263 | ofile= 264 | cfile= 265 | 266 | for arg 267 | do 268 | if test -n "$eat"; then 269 | eat= 270 | else 271 | case $1 in 272 | -o) 273 | # configure might choose to run compile as 'compile cc -o foo foo.c'. 274 | # So we strip '-o arg' only if arg is an object. 275 | eat=1 276 | case $2 in 277 | *.o | *.obj) 278 | ofile=$2 279 | ;; 280 | *) 281 | set x "$@" -o "$2" 282 | shift 283 | ;; 284 | esac 285 | ;; 286 | *.c) 287 | cfile=$1 288 | set x "$@" "$1" 289 | shift 290 | ;; 291 | *) 292 | set x "$@" "$1" 293 | shift 294 | ;; 295 | esac 296 | fi 297 | shift 298 | done 299 | 300 | if test -z "$ofile" || test -z "$cfile"; then 301 | # If no '-o' option was seen then we might have been invoked from a 302 | # pattern rule where we don't need one. That is ok -- this is a 303 | # normal compilation that the losing compiler can handle. If no 304 | # '.c' file was seen then we are probably linking. That is also 305 | # ok. 306 | exec "$@" 307 | fi 308 | 309 | # Name of file we expect compiler to create. 310 | cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 311 | 312 | # Create the lock directory. 313 | # Note: use '[/\\:.-]' here to ensure that we don't use the same name 314 | # that we are using for the .o file. Also, base the name on the expected 315 | # object file name, since that is what matters with a parallel build. 316 | lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 317 | while true; do 318 | if mkdir "$lockdir" >/dev/null 2>&1; then 319 | break 320 | fi 321 | sleep 1 322 | done 323 | # FIXME: race condition here if user kills between mkdir and trap. 324 | trap "rmdir '$lockdir'; exit 1" 1 2 15 325 | 326 | # Run the compile. 327 | "$@" 328 | ret=$? 329 | 330 | if test -f "$cofile"; then 331 | test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 332 | elif test -f "${cofile}bj"; then 333 | test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 334 | fi 335 | 336 | rmdir "$lockdir" 337 | exit $ret 338 | 339 | # Local Variables: 340 | # mode: shell-script 341 | # sh-indentation: 2 342 | # eval: (add-hook 'write-file-hooks 'time-stamp) 343 | # time-stamp-start: "scriptversion=" 344 | # time-stamp-format: "%:y-%02m-%02d.%02H" 345 | # time-stamp-time-zone: "UTC" 346 | # time-stamp-end: "; # UTC" 347 | # End: 348 | -------------------------------------------------------------------------------- /tools/gps_preprocess/gps_preprocess.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #include 6 | 7 | #include "common.h" 8 | #include "gps_preprocess.h" 9 | #include "../../json/json.h" 10 | 11 | #define DEVIATION 1.E-10 12 | 13 | 14 | GpsPreprocess::GpsPreprocess(string data_file) 15 | { 16 | if("" == data_file) 17 | return; 18 | 19 | this->init(data_file); 20 | } 21 | 22 | void GpsPreprocess::init(string data_file) 23 | { 24 | this->loadJsonGps(data_file); 25 | } 26 | 27 | bool GpsPreprocess::isEqualDouble(double val1, double val2) 28 | { 29 | if(fabs(val1-val2) <= DEVIATION) 30 | return true; 31 | return false; 32 | } 33 | 34 | int GpsPreprocess::getErrno() 35 | { 36 | return 0; 37 | } 38 | 39 | string GpsPreprocess::getErrMsg() 40 | { 41 | return ""; 42 | } 43 | 44 | void GpsPreprocess::loadJsonGps(string gps_file) 45 | { 46 | string json_string = ""; 47 | ifstream infile; 48 | #define LINE_BUFFER_LEN 1*1024*1024 49 | char buffer[LINE_BUFFER_LEN]; 50 | 51 | infile.open(gps_file, ios_base::in); 52 | if(!infile.good()) 53 | return ; 54 | 55 | while(infile.getline(buffer, LINE_BUFFER_LEN).good()) 56 | { 57 | json_string += string(buffer); 58 | } 59 | json_string += string(buffer); 60 | 61 | infile.close(); 62 | 63 | this->js.clear(); 64 | this->js = json::parse(json_string); 65 | 66 | //debug_msg("json_size:%d.\n", js.size()); 67 | 68 | return ; 69 | } 70 | 71 | void GpsPreprocess::dumpJsonGps(string dump_file) 72 | { 73 | string json_string = ""; 74 | FILE *fp; 75 | 76 | if("" != dump_file) { 77 | fp = fopen(dump_file.c_str(), "w"); 78 | //FIXME: log the error here. 79 | if(NULL == fp) 80 | fp = stdout; 81 | } 82 | else 83 | fp = stdout; 84 | 85 | json_string = this->js.to_string(); 86 | 87 | fwrite(json_string.c_str(), json_string.length(), 1, fp); 88 | 89 | if(stdout != fp) 90 | fclose(fp); 91 | } 92 | 93 | void GpsPreprocess::dumpJsonGpsBeauty(string dump_file) 94 | { 95 | size_t i; 96 | string json_string = ""; 97 | FILE *fp; 98 | double last_heading=0, heading=0, heading_dis=0; 99 | 100 | if("" != dump_file) { 101 | fp = fopen(dump_file.c_str(), "w"); 102 | //FIXME: log the error here. 103 | if(NULL == fp) 104 | fp = stdout; 105 | } 106 | else 107 | fp = stdout; 108 | 109 | json_string = "time\t\t\tlng\t\tlat\t\theading\t\theading(dg)\theading_dis\tspeed(ms)\tspeed(kmh)\n"; 110 | fwrite(json_string.c_str(), json_string.length(), 1, fp); 111 | 112 | for(i = 0; i < this->js.size(); i++) 113 | { 114 | last_heading = heading; 115 | heading = String2Double(this->js[i]["heading"].to_string())/DEF_PI180; 116 | heading_dis = heading - last_heading; 117 | //FIXME: a more high-performance method to use json lib 118 | json_string = this->js[i]["gps_time"].to_string() 119 | + "\t" + this->js[i]["lng"].to_string() 120 | + "\t" + this->js[i]["lat"].to_string() 121 | + "\t" + this->js[i]["heading"].to_string() 122 | + "\t" + Double2String(String2Double(this->js[i]["heading"].to_string())/DEF_PI180) 123 | + "\t" + Double2String(heading_dis) 124 | + "\t" + this->js[i]["speed"].to_string() 125 | + "\t" + Double2String(String2Double(this->js[i]["speed"].to_string())*3.6) 126 | + "\n"; 127 | 128 | fwrite(json_string.c_str(), json_string.length(), 1, fp); 129 | } 130 | 131 | if(stdout != fp) 132 | fclose(fp); 133 | } 134 | 135 | /* 136 | static const double DEF_PI = 3.14159265359; // PI 137 | static const double DEF_2PI = 6.28318530712; // 2*PI 138 | static const double DEF_PI180 = 0.01745329252; // PI/180.0 139 | static const double DEF_R = 6370693.5; // radius of earth 140 | */ 141 | 142 | void GpsPreprocess::appendLongSpeed() 143 | { 144 | unsigned int i; 145 | double last_lng, last_lat, lng, lat; 146 | double last_tm, tm; 147 | double speed; 148 | 149 | lng = String2Double(js[0]["lng"].to_string()); 150 | lat = String2Double(js[0]["lat"].to_string()); 151 | tm = String2Double(js[0]["gps_time"].to_string()); 152 | this->js[0]["speed"] = 0; 153 | for(i = 1; i < this->js.size(); i++) 154 | { 155 | last_lng = lng; 156 | last_lat = lat; 157 | last_tm = tm; 158 | lng = String2Double(js[i]["lng"].to_string()); 159 | lat = String2Double(js[i]["lat"].to_string()); 160 | tm = String2Double(js[i]["gps_time"].to_string()); 161 | speed = this->calLongSpeed(last_lng, last_lat, lng, lat, last_tm, tm); 162 | //debug_msg("%f\t%f\t%f\t%f\tspeed:%f\n", last_lng, last_lat, lng, lat, speed); 163 | this->js[i]["speed"] = speed; 164 | } 165 | 166 | return; 167 | } 168 | 169 | void GpsPreprocess::appendShortSpeed() 170 | { 171 | return; 172 | } 173 | 174 | void GpsPreprocess::appendLineHeading() 175 | { 176 | unsigned int i; 177 | double last_lng, last_lat, lng, lat; 178 | double heading; 179 | 180 | lng = String2Double(js[0]["lng"].to_string()); 181 | lat = String2Double(js[0]["lat"].to_string()); 182 | this->js[0]["heading"] = 0; 183 | for(i = 1; i < this->js.size(); i++) 184 | { 185 | last_lng = lng; 186 | last_lat = lat; 187 | lng = String2Double(js[i]["lng"].to_string()); 188 | lat = String2Double(js[i]["lat"].to_string()); 189 | heading = this->calLineHeading(last_lng, last_lat, lng, lat); 190 | //debug_msg("%f\t%f\t%f\t%f\theading:%f\theadingDgr:%f\n", last_lng, last_lat, lng, lat, heading, heading/DEF_PI180 ); 191 | this->js[i]["heading"] = heading; 192 | } 193 | 194 | return; 195 | } 196 | 197 | double GpsPreprocess::calLineDistance(double start_lng, double start_lat, double end_lng, double end_lat) 198 | { 199 | double distance, sq_distance; 200 | 201 | sq_distance = (end_lng - start_lng)*(end_lng - start_lng) + (end_lat - start_lat)*(end_lat - start_lat); 202 | distance = sqrt(sq_distance); 203 | 204 | return distance; 205 | } 206 | 207 | double GpsPreprocess::calShortDistance(double lon1, double lat1, double lon2, double lat2) 208 | { 209 | double ew1, ns1, ew2, ns2; 210 | double dx, dy, dew; 211 | double distance; 212 | // 角度转换为弧度 213 | ew1 = lon1 * DEF_PI180; 214 | ns1 = lat1 * DEF_PI180; 215 | ew2 = lon2 * DEF_PI180; 216 | ns2 = lat2 * DEF_PI180; 217 | // 经度差 218 | dew = ew1 - ew2; 219 | // 若跨东经和西经180 度,进行调整 220 | if (dew > DEF_PI) 221 | dew = DEF_2PI - dew; 222 | else if (dew < -DEF_PI) 223 | dew = DEF_2PI + dew; 224 | dx = DEF_R * cos(ns1) * dew; // 东西方向长度(在纬度圈上的投影长度) 225 | dy = DEF_R * (ns1 - ns2); // 南北方向长度(在经度圈上的投影长度) 226 | // 勾股定理求斜边长 227 | distance = sqrt(dx * dx + dy * dy); 228 | return distance; 229 | } 230 | 231 | double GpsPreprocess::calLongDistance(double lon1, double lat1, double lon2, double lat2) 232 | { 233 | double ew1, ns1, ew2, ns2; 234 | double distance; 235 | // 角度转换为弧度 236 | ew1 = lon1 * DEF_PI180; 237 | ns1 = lat1 * DEF_PI180; 238 | ew2 = lon2 * DEF_PI180; 239 | ns2 = lat2 * DEF_PI180; 240 | // 求大圆劣弧与球心所夹的角(弧度) 241 | distance = sin(ns1) * sin(ns2) + cos(ns1) * cos(ns2) * cos(ew1 - ew2); 242 | // 调整到[-1..1]范围内,避免溢出 243 | if (distance > 1.0) 244 | distance = 1.0; 245 | else if (distance < -1.0) 246 | distance = -1.0; 247 | // 求大圆劣弧长度 248 | distance = DEF_R * acos(distance); 249 | return distance; 250 | } 251 | 252 | /** 253 | * @desc: m/s = 3.6 km/h 254 | * @return: speed(m/s) 255 | * @ 256 | */ 257 | double GpsPreprocess::calLongSpeed(double lng1, double lat1, double lng2, double lat2, double time1, double time2) 258 | { 259 | double distance, time_gap; 260 | 261 | if(isEqualDouble(time1, time2)) 262 | return 0; 263 | 264 | time_gap = (time2 - time1)/1000; // ms to s 265 | distance = this->calLongDistance(lng1, lat1, lng2, lat2); 266 | 267 | //debug_msg("time_gap:%f\tdistance:%f\n", time_gap, distance); 268 | 269 | return distance/time_gap; 270 | } 271 | 272 | double GpsPreprocess::calShortSpeed(double lng1, double lat1, double lng2, double lat2, double time1, double time2) 273 | { 274 | double distance, time_gap; 275 | 276 | if(isEqualDouble(time1, time2)) 277 | return 0; 278 | 279 | time_gap = time2 - time1; 280 | distance = this->calShortDistance(lng1, lat1, lng2, lat2); 281 | 282 | return distance/time_gap; 283 | } 284 | 285 | /** 286 | * + P2 287 | * . 288 | * . 289 | * . 290 | * . 291 | * . )theta 292 | * P1 +----------+ P3 293 | * 294 | * 295 | * (P2-P1(P3-P1) = |P2-P1|*|P3-P1|*cos(theta) 296 | */ 297 | 298 | double GpsPreprocess::calLineHeading(double lng1, double lat1, double lng2, double lat2) 299 | { 300 | double theta; 301 | double cos_theta; 302 | double fake_lng, fake_lat; 303 | double distance1, distance2; 304 | 305 | if(isEqualDouble(lng1, lng2)) 306 | return 0.0; 307 | 308 | if(isEqualDouble(lng1, lng2)) { 309 | 310 | if(lat2 > lat1) 311 | theta = DEF_PI/2; 312 | else 313 | theta = -DEF_PI/2; 314 | return theta; 315 | } 316 | 317 | fake_lng = lng1 + fabs(lng2 - lng1); 318 | fake_lat = lat1; 319 | 320 | distance1 = this->calLineDistance(lng1, lat1, lng2, lat2); 321 | distance2 = this->calLineDistance(lng1, lat1, fake_lng, fake_lat); 322 | 323 | //FIXME: check if distance1 or distance2 equal zero 324 | if(isEqualDouble(distance1, 0) || isEqualDouble(distance2, 0)) { 325 | debug_msg("dis1:%f\tdis2:%f\n", distance1, distance2); 326 | return 0.0; 327 | } 328 | cos_theta = ((lng2-lng1)*(fake_lng-lng1)+(lat2-lat1)*(fake_lat-lat1)) / (distance1*distance2); 329 | 330 | theta = acos(cos_theta); 331 | if(lat2 < lat1) 332 | theta = DEF_2PI - theta; 333 | //debug_msg("%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", lng2-lng1, fake_lng-lng1, lat2-lat1, fake_lat-lat1, distance1, distance2, cos_theta, theta); 334 | 335 | return theta; 336 | } 337 | 338 | 339 | -------------------------------------------------------------------------------- /tools/query_grid/.deps/test.Po: -------------------------------------------------------------------------------- 1 | test.o: test.cpp /usr/include/stdc-predef.h /usr/include/c++/4.8/iostream \ 2 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++config.h \ 3 | /usr/include/i386-linux-gnu/c++/4.8/bits/os_defines.h \ 4 | /usr/include/features.h /usr/include/i386-linux-gnu/sys/cdefs.h \ 5 | /usr/include/i386-linux-gnu/bits/wordsize.h \ 6 | /usr/include/i386-linux-gnu/gnu/stubs.h \ 7 | /usr/include/i386-linux-gnu/gnu/stubs-32.h \ 8 | /usr/include/i386-linux-gnu/c++/4.8/bits/cpu_defines.h \ 9 | /usr/include/c++/4.8/ostream /usr/include/c++/4.8/ios \ 10 | /usr/include/c++/4.8/iosfwd /usr/include/c++/4.8/bits/stringfwd.h \ 11 | /usr/include/c++/4.8/bits/memoryfwd.h \ 12 | /usr/include/c++/4.8/bits/postypes.h /usr/include/c++/4.8/cwchar \ 13 | /usr/include/wchar.h /usr/include/stdio.h \ 14 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stdarg.h \ 15 | /usr/include/i386-linux-gnu/bits/wchar.h \ 16 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stddef.h /usr/include/xlocale.h \ 17 | /usr/include/c++/4.8/exception \ 18 | /usr/include/c++/4.8/bits/atomic_lockfree_defines.h \ 19 | /usr/include/c++/4.8/bits/char_traits.h \ 20 | /usr/include/c++/4.8/bits/stl_algobase.h \ 21 | /usr/include/c++/4.8/bits/functexcept.h \ 22 | /usr/include/c++/4.8/bits/exception_defines.h \ 23 | /usr/include/c++/4.8/bits/cpp_type_traits.h \ 24 | /usr/include/c++/4.8/ext/type_traits.h \ 25 | /usr/include/c++/4.8/ext/numeric_traits.h \ 26 | /usr/include/c++/4.8/bits/stl_pair.h /usr/include/c++/4.8/bits/move.h \ 27 | /usr/include/c++/4.8/bits/concept_check.h \ 28 | /usr/include/c++/4.8/bits/stl_iterator_base_types.h \ 29 | /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h \ 30 | /usr/include/c++/4.8/debug/debug.h \ 31 | /usr/include/c++/4.8/bits/stl_iterator.h \ 32 | /usr/include/c++/4.8/bits/localefwd.h \ 33 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++locale.h \ 34 | /usr/include/c++/4.8/clocale /usr/include/locale.h \ 35 | /usr/include/i386-linux-gnu/bits/locale.h /usr/include/c++/4.8/cctype \ 36 | /usr/include/ctype.h /usr/include/i386-linux-gnu/bits/types.h \ 37 | /usr/include/i386-linux-gnu/bits/typesizes.h /usr/include/endian.h \ 38 | /usr/include/i386-linux-gnu/bits/endian.h \ 39 | /usr/include/i386-linux-gnu/bits/byteswap.h \ 40 | /usr/include/i386-linux-gnu/bits/byteswap-16.h \ 41 | /usr/include/c++/4.8/bits/ios_base.h \ 42 | /usr/include/c++/4.8/ext/atomicity.h \ 43 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr.h \ 44 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr-default.h \ 45 | /usr/include/pthread.h /usr/include/sched.h /usr/include/time.h \ 46 | /usr/include/i386-linux-gnu/bits/sched.h \ 47 | /usr/include/i386-linux-gnu/bits/time.h \ 48 | /usr/include/i386-linux-gnu/bits/timex.h \ 49 | /usr/include/i386-linux-gnu/bits/pthreadtypes.h \ 50 | /usr/include/i386-linux-gnu/bits/setjmp.h \ 51 | /usr/include/i386-linux-gnu/c++/4.8/bits/atomic_word.h \ 52 | /usr/include/c++/4.8/bits/locale_classes.h /usr/include/c++/4.8/string \ 53 | /usr/include/c++/4.8/bits/allocator.h \ 54 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++allocator.h \ 55 | /usr/include/c++/4.8/ext/new_allocator.h /usr/include/c++/4.8/new \ 56 | /usr/include/c++/4.8/bits/ostream_insert.h \ 57 | /usr/include/c++/4.8/bits/cxxabi_forced.h \ 58 | /usr/include/c++/4.8/bits/stl_function.h \ 59 | /usr/include/c++/4.8/backward/binders.h \ 60 | /usr/include/c++/4.8/bits/range_access.h \ 61 | /usr/include/c++/4.8/bits/basic_string.h \ 62 | /usr/include/c++/4.8/bits/basic_string.tcc \ 63 | /usr/include/c++/4.8/bits/locale_classes.tcc \ 64 | /usr/include/c++/4.8/streambuf /usr/include/c++/4.8/bits/streambuf.tcc \ 65 | /usr/include/c++/4.8/bits/basic_ios.h \ 66 | /usr/include/c++/4.8/bits/locale_facets.h /usr/include/c++/4.8/cwctype \ 67 | /usr/include/wctype.h \ 68 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_base.h \ 69 | /usr/include/c++/4.8/bits/streambuf_iterator.h \ 70 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_inline.h \ 71 | /usr/include/c++/4.8/bits/locale_facets.tcc \ 72 | /usr/include/c++/4.8/bits/basic_ios.tcc \ 73 | /usr/include/c++/4.8/bits/ostream.tcc /usr/include/c++/4.8/istream \ 74 | /usr/include/c++/4.8/bits/istream.tcc /usr/include/c++/4.8/vector \ 75 | /usr/include/c++/4.8/bits/stl_construct.h \ 76 | /usr/include/c++/4.8/ext/alloc_traits.h \ 77 | /usr/include/c++/4.8/bits/stl_uninitialized.h \ 78 | /usr/include/c++/4.8/bits/stl_vector.h \ 79 | /usr/include/c++/4.8/bits/stl_bvector.h \ 80 | /usr/include/c++/4.8/bits/vector.tcc query_grid.h /usr/include/libio.h \ 81 | /usr/include/_G_config.h /usr/include/i386-linux-gnu/bits/stdio_lim.h \ 82 | /usr/include/i386-linux-gnu/bits/sys_errlist.h 83 | 84 | /usr/include/stdc-predef.h: 85 | 86 | /usr/include/c++/4.8/iostream: 87 | 88 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++config.h: 89 | 90 | /usr/include/i386-linux-gnu/c++/4.8/bits/os_defines.h: 91 | 92 | /usr/include/features.h: 93 | 94 | /usr/include/i386-linux-gnu/sys/cdefs.h: 95 | 96 | /usr/include/i386-linux-gnu/bits/wordsize.h: 97 | 98 | /usr/include/i386-linux-gnu/gnu/stubs.h: 99 | 100 | /usr/include/i386-linux-gnu/gnu/stubs-32.h: 101 | 102 | /usr/include/i386-linux-gnu/c++/4.8/bits/cpu_defines.h: 103 | 104 | /usr/include/c++/4.8/ostream: 105 | 106 | /usr/include/c++/4.8/ios: 107 | 108 | /usr/include/c++/4.8/iosfwd: 109 | 110 | /usr/include/c++/4.8/bits/stringfwd.h: 111 | 112 | /usr/include/c++/4.8/bits/memoryfwd.h: 113 | 114 | /usr/include/c++/4.8/bits/postypes.h: 115 | 116 | /usr/include/c++/4.8/cwchar: 117 | 118 | /usr/include/wchar.h: 119 | 120 | /usr/include/stdio.h: 121 | 122 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stdarg.h: 123 | 124 | /usr/include/i386-linux-gnu/bits/wchar.h: 125 | 126 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stddef.h: 127 | 128 | /usr/include/xlocale.h: 129 | 130 | /usr/include/c++/4.8/exception: 131 | 132 | /usr/include/c++/4.8/bits/atomic_lockfree_defines.h: 133 | 134 | /usr/include/c++/4.8/bits/char_traits.h: 135 | 136 | /usr/include/c++/4.8/bits/stl_algobase.h: 137 | 138 | /usr/include/c++/4.8/bits/functexcept.h: 139 | 140 | /usr/include/c++/4.8/bits/exception_defines.h: 141 | 142 | /usr/include/c++/4.8/bits/cpp_type_traits.h: 143 | 144 | /usr/include/c++/4.8/ext/type_traits.h: 145 | 146 | /usr/include/c++/4.8/ext/numeric_traits.h: 147 | 148 | /usr/include/c++/4.8/bits/stl_pair.h: 149 | 150 | /usr/include/c++/4.8/bits/move.h: 151 | 152 | /usr/include/c++/4.8/bits/concept_check.h: 153 | 154 | /usr/include/c++/4.8/bits/stl_iterator_base_types.h: 155 | 156 | /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h: 157 | 158 | /usr/include/c++/4.8/debug/debug.h: 159 | 160 | /usr/include/c++/4.8/bits/stl_iterator.h: 161 | 162 | /usr/include/c++/4.8/bits/localefwd.h: 163 | 164 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++locale.h: 165 | 166 | /usr/include/c++/4.8/clocale: 167 | 168 | /usr/include/locale.h: 169 | 170 | /usr/include/i386-linux-gnu/bits/locale.h: 171 | 172 | /usr/include/c++/4.8/cctype: 173 | 174 | /usr/include/ctype.h: 175 | 176 | /usr/include/i386-linux-gnu/bits/types.h: 177 | 178 | /usr/include/i386-linux-gnu/bits/typesizes.h: 179 | 180 | /usr/include/endian.h: 181 | 182 | /usr/include/i386-linux-gnu/bits/endian.h: 183 | 184 | /usr/include/i386-linux-gnu/bits/byteswap.h: 185 | 186 | /usr/include/i386-linux-gnu/bits/byteswap-16.h: 187 | 188 | /usr/include/c++/4.8/bits/ios_base.h: 189 | 190 | /usr/include/c++/4.8/ext/atomicity.h: 191 | 192 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr.h: 193 | 194 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr-default.h: 195 | 196 | /usr/include/pthread.h: 197 | 198 | /usr/include/sched.h: 199 | 200 | /usr/include/time.h: 201 | 202 | /usr/include/i386-linux-gnu/bits/sched.h: 203 | 204 | /usr/include/i386-linux-gnu/bits/time.h: 205 | 206 | /usr/include/i386-linux-gnu/bits/timex.h: 207 | 208 | /usr/include/i386-linux-gnu/bits/pthreadtypes.h: 209 | 210 | /usr/include/i386-linux-gnu/bits/setjmp.h: 211 | 212 | /usr/include/i386-linux-gnu/c++/4.8/bits/atomic_word.h: 213 | 214 | /usr/include/c++/4.8/bits/locale_classes.h: 215 | 216 | /usr/include/c++/4.8/string: 217 | 218 | /usr/include/c++/4.8/bits/allocator.h: 219 | 220 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++allocator.h: 221 | 222 | /usr/include/c++/4.8/ext/new_allocator.h: 223 | 224 | /usr/include/c++/4.8/new: 225 | 226 | /usr/include/c++/4.8/bits/ostream_insert.h: 227 | 228 | /usr/include/c++/4.8/bits/cxxabi_forced.h: 229 | 230 | /usr/include/c++/4.8/bits/stl_function.h: 231 | 232 | /usr/include/c++/4.8/backward/binders.h: 233 | 234 | /usr/include/c++/4.8/bits/range_access.h: 235 | 236 | /usr/include/c++/4.8/bits/basic_string.h: 237 | 238 | /usr/include/c++/4.8/bits/basic_string.tcc: 239 | 240 | /usr/include/c++/4.8/bits/locale_classes.tcc: 241 | 242 | /usr/include/c++/4.8/streambuf: 243 | 244 | /usr/include/c++/4.8/bits/streambuf.tcc: 245 | 246 | /usr/include/c++/4.8/bits/basic_ios.h: 247 | 248 | /usr/include/c++/4.8/bits/locale_facets.h: 249 | 250 | /usr/include/c++/4.8/cwctype: 251 | 252 | /usr/include/wctype.h: 253 | 254 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_base.h: 255 | 256 | /usr/include/c++/4.8/bits/streambuf_iterator.h: 257 | 258 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_inline.h: 259 | 260 | /usr/include/c++/4.8/bits/locale_facets.tcc: 261 | 262 | /usr/include/c++/4.8/bits/basic_ios.tcc: 263 | 264 | /usr/include/c++/4.8/bits/ostream.tcc: 265 | 266 | /usr/include/c++/4.8/istream: 267 | 268 | /usr/include/c++/4.8/bits/istream.tcc: 269 | 270 | /usr/include/c++/4.8/vector: 271 | 272 | /usr/include/c++/4.8/bits/stl_construct.h: 273 | 274 | /usr/include/c++/4.8/ext/alloc_traits.h: 275 | 276 | /usr/include/c++/4.8/bits/stl_uninitialized.h: 277 | 278 | /usr/include/c++/4.8/bits/stl_vector.h: 279 | 280 | /usr/include/c++/4.8/bits/stl_bvector.h: 281 | 282 | /usr/include/c++/4.8/bits/vector.tcc: 283 | 284 | query_grid.h: 285 | 286 | /usr/include/libio.h: 287 | 288 | /usr/include/_G_config.h: 289 | 290 | /usr/include/i386-linux-gnu/bits/stdio_lim.h: 291 | 292 | /usr/include/i386-linux-gnu/bits/sys_errlist.h: 293 | -------------------------------------------------------------------------------- /tools/gen_distance_table/.deps/gen_distance_table.Po: -------------------------------------------------------------------------------- 1 | gen_distance_table.o: gen_distance_table.cpp /usr/include/stdc-predef.h \ 2 | gen_distance_table.h /usr/include/c++/4.8/iostream \ 3 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++config.h \ 4 | /usr/include/i386-linux-gnu/c++/4.8/bits/os_defines.h \ 5 | /usr/include/features.h /usr/include/i386-linux-gnu/sys/cdefs.h \ 6 | /usr/include/i386-linux-gnu/bits/wordsize.h \ 7 | /usr/include/i386-linux-gnu/gnu/stubs.h \ 8 | /usr/include/i386-linux-gnu/gnu/stubs-32.h \ 9 | /usr/include/i386-linux-gnu/c++/4.8/bits/cpu_defines.h \ 10 | /usr/include/c++/4.8/ostream /usr/include/c++/4.8/ios \ 11 | /usr/include/c++/4.8/iosfwd /usr/include/c++/4.8/bits/stringfwd.h \ 12 | /usr/include/c++/4.8/bits/memoryfwd.h \ 13 | /usr/include/c++/4.8/bits/postypes.h /usr/include/c++/4.8/cwchar \ 14 | /usr/include/wchar.h /usr/include/stdio.h \ 15 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stdarg.h \ 16 | /usr/include/i386-linux-gnu/bits/wchar.h \ 17 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stddef.h /usr/include/xlocale.h \ 18 | /usr/include/i386-linux-gnu/bits/wchar2.h /usr/include/c++/4.8/exception \ 19 | /usr/include/c++/4.8/bits/atomic_lockfree_defines.h \ 20 | /usr/include/c++/4.8/bits/char_traits.h \ 21 | /usr/include/c++/4.8/bits/stl_algobase.h \ 22 | /usr/include/c++/4.8/bits/functexcept.h \ 23 | /usr/include/c++/4.8/bits/exception_defines.h \ 24 | /usr/include/c++/4.8/bits/cpp_type_traits.h \ 25 | /usr/include/c++/4.8/ext/type_traits.h \ 26 | /usr/include/c++/4.8/ext/numeric_traits.h \ 27 | /usr/include/c++/4.8/bits/stl_pair.h /usr/include/c++/4.8/bits/move.h \ 28 | /usr/include/c++/4.8/bits/concept_check.h \ 29 | /usr/include/c++/4.8/bits/stl_iterator_base_types.h \ 30 | /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h \ 31 | /usr/include/c++/4.8/debug/debug.h \ 32 | /usr/include/c++/4.8/bits/stl_iterator.h \ 33 | /usr/include/c++/4.8/bits/localefwd.h \ 34 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++locale.h \ 35 | /usr/include/c++/4.8/clocale /usr/include/locale.h \ 36 | /usr/include/i386-linux-gnu/bits/locale.h /usr/include/c++/4.8/cctype \ 37 | /usr/include/ctype.h /usr/include/i386-linux-gnu/bits/types.h \ 38 | /usr/include/i386-linux-gnu/bits/typesizes.h /usr/include/endian.h \ 39 | /usr/include/i386-linux-gnu/bits/endian.h \ 40 | /usr/include/i386-linux-gnu/bits/byteswap.h \ 41 | /usr/include/i386-linux-gnu/bits/byteswap-16.h \ 42 | /usr/include/c++/4.8/bits/ios_base.h \ 43 | /usr/include/c++/4.8/ext/atomicity.h \ 44 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr.h \ 45 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr-default.h \ 46 | /usr/include/pthread.h /usr/include/sched.h /usr/include/time.h \ 47 | /usr/include/i386-linux-gnu/bits/sched.h \ 48 | /usr/include/i386-linux-gnu/bits/time.h \ 49 | /usr/include/i386-linux-gnu/bits/timex.h \ 50 | /usr/include/i386-linux-gnu/bits/pthreadtypes.h \ 51 | /usr/include/i386-linux-gnu/bits/setjmp.h \ 52 | /usr/include/i386-linux-gnu/c++/4.8/bits/atomic_word.h \ 53 | /usr/include/c++/4.8/bits/locale_classes.h /usr/include/c++/4.8/string \ 54 | /usr/include/c++/4.8/bits/allocator.h \ 55 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++allocator.h \ 56 | /usr/include/c++/4.8/ext/new_allocator.h /usr/include/c++/4.8/new \ 57 | /usr/include/c++/4.8/bits/ostream_insert.h \ 58 | /usr/include/c++/4.8/bits/cxxabi_forced.h \ 59 | /usr/include/c++/4.8/bits/stl_function.h \ 60 | /usr/include/c++/4.8/backward/binders.h \ 61 | /usr/include/c++/4.8/bits/range_access.h \ 62 | /usr/include/c++/4.8/bits/basic_string.h \ 63 | /usr/include/c++/4.8/bits/basic_string.tcc \ 64 | /usr/include/c++/4.8/bits/locale_classes.tcc \ 65 | /usr/include/c++/4.8/streambuf /usr/include/c++/4.8/bits/streambuf.tcc \ 66 | /usr/include/c++/4.8/bits/basic_ios.h \ 67 | /usr/include/c++/4.8/bits/locale_facets.h /usr/include/c++/4.8/cwctype \ 68 | /usr/include/wctype.h \ 69 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_base.h \ 70 | /usr/include/c++/4.8/bits/streambuf_iterator.h \ 71 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_inline.h \ 72 | /usr/include/c++/4.8/bits/locale_facets.tcc \ 73 | /usr/include/c++/4.8/bits/basic_ios.tcc \ 74 | /usr/include/c++/4.8/bits/ostream.tcc /usr/include/c++/4.8/istream \ 75 | /usr/include/c++/4.8/bits/istream.tcc /usr/include/c++/4.8/cmath \ 76 | /usr/include/math.h /usr/include/i386-linux-gnu/bits/huge_val.h \ 77 | /usr/include/i386-linux-gnu/bits/huge_valf.h \ 78 | /usr/include/i386-linux-gnu/bits/huge_vall.h \ 79 | /usr/include/i386-linux-gnu/bits/inf.h \ 80 | /usr/include/i386-linux-gnu/bits/nan.h \ 81 | /usr/include/i386-linux-gnu/bits/mathdef.h \ 82 | /usr/include/i386-linux-gnu/bits/mathcalls.h \ 83 | /usr/include/i386-linux-gnu/bits/mathinline.h /usr/include/libio.h \ 84 | /usr/include/_G_config.h /usr/include/i386-linux-gnu/bits/stdio_lim.h \ 85 | /usr/include/i386-linux-gnu/bits/sys_errlist.h \ 86 | /usr/include/i386-linux-gnu/bits/stdio.h \ 87 | /usr/include/i386-linux-gnu/bits/stdio2.h 88 | 89 | /usr/include/stdc-predef.h: 90 | 91 | gen_distance_table.h: 92 | 93 | /usr/include/c++/4.8/iostream: 94 | 95 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++config.h: 96 | 97 | /usr/include/i386-linux-gnu/c++/4.8/bits/os_defines.h: 98 | 99 | /usr/include/features.h: 100 | 101 | /usr/include/i386-linux-gnu/sys/cdefs.h: 102 | 103 | /usr/include/i386-linux-gnu/bits/wordsize.h: 104 | 105 | /usr/include/i386-linux-gnu/gnu/stubs.h: 106 | 107 | /usr/include/i386-linux-gnu/gnu/stubs-32.h: 108 | 109 | /usr/include/i386-linux-gnu/c++/4.8/bits/cpu_defines.h: 110 | 111 | /usr/include/c++/4.8/ostream: 112 | 113 | /usr/include/c++/4.8/ios: 114 | 115 | /usr/include/c++/4.8/iosfwd: 116 | 117 | /usr/include/c++/4.8/bits/stringfwd.h: 118 | 119 | /usr/include/c++/4.8/bits/memoryfwd.h: 120 | 121 | /usr/include/c++/4.8/bits/postypes.h: 122 | 123 | /usr/include/c++/4.8/cwchar: 124 | 125 | /usr/include/wchar.h: 126 | 127 | /usr/include/stdio.h: 128 | 129 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stdarg.h: 130 | 131 | /usr/include/i386-linux-gnu/bits/wchar.h: 132 | 133 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stddef.h: 134 | 135 | /usr/include/xlocale.h: 136 | 137 | /usr/include/i386-linux-gnu/bits/wchar2.h: 138 | 139 | /usr/include/c++/4.8/exception: 140 | 141 | /usr/include/c++/4.8/bits/atomic_lockfree_defines.h: 142 | 143 | /usr/include/c++/4.8/bits/char_traits.h: 144 | 145 | /usr/include/c++/4.8/bits/stl_algobase.h: 146 | 147 | /usr/include/c++/4.8/bits/functexcept.h: 148 | 149 | /usr/include/c++/4.8/bits/exception_defines.h: 150 | 151 | /usr/include/c++/4.8/bits/cpp_type_traits.h: 152 | 153 | /usr/include/c++/4.8/ext/type_traits.h: 154 | 155 | /usr/include/c++/4.8/ext/numeric_traits.h: 156 | 157 | /usr/include/c++/4.8/bits/stl_pair.h: 158 | 159 | /usr/include/c++/4.8/bits/move.h: 160 | 161 | /usr/include/c++/4.8/bits/concept_check.h: 162 | 163 | /usr/include/c++/4.8/bits/stl_iterator_base_types.h: 164 | 165 | /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h: 166 | 167 | /usr/include/c++/4.8/debug/debug.h: 168 | 169 | /usr/include/c++/4.8/bits/stl_iterator.h: 170 | 171 | /usr/include/c++/4.8/bits/localefwd.h: 172 | 173 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++locale.h: 174 | 175 | /usr/include/c++/4.8/clocale: 176 | 177 | /usr/include/locale.h: 178 | 179 | /usr/include/i386-linux-gnu/bits/locale.h: 180 | 181 | /usr/include/c++/4.8/cctype: 182 | 183 | /usr/include/ctype.h: 184 | 185 | /usr/include/i386-linux-gnu/bits/types.h: 186 | 187 | /usr/include/i386-linux-gnu/bits/typesizes.h: 188 | 189 | /usr/include/endian.h: 190 | 191 | /usr/include/i386-linux-gnu/bits/endian.h: 192 | 193 | /usr/include/i386-linux-gnu/bits/byteswap.h: 194 | 195 | /usr/include/i386-linux-gnu/bits/byteswap-16.h: 196 | 197 | /usr/include/c++/4.8/bits/ios_base.h: 198 | 199 | /usr/include/c++/4.8/ext/atomicity.h: 200 | 201 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr.h: 202 | 203 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr-default.h: 204 | 205 | /usr/include/pthread.h: 206 | 207 | /usr/include/sched.h: 208 | 209 | /usr/include/time.h: 210 | 211 | /usr/include/i386-linux-gnu/bits/sched.h: 212 | 213 | /usr/include/i386-linux-gnu/bits/time.h: 214 | 215 | /usr/include/i386-linux-gnu/bits/timex.h: 216 | 217 | /usr/include/i386-linux-gnu/bits/pthreadtypes.h: 218 | 219 | /usr/include/i386-linux-gnu/bits/setjmp.h: 220 | 221 | /usr/include/i386-linux-gnu/c++/4.8/bits/atomic_word.h: 222 | 223 | /usr/include/c++/4.8/bits/locale_classes.h: 224 | 225 | /usr/include/c++/4.8/string: 226 | 227 | /usr/include/c++/4.8/bits/allocator.h: 228 | 229 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++allocator.h: 230 | 231 | /usr/include/c++/4.8/ext/new_allocator.h: 232 | 233 | /usr/include/c++/4.8/new: 234 | 235 | /usr/include/c++/4.8/bits/ostream_insert.h: 236 | 237 | /usr/include/c++/4.8/bits/cxxabi_forced.h: 238 | 239 | /usr/include/c++/4.8/bits/stl_function.h: 240 | 241 | /usr/include/c++/4.8/backward/binders.h: 242 | 243 | /usr/include/c++/4.8/bits/range_access.h: 244 | 245 | /usr/include/c++/4.8/bits/basic_string.h: 246 | 247 | /usr/include/c++/4.8/bits/basic_string.tcc: 248 | 249 | /usr/include/c++/4.8/bits/locale_classes.tcc: 250 | 251 | /usr/include/c++/4.8/streambuf: 252 | 253 | /usr/include/c++/4.8/bits/streambuf.tcc: 254 | 255 | /usr/include/c++/4.8/bits/basic_ios.h: 256 | 257 | /usr/include/c++/4.8/bits/locale_facets.h: 258 | 259 | /usr/include/c++/4.8/cwctype: 260 | 261 | /usr/include/wctype.h: 262 | 263 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_base.h: 264 | 265 | /usr/include/c++/4.8/bits/streambuf_iterator.h: 266 | 267 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_inline.h: 268 | 269 | /usr/include/c++/4.8/bits/locale_facets.tcc: 270 | 271 | /usr/include/c++/4.8/bits/basic_ios.tcc: 272 | 273 | /usr/include/c++/4.8/bits/ostream.tcc: 274 | 275 | /usr/include/c++/4.8/istream: 276 | 277 | /usr/include/c++/4.8/bits/istream.tcc: 278 | 279 | /usr/include/c++/4.8/cmath: 280 | 281 | /usr/include/math.h: 282 | 283 | /usr/include/i386-linux-gnu/bits/huge_val.h: 284 | 285 | /usr/include/i386-linux-gnu/bits/huge_valf.h: 286 | 287 | /usr/include/i386-linux-gnu/bits/huge_vall.h: 288 | 289 | /usr/include/i386-linux-gnu/bits/inf.h: 290 | 291 | /usr/include/i386-linux-gnu/bits/nan.h: 292 | 293 | /usr/include/i386-linux-gnu/bits/mathdef.h: 294 | 295 | /usr/include/i386-linux-gnu/bits/mathcalls.h: 296 | 297 | /usr/include/i386-linux-gnu/bits/mathinline.h: 298 | 299 | /usr/include/libio.h: 300 | 301 | /usr/include/_G_config.h: 302 | 303 | /usr/include/i386-linux-gnu/bits/stdio_lim.h: 304 | 305 | /usr/include/i386-linux-gnu/bits/sys_errlist.h: 306 | 307 | /usr/include/i386-linux-gnu/bits/stdio.h: 308 | 309 | /usr/include/i386-linux-gnu/bits/stdio2.h: 310 | -------------------------------------------------------------------------------- /tools/query_grid/.deps/common.Po: -------------------------------------------------------------------------------- 1 | common.o: common.cpp /usr/include/stdc-predef.h /usr/include/stdlib.h \ 2 | /usr/include/features.h /usr/include/i386-linux-gnu/sys/cdefs.h \ 3 | /usr/include/i386-linux-gnu/bits/wordsize.h \ 4 | /usr/include/i386-linux-gnu/gnu/stubs.h \ 5 | /usr/include/i386-linux-gnu/gnu/stubs-32.h \ 6 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stddef.h \ 7 | /usr/include/i386-linux-gnu/bits/waitflags.h \ 8 | /usr/include/i386-linux-gnu/bits/waitstatus.h /usr/include/endian.h \ 9 | /usr/include/i386-linux-gnu/bits/endian.h \ 10 | /usr/include/i386-linux-gnu/bits/byteswap.h \ 11 | /usr/include/i386-linux-gnu/bits/types.h \ 12 | /usr/include/i386-linux-gnu/bits/typesizes.h \ 13 | /usr/include/i386-linux-gnu/bits/byteswap-16.h /usr/include/xlocale.h \ 14 | /usr/include/i386-linux-gnu/sys/types.h /usr/include/time.h \ 15 | /usr/include/i386-linux-gnu/sys/select.h \ 16 | /usr/include/i386-linux-gnu/bits/select.h \ 17 | /usr/include/i386-linux-gnu/bits/sigset.h \ 18 | /usr/include/i386-linux-gnu/bits/time.h \ 19 | /usr/include/i386-linux-gnu/sys/sysmacros.h \ 20 | /usr/include/i386-linux-gnu/bits/pthreadtypes.h /usr/include/alloca.h \ 21 | /usr/include/i386-linux-gnu/bits/stdlib-float.h /usr/include/stdio.h \ 22 | /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \ 23 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stdarg.h \ 24 | /usr/include/i386-linux-gnu/bits/stdio_lim.h \ 25 | /usr/include/i386-linux-gnu/bits/sys_errlist.h \ 26 | /usr/include/c++/4.8/iostream \ 27 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++config.h \ 28 | /usr/include/i386-linux-gnu/c++/4.8/bits/os_defines.h \ 29 | /usr/include/i386-linux-gnu/c++/4.8/bits/cpu_defines.h \ 30 | /usr/include/c++/4.8/ostream /usr/include/c++/4.8/ios \ 31 | /usr/include/c++/4.8/iosfwd /usr/include/c++/4.8/bits/stringfwd.h \ 32 | /usr/include/c++/4.8/bits/memoryfwd.h \ 33 | /usr/include/c++/4.8/bits/postypes.h /usr/include/c++/4.8/cwchar \ 34 | /usr/include/i386-linux-gnu/bits/wchar.h /usr/include/c++/4.8/exception \ 35 | /usr/include/c++/4.8/bits/atomic_lockfree_defines.h \ 36 | /usr/include/c++/4.8/bits/char_traits.h \ 37 | /usr/include/c++/4.8/bits/stl_algobase.h \ 38 | /usr/include/c++/4.8/bits/functexcept.h \ 39 | /usr/include/c++/4.8/bits/exception_defines.h \ 40 | /usr/include/c++/4.8/bits/cpp_type_traits.h \ 41 | /usr/include/c++/4.8/ext/type_traits.h \ 42 | /usr/include/c++/4.8/ext/numeric_traits.h \ 43 | /usr/include/c++/4.8/bits/stl_pair.h /usr/include/c++/4.8/bits/move.h \ 44 | /usr/include/c++/4.8/bits/concept_check.h \ 45 | /usr/include/c++/4.8/bits/stl_iterator_base_types.h \ 46 | /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h \ 47 | /usr/include/c++/4.8/debug/debug.h \ 48 | /usr/include/c++/4.8/bits/stl_iterator.h \ 49 | /usr/include/c++/4.8/bits/localefwd.h \ 50 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++locale.h \ 51 | /usr/include/c++/4.8/clocale /usr/include/locale.h \ 52 | /usr/include/i386-linux-gnu/bits/locale.h /usr/include/c++/4.8/cctype \ 53 | /usr/include/ctype.h /usr/include/c++/4.8/bits/ios_base.h \ 54 | /usr/include/c++/4.8/ext/atomicity.h \ 55 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr.h \ 56 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr-default.h \ 57 | /usr/include/pthread.h /usr/include/sched.h \ 58 | /usr/include/i386-linux-gnu/bits/sched.h \ 59 | /usr/include/i386-linux-gnu/bits/timex.h \ 60 | /usr/include/i386-linux-gnu/bits/setjmp.h \ 61 | /usr/include/i386-linux-gnu/c++/4.8/bits/atomic_word.h \ 62 | /usr/include/c++/4.8/bits/locale_classes.h /usr/include/c++/4.8/string \ 63 | /usr/include/c++/4.8/bits/allocator.h \ 64 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++allocator.h \ 65 | /usr/include/c++/4.8/ext/new_allocator.h /usr/include/c++/4.8/new \ 66 | /usr/include/c++/4.8/bits/ostream_insert.h \ 67 | /usr/include/c++/4.8/bits/cxxabi_forced.h \ 68 | /usr/include/c++/4.8/bits/stl_function.h \ 69 | /usr/include/c++/4.8/backward/binders.h \ 70 | /usr/include/c++/4.8/bits/range_access.h \ 71 | /usr/include/c++/4.8/bits/basic_string.h \ 72 | /usr/include/c++/4.8/bits/basic_string.tcc \ 73 | /usr/include/c++/4.8/bits/locale_classes.tcc \ 74 | /usr/include/c++/4.8/streambuf /usr/include/c++/4.8/bits/streambuf.tcc \ 75 | /usr/include/c++/4.8/bits/basic_ios.h \ 76 | /usr/include/c++/4.8/bits/locale_facets.h /usr/include/c++/4.8/cwctype \ 77 | /usr/include/wctype.h \ 78 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_base.h \ 79 | /usr/include/c++/4.8/bits/streambuf_iterator.h \ 80 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_inline.h \ 81 | /usr/include/c++/4.8/bits/locale_facets.tcc \ 82 | /usr/include/c++/4.8/bits/basic_ios.tcc \ 83 | /usr/include/c++/4.8/bits/ostream.tcc /usr/include/c++/4.8/istream \ 84 | /usr/include/c++/4.8/bits/istream.tcc /usr/include/c++/4.8/vector \ 85 | /usr/include/c++/4.8/bits/stl_construct.h \ 86 | /usr/include/c++/4.8/ext/alloc_traits.h \ 87 | /usr/include/c++/4.8/bits/stl_uninitialized.h \ 88 | /usr/include/c++/4.8/bits/stl_vector.h \ 89 | /usr/include/c++/4.8/bits/stl_bvector.h \ 90 | /usr/include/c++/4.8/bits/vector.tcc common.h 91 | 92 | /usr/include/stdc-predef.h: 93 | 94 | /usr/include/stdlib.h: 95 | 96 | /usr/include/features.h: 97 | 98 | /usr/include/i386-linux-gnu/sys/cdefs.h: 99 | 100 | /usr/include/i386-linux-gnu/bits/wordsize.h: 101 | 102 | /usr/include/i386-linux-gnu/gnu/stubs.h: 103 | 104 | /usr/include/i386-linux-gnu/gnu/stubs-32.h: 105 | 106 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stddef.h: 107 | 108 | /usr/include/i386-linux-gnu/bits/waitflags.h: 109 | 110 | /usr/include/i386-linux-gnu/bits/waitstatus.h: 111 | 112 | /usr/include/endian.h: 113 | 114 | /usr/include/i386-linux-gnu/bits/endian.h: 115 | 116 | /usr/include/i386-linux-gnu/bits/byteswap.h: 117 | 118 | /usr/include/i386-linux-gnu/bits/types.h: 119 | 120 | /usr/include/i386-linux-gnu/bits/typesizes.h: 121 | 122 | /usr/include/i386-linux-gnu/bits/byteswap-16.h: 123 | 124 | /usr/include/xlocale.h: 125 | 126 | /usr/include/i386-linux-gnu/sys/types.h: 127 | 128 | /usr/include/time.h: 129 | 130 | /usr/include/i386-linux-gnu/sys/select.h: 131 | 132 | /usr/include/i386-linux-gnu/bits/select.h: 133 | 134 | /usr/include/i386-linux-gnu/bits/sigset.h: 135 | 136 | /usr/include/i386-linux-gnu/bits/time.h: 137 | 138 | /usr/include/i386-linux-gnu/sys/sysmacros.h: 139 | 140 | /usr/include/i386-linux-gnu/bits/pthreadtypes.h: 141 | 142 | /usr/include/alloca.h: 143 | 144 | /usr/include/i386-linux-gnu/bits/stdlib-float.h: 145 | 146 | /usr/include/stdio.h: 147 | 148 | /usr/include/libio.h: 149 | 150 | /usr/include/_G_config.h: 151 | 152 | /usr/include/wchar.h: 153 | 154 | /usr/lib/gcc/i686-linux-gnu/4.8/include/stdarg.h: 155 | 156 | /usr/include/i386-linux-gnu/bits/stdio_lim.h: 157 | 158 | /usr/include/i386-linux-gnu/bits/sys_errlist.h: 159 | 160 | /usr/include/c++/4.8/iostream: 161 | 162 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++config.h: 163 | 164 | /usr/include/i386-linux-gnu/c++/4.8/bits/os_defines.h: 165 | 166 | /usr/include/i386-linux-gnu/c++/4.8/bits/cpu_defines.h: 167 | 168 | /usr/include/c++/4.8/ostream: 169 | 170 | /usr/include/c++/4.8/ios: 171 | 172 | /usr/include/c++/4.8/iosfwd: 173 | 174 | /usr/include/c++/4.8/bits/stringfwd.h: 175 | 176 | /usr/include/c++/4.8/bits/memoryfwd.h: 177 | 178 | /usr/include/c++/4.8/bits/postypes.h: 179 | 180 | /usr/include/c++/4.8/cwchar: 181 | 182 | /usr/include/i386-linux-gnu/bits/wchar.h: 183 | 184 | /usr/include/c++/4.8/exception: 185 | 186 | /usr/include/c++/4.8/bits/atomic_lockfree_defines.h: 187 | 188 | /usr/include/c++/4.8/bits/char_traits.h: 189 | 190 | /usr/include/c++/4.8/bits/stl_algobase.h: 191 | 192 | /usr/include/c++/4.8/bits/functexcept.h: 193 | 194 | /usr/include/c++/4.8/bits/exception_defines.h: 195 | 196 | /usr/include/c++/4.8/bits/cpp_type_traits.h: 197 | 198 | /usr/include/c++/4.8/ext/type_traits.h: 199 | 200 | /usr/include/c++/4.8/ext/numeric_traits.h: 201 | 202 | /usr/include/c++/4.8/bits/stl_pair.h: 203 | 204 | /usr/include/c++/4.8/bits/move.h: 205 | 206 | /usr/include/c++/4.8/bits/concept_check.h: 207 | 208 | /usr/include/c++/4.8/bits/stl_iterator_base_types.h: 209 | 210 | /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h: 211 | 212 | /usr/include/c++/4.8/debug/debug.h: 213 | 214 | /usr/include/c++/4.8/bits/stl_iterator.h: 215 | 216 | /usr/include/c++/4.8/bits/localefwd.h: 217 | 218 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++locale.h: 219 | 220 | /usr/include/c++/4.8/clocale: 221 | 222 | /usr/include/locale.h: 223 | 224 | /usr/include/i386-linux-gnu/bits/locale.h: 225 | 226 | /usr/include/c++/4.8/cctype: 227 | 228 | /usr/include/ctype.h: 229 | 230 | /usr/include/c++/4.8/bits/ios_base.h: 231 | 232 | /usr/include/c++/4.8/ext/atomicity.h: 233 | 234 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr.h: 235 | 236 | /usr/include/i386-linux-gnu/c++/4.8/bits/gthr-default.h: 237 | 238 | /usr/include/pthread.h: 239 | 240 | /usr/include/sched.h: 241 | 242 | /usr/include/i386-linux-gnu/bits/sched.h: 243 | 244 | /usr/include/i386-linux-gnu/bits/timex.h: 245 | 246 | /usr/include/i386-linux-gnu/bits/setjmp.h: 247 | 248 | /usr/include/i386-linux-gnu/c++/4.8/bits/atomic_word.h: 249 | 250 | /usr/include/c++/4.8/bits/locale_classes.h: 251 | 252 | /usr/include/c++/4.8/string: 253 | 254 | /usr/include/c++/4.8/bits/allocator.h: 255 | 256 | /usr/include/i386-linux-gnu/c++/4.8/bits/c++allocator.h: 257 | 258 | /usr/include/c++/4.8/ext/new_allocator.h: 259 | 260 | /usr/include/c++/4.8/new: 261 | 262 | /usr/include/c++/4.8/bits/ostream_insert.h: 263 | 264 | /usr/include/c++/4.8/bits/cxxabi_forced.h: 265 | 266 | /usr/include/c++/4.8/bits/stl_function.h: 267 | 268 | /usr/include/c++/4.8/backward/binders.h: 269 | 270 | /usr/include/c++/4.8/bits/range_access.h: 271 | 272 | /usr/include/c++/4.8/bits/basic_string.h: 273 | 274 | /usr/include/c++/4.8/bits/basic_string.tcc: 275 | 276 | /usr/include/c++/4.8/bits/locale_classes.tcc: 277 | 278 | /usr/include/c++/4.8/streambuf: 279 | 280 | /usr/include/c++/4.8/bits/streambuf.tcc: 281 | 282 | /usr/include/c++/4.8/bits/basic_ios.h: 283 | 284 | /usr/include/c++/4.8/bits/locale_facets.h: 285 | 286 | /usr/include/c++/4.8/cwctype: 287 | 288 | /usr/include/wctype.h: 289 | 290 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_base.h: 291 | 292 | /usr/include/c++/4.8/bits/streambuf_iterator.h: 293 | 294 | /usr/include/i386-linux-gnu/c++/4.8/bits/ctype_inline.h: 295 | 296 | /usr/include/c++/4.8/bits/locale_facets.tcc: 297 | 298 | /usr/include/c++/4.8/bits/basic_ios.tcc: 299 | 300 | /usr/include/c++/4.8/bits/ostream.tcc: 301 | 302 | /usr/include/c++/4.8/istream: 303 | 304 | /usr/include/c++/4.8/bits/istream.tcc: 305 | 306 | /usr/include/c++/4.8/vector: 307 | 308 | /usr/include/c++/4.8/bits/stl_construct.h: 309 | 310 | /usr/include/c++/4.8/ext/alloc_traits.h: 311 | 312 | /usr/include/c++/4.8/bits/stl_uninitialized.h: 313 | 314 | /usr/include/c++/4.8/bits/stl_vector.h: 315 | 316 | /usr/include/c++/4.8/bits/stl_bvector.h: 317 | 318 | /usr/include/c++/4.8/bits/vector.tcc: 319 | 320 | common.h: 321 | -------------------------------------------------------------------------------- /src/map-index/map_index.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * impletation of build grid index of road network for map matching 3 | * 4 | * @date: 2014-12-21 5 | * @author: lifulong 6 | **/ 7 | 8 | #include 9 | 10 | #include "common.h" 11 | #include "map_index.h" 12 | 13 | MapIndex::MapIndex(string nodes_file, string edges_file, string geos_file, string segs_file, 14 | string grid_info, string grid_file, string logfile) 15 | { 16 | //FIXME:init init_mode value by config genSeg, genGrid, loadGrid. 17 | string init_mode = "loadGrid"; 18 | 19 | logger = new Logger(logfile); 20 | logger->Info("Init MapIndex..."); 21 | 22 | this->initMapIndex(); 23 | 24 | //FIXME: check valid. 25 | //regenerate segs and grid file 26 | if(init_mode == "genSeg" && nodes_file != "" && edges_file != "" && geos_file != "") { 27 | 28 | logger->Info("Loading vnode..."); 29 | this->loadNodes(nodes_file); 30 | logger->Info("Loading edge..."); 31 | this->loadEdges(edges_file); 32 | logger->Info("Loading geos..."); 33 | this->loadGeos(geos_file); 34 | logger->Info("Gening segs..."); 35 | this->genSegs(); 36 | this->preprocessGridInfo("round"); 37 | this->initGenGrid(); 38 | logger->Info("Gening grid..."); 39 | this->genGrid(segs_file); 40 | } else if(init_mode == "genGrid" && segs_file != "") { 41 | 42 | logger->Info("Loading segs..."); 43 | this->loadSegs(segs_file); 44 | this->preprocessGridInfo("round"); 45 | this->initGenGrid(); 46 | logger->Info("Gening grid..."); 47 | this->genGrid(segs_file); 48 | logger->Info("Dumping grid..."); 49 | this->dumpGrid("grid.txt"); 50 | } else if(init_mode == "loadGrid" && segs_file != "" && grid_info != "" && grid_file != "") { 51 | 52 | logger->Info("Loading segs..."); 53 | this->loadSegs(segs_file); 54 | logger->Info("Loading Grid..."); 55 | this->loadGridInfo(grid_info); 56 | this->dumpGridInfo(); 57 | this->initGrid(); 58 | this->loadGridData(grid_file); 59 | } else { 60 | 61 | this->_errno = Error::ERR_PARA; 62 | this->errMsg = "parameter error while init map index..."; 63 | return; 64 | } 65 | 66 | this->_errno = Error::ERR_OK; 67 | logger->Info("Init MapIndex Over..."); 68 | } 69 | 70 | int MapIndex::getErrno() 71 | { 72 | return this->_errno; 73 | } 74 | 75 | string MapIndex::getErrMsg() 76 | { 77 | return this->errMsg; 78 | } 79 | 80 | void MapIndex::initMapIndex() 81 | { 82 | //FIXME:use config file to decide which branch running to ... 83 | if("loadGrid" != init_mode) { 84 | 85 | map_start_lng = START_LNG; 86 | map_start_lat = START_LAT; 87 | map_end_lng = END_LNG; 88 | map_end_lat = END_LAT; 89 | map_lng_gap = LNG_GAP; 90 | map_lat_gap = LAT_GAP; 91 | map_lat_num = map_lng_num = 0; 92 | } else { 93 | 94 | map_start_lng = 0; 95 | map_start_lat = 0; 96 | map_end_lng = 0; 97 | map_end_lat = 0; 98 | map_lng_gap = 0; 99 | map_lat_gap = 0; 100 | map_lat_num = map_lng_num = 0; 101 | } 102 | 103 | this->inodes.clear(); 104 | this->iedges.clear(); 105 | this->igeos.clear(); 106 | this->segs.clear(); 107 | } 108 | 109 | void MapIndex::loadNodes(string node_file) 110 | { 111 | char buffer[LINE_BUFFER_LEN]; 112 | vector res; 113 | ifstream infile; 114 | 115 | infile.open(node_file.c_str()); 116 | 117 | if(!infile) { 118 | //Log:: 119 | return ; 120 | } 121 | 122 | while(infile.getline(buffer, LINE_BUFFER_LEN)) 123 | { 124 | res = SplitBySep(buffer, "\t"); 125 | if(res.size() != 3) 126 | { 127 | cout << "Parse " + node_file + " error, line seg is not 3." << endl; 128 | continue; 129 | } 130 | cout << res[0] << ":" << res[1] << ":" << res[2] << endl; 131 | struct inode inode; 132 | inode.node_index = atoi(res[0].c_str()); 133 | inode.point.lat = atof(res[1].c_str()); 134 | inode.point.lng = atof(res[2].c_str()); 135 | this->inodes.push_back(inode); 136 | } 137 | 138 | infile.close(); 139 | 140 | return ; 141 | } 142 | 143 | void MapIndex::loadEdges(string edge_file) 144 | { 145 | char buffer[LINE_BUFFER_LEN]; 146 | vector res; 147 | ifstream infile; 148 | 149 | infile.open(edge_file.c_str()); 150 | 151 | if(!infile) { 152 | //Log:: 153 | return ; 154 | } 155 | 156 | while(infile.getline(buffer, LINE_BUFFER_LEN)) 157 | { 158 | res = SplitBySep(buffer, "\t"); 159 | if(res.size() != 3) 160 | { 161 | cout << "Parse " + edge_file + " error, line seg is not 3." << endl; 162 | continue; 163 | } 164 | struct iedge iedge; 165 | iedge.edge_index = atoi(res[0].c_str()); 166 | iedge.start_inode_index = atoi(res[1].c_str()); 167 | iedge.end_inode_index = atoi(res[2].c_str()); 168 | this->iedges.push_back(iedge); 169 | } 170 | 171 | infile.close(); 172 | 173 | return ; 174 | } 175 | 176 | void MapIndex::loadGeos(string geo_file) 177 | { 178 | int i = 0; 179 | char buffer[LINE_BUFFER_LEN]; 180 | vector res; 181 | ifstream infile; 182 | 183 | infile.open(geo_file.c_str()); 184 | 185 | if(!infile) { 186 | //Log:: 187 | return ; 188 | } 189 | 190 | while(infile.getline(buffer, LINE_BUFFER_LEN)) 191 | { 192 | res = SplitBySep(buffer, "\t"); 193 | if(res.size() < 5) 194 | { 195 | cout << "Parse " + geo_file + " error, line seg is less than 5." << endl; 196 | continue; 197 | } 198 | struct igeo igeo; 199 | igeo.points.clear(); 200 | for(vector::iterator iter = res.begin(); iter != res.end(); iter++, i++) 201 | { 202 | if(0 == i) 203 | igeo.edge_index = atoi((*iter).c_str()); 204 | else 205 | { 206 | struct point point; 207 | point.lat = atof((*iter).c_str()); 208 | iter++; 209 | point.lat = atof((*iter).c_str()); 210 | igeo.points.push_back(point); 211 | } 212 | } 213 | this->igeos.push_back(igeo); 214 | } 215 | 216 | infile.close(); 217 | 218 | return ; 219 | } 220 | 221 | 222 | void MapIndex::loadSegs(string segs_file) 223 | { 224 | ifstream infile; 225 | char buffer[LINE_BUFFER_LEN]; 226 | struct seg seg; 227 | vector seg_data; 228 | 229 | debug_msg("[INFO]loading segs... ...\n"); 230 | infile.open(segs_file.c_str(), ifstream::in); 231 | 232 | this->segs.clear(); 233 | this->segs.push_back(seg); //FIXME:First seg is padding, invalid. 234 | 235 | while(!infile.getline(buffer, LINE_BUFFER_LEN).eof()) 236 | { 237 | seg_data = SplitBySep(buffer, "\t"); 238 | if(seg_data.size() != 6) 239 | continue; 240 | seg.seg_id = atoi(seg_data[0].c_str()); 241 | seg.start_lng = atof(seg_data[1].c_str()); 242 | seg.start_lat = atof(seg_data[2].c_str()); 243 | seg.end_lng = atof(seg_data[3].c_str()); 244 | seg.end_lat = atof(seg_data[4].c_str()); 245 | seg.edge_id = atoi(seg_data[5].c_str()); 246 | this->segs.push_back(seg); 247 | } 248 | 249 | infile.close(); 250 | debug_msg("[INFO]loading segs ok... ...\n"); 251 | } 252 | 253 | void MapIndex::setValue(string key, string value) 254 | { 255 | if(0 == strcmp(key.c_str(), "start_lng")) { 256 | 257 | this->map_start_lng = atof(value.c_str()); 258 | } else if (0 == strcmp(key.c_str(), "start_lat")) { 259 | 260 | this->map_start_lat = atof(value.c_str()); 261 | } else if (0 == strcmp(key.c_str(), "end_lng")) { 262 | 263 | this->map_end_lng = atof(value.c_str()); 264 | } else if (0 == strcmp(key.c_str(), "end_lat")) { 265 | 266 | this->map_end_lat = atof(value.c_str()); 267 | } else if (0 == strcmp(key.c_str(), "lng_gap")) { 268 | 269 | this->map_lng_gap = atof(value.c_str()); 270 | } else if (0 == strcmp(key.c_str(), "lat_gap")) { 271 | 272 | this->map_lat_gap = atof(value.c_str()); 273 | } else { 274 | 275 | debug_msg("unkown key value detect: key=%s, value=%s.\n", key.c_str(), value.c_str()); 276 | } 277 | } 278 | 279 | void MapIndex::loadGridInfo(string grid_info) 280 | { 281 | FILE *fp; 282 | char buffer[LINE_BUFFER_LEN]; 283 | vector key_value; 284 | string key, value; 285 | 286 | fp = fopen(grid_info.c_str(), "r"); 287 | 288 | while(fgets(buffer, LINE_BUFFER_LEN, fp)) 289 | { 290 | key_value = SplitBySep(buffer, ":"); 291 | if(key_value.size() != 2) 292 | { 293 | debug_msg("load grid info error.\n"); 294 | continue; 295 | } 296 | key = key_value[0]; 297 | value = key_value[1]; 298 | this->setValue(key, value); 299 | } 300 | 301 | fclose(fp); 302 | 303 | //FIXME: start_lng end_lng ... check 304 | this->map_lng_num = fabs(map_start_lng - map_end_lng) / map_lng_gap + 1; 305 | this->map_lat_num = fabs(map_start_lat - map_end_lat) / map_lat_gap + 1; 306 | } 307 | 308 | void MapIndex::dumpGridInfo() 309 | { 310 | cout << "dumpGridInfo:" << endl; 311 | cout << "start_lng:" << map_start_lng << endl; 312 | cout << "start_lat:" << map_start_lat << endl; 313 | cout << "end_lng:" << map_end_lng << endl; 314 | cout << "end_lat:" << map_end_lat << endl; 315 | cout << "lng_gap:" << map_lng_gap << endl; 316 | cout << "lat_gap:" << map_lat_gap << endl; 317 | cout << endl; 318 | } 319 | 320 | void MapIndex::loadGridData(string grid_file) 321 | { 322 | int i, j, pos, len, seg_id, segs_size; 323 | double start_lng, start_lat, end_lng, end_lat; 324 | FILE *fp; 325 | char buffer[LINE_BUFFER_LEN]; 326 | vector grid_data; 327 | struct seg seg; 328 | 329 | debug_msg("[INFO]loading grid ... ...\n"); 330 | segs_size = this->segs.size(); 331 | fp = fopen(grid_file.c_str(), "r"); 332 | 333 | memset(buffer, 0, LINE_BUFFER_LEN); 334 | while(fgets(buffer, LINE_BUFFER_LEN, fp)) 335 | { 336 | grid_data.clear(); 337 | EchoRunning(); 338 | grid_data = SplitBySep(buffer, "\t"); 339 | if(grid_data.size() < 6) { 340 | debug_msg("grid data size error, %u.\n", grid_data.size()); 341 | debug_msg("grid data size error, %s.\n", buffer); 342 | continue; 343 | } 344 | i = atoi(grid_data[0].c_str()); 345 | j = atoi(grid_data[1].c_str()); 346 | start_lng = atof(grid_data[2].c_str()); 347 | start_lat = atof(grid_data[3].c_str()); 348 | end_lng = atof(grid_data[4].c_str()); 349 | end_lat = atof(grid_data[5].c_str()); 350 | 351 | if(i < 0 || i > this->map_lng_num) { 352 | debug_msg("grid lng index error, %d.\n", i); 353 | continue; 354 | } 355 | 356 | if(j < 0 || j > this->map_lat_num) { 357 | debug_msg("grid lat index error, %d.\n", j); 358 | continue; 359 | } 360 | 361 | this->grid[i][j].start_lng = start_lng; 362 | this->grid[i][j].start_lat = start_lat; 363 | this->grid[i][j].end_lng = end_lng; 364 | this->grid[i][j].end_lat = end_lat; 365 | 366 | pos = 6; 367 | len = grid_data.size(); 368 | while(pos < len) 369 | { 370 | seg_id = atoi(grid_data[pos].c_str()); 371 | if(seg_id <= 0 || seg_id > segs_size) { 372 | debug_msg("seg_id invlid, seg_id=%d,segs_size=%d.\n", seg_id, segs_size); 373 | pos++; 374 | continue; 375 | } 376 | seg = this->segs[seg_id - 1]; 377 | this->grid[i][j].node_segs.push_back(seg); 378 | pos++; 379 | } 380 | } 381 | 382 | fclose(fp); 383 | debug_msg("[INFO]loading grid ok ... ...\n"); 384 | } 385 | 386 | void MapIndex::initGrid() 387 | { 388 | int i, j; 389 | 390 | grid = new grid_node*[map_lng_num]; 391 | for(i = 0; i < map_lng_num; i++) 392 | { 393 | grid[i] = new grid_node[map_lat_num]; 394 | } 395 | for(i = 0; i < map_lng_num; i++) 396 | { 397 | for(j = 0; j < map_lat_num; j++) 398 | { 399 | grid[i][j].node_segs.clear(); 400 | } 401 | } 402 | } 403 | 404 | -------------------------------------------------------------------------------- /src/map-index/gen_grid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "common.h" 6 | #include "map_index.h" 7 | 8 | #define READ_BUFFER_LINE 4096 9 | 10 | double MapIndex::round(double val, double mod, char type) 11 | { 12 | #define MULTI 100000 13 | int i_val, i_mod; 14 | int tmp; 15 | 16 | i_val = val*MULTI; 17 | i_mod = mod*MULTI; 18 | 19 | if(0 == type) //up bound 20 | { 21 | tmp = i_val % i_mod; 22 | if(0 != tmp) 23 | i_val = i_val - tmp + i_mod; 24 | val = (double)i_val / MULTI; 25 | } 26 | else if(1 == type) //down bound 27 | { 28 | tmp = i_val % i_mod; 29 | if(0 != tmp) 30 | i_val = i_val - tmp; 31 | val = (double)i_val / MULTI; 32 | } 33 | else 34 | { 35 | return val; 36 | } 37 | 38 | return val; 39 | } 40 | 41 | void MapIndex::preprocessGridInfo(string type) 42 | { 43 | if(0 == strcmp(type.c_str(), "round")) 44 | { 45 | debug_msg("%f\t%f\t%f\t%f\n", map_start_lat, map_end_lat, map_start_lng, map_end_lng); 46 | map_start_lat = this->round(map_start_lat, map_lat_gap, 1); 47 | map_end_lat = this->round(map_end_lat, map_lat_gap, 0); 48 | map_start_lng = this->round(map_start_lng, map_lng_gap, 1); 49 | map_end_lng = this->round(map_end_lng, map_lng_gap, 0); 50 | } 51 | 52 | debug_msg("%f\t%f\t%f\t%f\t%f\t%f\n", map_start_lat, map_end_lat, map_start_lng, map_end_lng, map_lat_gap, map_lng_gap); 53 | map_lat_num = fabs(map_end_lat - map_start_lat) / map_lat_gap + 1; 54 | map_lng_num = fabs(map_end_lng - map_start_lng) / map_lng_gap + 1; 55 | debug_msg("lat_num:%d\tlng_num:%d\n", map_lat_num, map_lng_num); 56 | } 57 | 58 | 59 | void MapIndex::genGrid(string segs_file) 60 | { 61 | FILE *fp; 62 | char buffer[READ_BUFFER_LINE]; 63 | struct seg seg; 64 | vector seg_info; 65 | 66 | if(segs_file == "") 67 | return; 68 | 69 | debug_msg("Start genGrid ... ...\n"); 70 | 71 | seg_info.clear(); 72 | 73 | fp = fopen(segs_file.c_str(), "r"); 74 | while(NULL != fgets(buffer, READ_BUFFER_LINE, fp)) 75 | { 76 | EchoRunning(); 77 | seg_info = SplitBySep(buffer, "\t"); 78 | if(seg_info.size() != 6) 79 | continue; 80 | seg.seg_id = atoi(seg_info[0].c_str()); 81 | seg.start_lng = atof(seg_info[1].c_str()); 82 | seg.start_lat = atof(seg_info[2].c_str()); 83 | seg.end_lng = atof(seg_info[3].c_str()); 84 | seg.end_lat = atof(seg_info[4].c_str()); 85 | seg.edge_id = atoi(seg_info[5].c_str()); 86 | this->updateGrids(seg); 87 | } 88 | fclose(fp); 89 | debug_msg("genGrid Finish.\n"); 90 | } 91 | 92 | void MapIndex::dumpGrid(string dump_file="") 93 | { 94 | int i, j; 95 | FILE *fp; 96 | 97 | if("" == dump_file) 98 | fp = stdout; 99 | else 100 | { 101 | fp = fopen(dump_file.c_str(), "w"); 102 | } 103 | 104 | debug_msg("Start dumpGrid ... ...\n"); 105 | 106 | for(i = 0; i < map_lng_num; i++) 107 | { 108 | for(j = 0; j < map_lat_num; j++) 109 | { 110 | //format:i j start_lng start_lat end_lng end_lat seg_id1 ... seg_idn 111 | fprintf(fp, "%d\t%d\t%f\t%f\t%f\t%f", i, j, grid[i][j].start_lng, grid[i][j].start_lat, 112 | grid[i][j].end_lng, grid[i][j].end_lat); 113 | for(vector::iterator iter = grid[i][j].node_segs.begin(); iter != grid[i][j].node_segs.end(); iter++) 114 | { 115 | fprintf(fp, "\t%d", iter->seg_id); 116 | } 117 | fprintf(fp, "\n"); 118 | } 119 | } 120 | 121 | if("" != dump_file) 122 | { 123 | fclose(fp); 124 | } 125 | 126 | debug_msg("dumpGrid Finish.\n"); 127 | } 128 | 129 | 130 | //private functions 131 | 132 | 133 | void MapIndex::initGenGrid() 134 | { 135 | int i, j; 136 | 137 | grid = new grid_node*[map_lng_num]; 138 | for(i = 0; i < map_lng_num; i++) 139 | { 140 | grid[i] = new grid_node[map_lat_num]; 141 | } 142 | 143 | /** 144 | * first dimension is horizontal, lng 145 | * second dimension is vertical, lat 146 | */ 147 | for(i = 0; i < map_lng_num; i++) 148 | for(j = 0; j < map_lat_num; j++) { 149 | grid[i][j].start_lng = this->map_start_lng + i*this->map_lng_gap; 150 | grid[i][j].end_lng = grid[i][j].start_lng + this->map_lng_gap; 151 | grid[i][j].start_lat = this->map_start_lat + j*this->map_lat_gap; 152 | grid[i][j].end_lat = grid[i][j].start_lat + this->map_lat_gap; 153 | grid[i][j].node_segs.clear(); 154 | } 155 | } 156 | 157 | struct grid_index MapIndex::getGridIndexByPoint(double lng, double lat) 158 | { 159 | int i=0, j=0; 160 | 161 | struct grid_index index = {-1, -1}; 162 | 163 | if(lng < this->map_start_lng || lng > this->map_end_lng || lat < this->map_start_lat || lat > this->map_end_lat) 164 | return index; 165 | 166 | //i = (lng - this->start_lng) / this->lng_gap + 1; 167 | //j = (lat - this->start_lat) / this->lat_gap + 1; 168 | i = (lng - this->map_start_lng) / this->map_lng_gap; 169 | j = (lat - this->map_start_lat) / this->map_lat_gap; 170 | 171 | if(i >= this->map_lng_num || j >= this->map_lat_num) 172 | { 173 | debug_msg("getGridIndexByPoint: i = %d j = %d.\n", i, j); 174 | i = -1; 175 | j = -1; 176 | } 177 | 178 | if(i < 0 || j < 0) { 179 | debug_msg("getGridIndexByPoint lng: %f,lat: %f.\n", lng, lat); 180 | debug_msg("getGridIndexByPoint start_lng: %f,start_lat: %f.\n", this->map_start_lng, this->map_start_lat); 181 | debug_msg("getGridIndexByPoint: lng_num = %d, lat_num = %d.\n", map_lng_num, map_lat_num); 182 | debug_msg("getGridIndexByPoint: i = %d j = %d.\n", i, j); 183 | } 184 | 185 | index.i = i; 186 | index.j = j; 187 | 188 | return index; 189 | } 190 | 191 | 192 | void MapIndex::updateGrid(struct grid_index index, struct seg seg) 193 | { 194 | if(index.i < 0 || index.i > map_lng_num || index.j < 0 || index.j > map_lat_num) 195 | { 196 | cout << "updateGrid:index valid: i = " << index.i << " j = " << index.j << endl; 197 | return; 198 | } 199 | this->grid[index.i][index.j].node_segs.push_back(seg); 200 | //printf("i:%d\tj:%d\tsize:%d\n", index.i, index.j, grid[index.i][index.j].node_segs.size()); 201 | } 202 | 203 | void MapIndex::updateHorizontalGrids(double k, double start_lng, double start_lat, 204 | double end_lng, double end_lat, struct seg seg) 205 | { 206 | double curr_lng, curr_lat; 207 | struct grid_index index={0, 0}, last_index={0, 0}; 208 | 209 | curr_lng = start_lng; 210 | curr_lat = start_lat; 211 | 212 | while(curr_lng <= end_lng) 213 | { 214 | index = this->getGridIndexByPoint(curr_lng, curr_lat); 215 | last_index = index; 216 | this->updateGrid(index, seg); 217 | curr_lng = curr_lng + map_lng_gap; 218 | } 219 | 220 | if(curr_lng > end_lng) 221 | { 222 | curr_lng = end_lng; 223 | index = this->getGridIndexByPoint(curr_lng, curr_lat); 224 | if(last_index.i != index.i || last_index.j != index.j) 225 | this->updateGrid(index, seg); 226 | } 227 | 228 | } 229 | 230 | void MapIndex::updateVerticalGrids(double k, double start_lng, double start_lat, 231 | double end_lng, double end_lat, struct seg seg) 232 | { 233 | double curr_lng, curr_lat; 234 | struct grid_index index={0, 0}, last_index={0, 0}; 235 | 236 | curr_lat = start_lat; 237 | curr_lng = start_lng; 238 | 239 | while(curr_lat <= end_lat) 240 | { 241 | index = this->getGridIndexByPoint(curr_lng, curr_lat); 242 | last_index = index; 243 | this->updateGrid(index, seg); 244 | curr_lat = curr_lat + map_lat_gap; 245 | } 246 | 247 | if(curr_lat > end_lat) 248 | { 249 | curr_lat = end_lat; 250 | index = this->getGridIndexByPoint(curr_lng, curr_lat); 251 | if(last_index.i != index.i || last_index.j != index.j) 252 | this->updateGrid(index, seg); 253 | } 254 | } 255 | 256 | void MapIndex::updateHorizOrientGrids(double k, double start_lng, double start_lat, 257 | double end_lng, double end_lat, struct seg seg) 258 | { 259 | double curr_lng, curr_lat; 260 | struct grid_index index={0, 0}, last_index={0, 0}; 261 | 262 | curr_lng = start_lng; 263 | curr_lat = start_lat; 264 | 265 | while(curr_lng <= end_lng) 266 | { 267 | index = this->getGridIndexByPoint(curr_lng, curr_lat); 268 | last_index = index; 269 | this->updateGrid(index, seg); 270 | curr_lng = curr_lng + map_lng_gap; 271 | curr_lat = k * (curr_lng - start_lng) + start_lat; 272 | } 273 | 274 | if(curr_lng > end_lng) 275 | { 276 | curr_lng = end_lng; 277 | curr_lat = k * (curr_lng - start_lng) + start_lat; 278 | index = this->getGridIndexByPoint(curr_lng, curr_lat); 279 | if(last_index.i != index.i || last_index.j != index.j) 280 | this->updateGrid(index, seg); 281 | } 282 | } 283 | 284 | void MapIndex::updateVertOrientGrids(double k, double start_lng, double start_lat, 285 | double end_lng, double end_lat, struct seg seg) 286 | { 287 | double curr_lng, curr_lat; 288 | struct grid_index index={0, 0}, last_index={0, 0}; 289 | 290 | curr_lat = start_lat; 291 | curr_lng = start_lng; 292 | 293 | while(curr_lat <= end_lat) 294 | { 295 | index = this->getGridIndexByPoint(curr_lng, curr_lat); 296 | last_index = index; 297 | this->updateGrid(index, seg); 298 | curr_lat = curr_lat + map_lat_gap; 299 | curr_lng = (curr_lat - start_lat) / k + start_lng; 300 | } 301 | 302 | if(curr_lng > end_lng) 303 | { 304 | curr_lat = end_lat; 305 | curr_lng = (curr_lat - start_lat) / k + start_lng; 306 | index = this->getGridIndexByPoint(curr_lng, curr_lat); 307 | if(last_index.i != index.i || last_index.j != index.j) 308 | this->updateGrid(index, seg); 309 | } 310 | } 311 | 312 | void MapIndex::updateGrids(struct seg seg) 313 | { 314 | double k = 0, abs_k = 0; 315 | double left_lat=0, left_lng=0, right_lat=0, right_lng=0; 316 | double buttom_lat=0, buttom_lng=0, top_lat=0, top_lng=0; 317 | // 1:horizontal 2:vertical 3:horiz_orientation 4:vertical_orientation 318 | int direction = 0; 319 | 320 | if(seg.start_lat == seg.end_lat) { 321 | 322 | k = 0; 323 | direction = 1; 324 | } else if(seg.start_lng == seg.end_lng) { 325 | 326 | k = HUGE_VAL; 327 | direction = 2; 328 | } else { 329 | 330 | k = (seg.start_lng - seg.end_lng)/(seg.start_lat - seg.end_lat); 331 | abs_k = fabs(k); 332 | 333 | if(abs_k <= 1) { 334 | direction = 3; 335 | } else { 336 | direction = 4; 337 | } 338 | } 339 | 340 | if(2 == direction || 4 == direction) { 341 | 342 | if(seg.start_lng <= seg.end_lng) { 343 | 344 | buttom_lng = seg.start_lng; 345 | buttom_lat = seg.start_lat; 346 | top_lng = seg.end_lng; 347 | top_lat = seg.end_lat; 348 | } else { 349 | 350 | buttom_lng = seg.end_lng; 351 | buttom_lat = seg.end_lat; 352 | top_lng = seg.start_lng; 353 | top_lat = seg.start_lat; 354 | } 355 | 356 | } else if(1 == direction || 3 == direction) { 357 | 358 | if(seg.start_lat <= seg.end_lat) { 359 | 360 | left_lng = seg.start_lng; 361 | left_lat = seg.start_lat; 362 | right_lng = seg.end_lng; 363 | right_lat = seg.end_lat; 364 | } else { 365 | 366 | left_lng = seg.end_lng; 367 | left_lat = seg.end_lat; 368 | right_lng = seg.start_lng; 369 | right_lat = seg.start_lat; 370 | } 371 | } 372 | 373 | switch(direction) 374 | { 375 | case 0: 376 | break; 377 | case 1: 378 | updateHorizontalGrids(abs_k, left_lng, left_lat, right_lng, right_lat, seg); 379 | break; 380 | case 2: 381 | updateVerticalGrids(abs_k, buttom_lng, buttom_lat, top_lng, top_lat, seg); 382 | break; 383 | case 3: 384 | updateHorizOrientGrids(abs_k, left_lng, left_lat, right_lng, right_lat, seg); 385 | break; 386 | case 4: 387 | updateVertOrientGrids(abs_k, buttom_lng, buttom_lat, top_lng, top_lat, seg); 388 | break; 389 | default: 390 | break; 391 | } 392 | } 393 | 394 | 395 | --------------------------------------------------------------------------------