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)
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()
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): gps_points = eval(train1000[t_number]) wkt = 'LINESTRING(' + ','.join( [' '.join([str(j) for j in i]) for i in gps_points]) + ')' result = fmm_model.match_wkt(wkt, fmm_config) if list(result.cpath) == []: print('stmatching') result = stmatch_model.match_wkt(wkt, stmatch_config) candidates = list(result.candidates) results.append( dict(cpath=str(list(result.cpath)), mgeom=result.mgeom.export_wkt(), opath=str(list(result.opath)), offset=str([c.offset for c in candidates]), length=str([c.length for c in candidates]), spdist=str([c.spdist for c in candidates]))) # cpath, opath, offset, length, spdist, mgeom with open("../../data/match_result.csv", "w") as csvfile: writer = csv.writer(csvfile) writer.writerow( ["t_number", "cpath", "opath", "offset", "length", "spdist", "mgeom"])