Example #1
0
def address_to_inter(startname, endname):
	"""
	start_inter
	end_inter
	start_dist
	end_dist
	end_side
	"""
	starti, startd, starts, slat, slon = getaddress(startname)
	endi, endd, ends, elat, elon = getaddress(endname)
	if starti == None or endi == None:
		return None, None, None, None, None, None
	startedge = gr[starti[0]][starti[1]]
	endedge = gr[endi[0]][endi[1]]
	d = None
	for i in range(2):
		for j in range(2):
			si = starti[i]
			ei = endi[j]
			sd = streetdist(i, startedge, startd)
			ed = streetdist(j, endedge, endd)
			es = flip(ends) if j == 1 else ends
			si_latlon = (gr.node[si]["lat"], gr.node[si]["lon"])
			ei_latlon = (gr.node[ei]["lat"], gr.node[ei]["lon"])
			hav = util.hav(si_latlon, ei_latlon)
			# direction from initial address to initial intersection
			si_lon = gr.node[si]['lon']
			si_lat = gr.node[si]['lat']
			start_direction = get_dir_helper(si_lat - slat, si_lon - slon)
			if d == None or hav < d[0]:
				d = (hav, si, ei, sd, ed, es, start_direction)
	return d[1:]
Example #2
0
def centerline_length(shape):
    """Calculate the length of a pyshp line in kilometers using the Haversine formula."""
    if shape.shapeType != 3:
        raise Exception("Can't calculate length of non-line shape: " + str(shape.shapeType))
    p = shape.points
    l = 0
    for i in range(len(p) - 1):
        p0 = p[i]
        p1 = p[i + 1]
        l += util.hav(p0, p1)
    return l
Example #3
0
def centerline_length(shape):
    """Calculate the length of a pyshp line in kilometers using the Haversine formula."""
    if shape.shapeType != 3:
        raise Exception("Can't calculate length of non-line shape: " +
                        str(shape.shapeType))
    p = shape.points
    l = 0
    for i in range(len(p) - 1):
        p0 = p[i]
        p1 = p[i + 1]
        l += util.hav(p0, p1)
    return l