def match_coor(x): res = [] # with Network(SparkFiles.get("my_connected_path4.shp")) as network: # graph = NetworkGraph(netwk.value) # model = STMATCH(netwk.value, graph) network = Network("./data/my_connected_path4.shp") graph = NetworkGraph(network) model = STMATCH(network, graph) config = STMATCHConfig() config.k = 4 config.gps_error = 0.5 # config.radius = 0.4 config.radius = 100 config.vmax = 60 config.factor = 1.5 for traj in x: tmp = [] for item in traj[1]: y,x = float(item[4]), float(item[3]) if x>180 or x<-180 or y>80 or y<-80: continue trans_coor = utm.from_latlon(y,x, force_zone_number=49) tmp.append(str(trans_coor[0])+" "+str(trans_coor[1])) if len(tmp) == 0: continue wkt = "LINESTRING("+",".join(tmp)+")" result = model.match_wkt(wkt,config) opath = list(result.opath) x2 = list(zip(traj[1],opath)) res.append(x2) return iter(res)
def __init__(self, config_json_file): if not os.path.exists(config_json_file): raise Exception("File for {} is missing.".format(config_json_file)) config = MapMatcherConfig(config_json_file) self.network = Network(config.network_file, config.network_id, config.network_source, config.network_target) self.graph = NetworkGraph(self.network) if config.model_tag == "stmatch": self.model = STMATCH(self.network, self.graph) self.mm_config = config.mm_config elif (config.model_tag == "fmm"): self.ubodt = UBODT.read_ubodt_file(config.ubodt_file) self.model = FastMapMatch(self.network, self.graph, self.ubodt) self.mm_config = config.mm_config else: raise Exception("Model not found for {} ".format(data["model"]))
from fmm import Network, NetworkGraph, STMATCH, STMATCHConfig network = Network("../data/edges.shp") graph = NetworkGraph(network) print graph.get_num_vertices() model = STMATCH(network, graph) wkt = "LINESTRING(0.200812146892656 2.14088983050848,1.44262005649717 2.14879943502825,3.06408898305084 2.16066384180791,3.06408898305084 2.7103813559322,3.70872175141242 2.97930790960452,4.11606638418078 2.62337570621469)" config = STMATCHConfig() config.k = 4 config.gps_error = 0.5 config.radius = 0.4 config.vmax = 30 config.factor = 1.5 result = model.match_wkt(wkt, config) print type(result) print "Opath ", list(result.opath) print "Cpath ", list(result.cpath) print "WKT ", result.mgeom.export_wkt()
print 'generate and read the ubodt file' ubodt_gen = UBODTGenAlgorithm(network, graph) status = ubodt_gen.generate_ubodt("../../data/Porto/ubodt.txt", 0.03, binary=False, use_omp=True) print status ubodt = UBODT.read_ubodt_csv("../../data/Porto/ubodt.txt") fmm_model = FastMapMatch(network, graph, ubodt) k = 16 radius = 0.005 gps_error = 0.0005 fmm_config = FastMapMatchConfig(k, radius, gps_error) stmatch_model = STMATCH(network, graph) k = 8 gps_error = 0.0005 radius = 0.005 vmax = 0.0003 factor = 1.5 stmatch_config = STMATCHConfig(k, radius, gps_error, vmax, factor) train1000 = [] with open("../../data/train-1000.csv", "r") as csvfile: reader = csv.reader(csvfile) for line in reader: train1000.append(line[8]) #POLYLINES results = [] for t_number in range(1, 1001):