예제 #1
0
def get_sbwstops(o_lat, o_lng, d_lat, d_lng, dis):
    #设置最远阈值1000米范围内
    o_dmin = [dis, None]
    d_dmin = [dis, None]
    ominlat, omaxlat, ominlng, omaxlng = get_area(o_lat, o_lng, dis / 1000)
    dminlat, dmaxlat, dminlng, dmaxlng = get_area(d_lat, d_lng, dis / 1000)
    for key in sbwstation:
        [t_lat, t_lng] = sbwstation[key].get_location()
        if t_lat > ominlat and t_lat < omaxlat and t_lng > ominlng and t_lng < omaxlng:
            o_d = get_distance(o_lat, o_lng, sbwstation[key].get_location()[0],
                               sbwstation[key].get_location()[1])
            o_dmin = ([o_d, key] if o_d < o_dmin[0] else o_dmin)
        if t_lat > dminlat and t_lat < dmaxlat and t_lng > dminlng and t_lng < dmaxlng:
            d_d = get_distance(d_lat, d_lng, sbwstation[key].get_location()[0],
                               sbwstation[key].get_location()[1])
            d_dmin = ([d_d, key] if d_d < d_dmin[0] else d_dmin)
    return o_dmin, d_dmin
예제 #2
0
def yyplan0(o_nstops,
            d_nstops,
            o_nlines=[],
            d_nlines=[],
            oclatlng=None,
            dclatlng=None):
    planline = []
    plans = []
    if o_nlines == []:
        o_nlines = get_lines_by_stops(o_nstops)
    if d_nlines == []:
        d_nlines = get_lines_by_stops(d_nstops)
    for i in o_nlines:
        if i in d_nlines:
            planline.append(i)
    if len(planline) > 0:
        for i in planline:
            s = ydline[i].get_stops()
            o_ps = []
            d_ps = []
            mind = 10000
            for j in o_nstops:
                if j in s and j.find('仅下客') == -1:
                    if oclatlng != None:
                        jlatlng = ydstation[j].get_location()
                        d = get_distance(jlatlng[0], jlatlng[1], oclatlng[0],
                                         oclatlng[1])
                        if d < mind:
                            mind = d
                            o_ps = [[j, s[j][0]]]
                        else:
                            continue
                    else:
                        o_ps.append([j, s[j][0]])
            mind = 10000
            for k in d_nstops:
                if k in s:
                    if dclatlng != None:
                        klatlng = ydstation[k].get_location()
                        d = get_distance(klatlng[0], klatlng[1], dclatlng[0],
                                         dclatlng[1])
                        if d < mind:
                            mind = d
                            d_ps = [[k, s[k][0]]]
                        else:
                            continue
                    else:
                        d_ps.append([k, s[k][0]])
            for ops in o_ps:
                for dps in d_ps:
                    if ops[1] < dps[1]:
                        if ydline[i].get_isCircle() == True:
                            num = len(s)
                            n = dps[1] - ops[1]
                            if n <= (num - n):
                                pl = [
                                    ydline[i].get_name(), ydline[i].get_type(),
                                    ydline[i].get_id()
                                ]
                                plans.append([ops, pl, dps])
                        else:
                            pl = [
                                ydline[i].get_name(), ydline[i].get_type(),
                                ydline[i].get_id()
                            ]
                            plans.append([ops, pl, dps])
        if len(plans) > 0:
            return True, plans
        else:
            return False, [o_nlines, d_nlines]
    else:
        return False, [o_nlines, d_nlines]
예제 #3
0
                    location = [lng, lat]
                sline = copy.deepcopy(stopline[name])
                ydstation[name] = Station(id, name, location, sline)
                num += 1

# 站点半径500米内其他站点定义为周边站点【0】,获取周边站点集合并添加到对应站点类中
nearby_stops = {}
for i in stop:
    nearby_stops[i] = []
    [c_lat, c_lng] = ydstation[i].get_location()
    minlat, maxlat, minlng, maxlng = get_area(c_lat, c_lng, 0.5)
    n_stops = {}
    for j in stop:
        [t_lat, t_lng] = ydstation[j].get_location()
        if t_lat > minlat and t_lat < maxlat and t_lng > minlng and t_lng < maxlng:
            n_stops[j] = get_distance(c_lat, c_lng, t_lat, t_lng)
    n_stops.pop(i)
    nearby_stops[i] = copy.deepcopy(n_stops)
for key in ydstation:
    stopsdict = {0: copy.deepcopy(nearby_stops[key])}
    ydstation[key].set_stops(stopsdict)

# DICT SBWSTATION
# 将获取到的地铁json站点数据整理成站点类的形式,存在key为地铁站点id,value为站点类的字典中
sbwstation = {}
for i in range(len(sbw_sdata)):
    id = sbw_sdata[i]['id']
    name = sbw_sdata[i]['name']
    lat = float(sbw_sdata[i]['lat_bd'])
    lng = float(sbw_sdata[i]['long_bd'])
    location = [lat, lng]