示例#1
0
    def filter(self, csv_in, csv_out, max_dist):
        print('filtering graph for maximum distance: %s' % max_dist)
        g = graph.read_graph(csv_in)

        for edge in g:
            loc1 = self.locmap.coords[edge[0]]
            loc2 = self.locmap.coords[edge[1]]
            dist = geo.distance(loc1, loc2)
            if dist > max_dist:
                g[edge] = 0.

        graph.write_graph(g, csv_out)
示例#2
0
    def crop(self, csv_in, csv_out, min_lat, min_lng, max_lat, max_lng):
        print('cropping graph for rectangle: %s %s %s %s' %
              (min_lat, min_lng, max_lat, max_lng))
        g = graph.read_graph(csv_in)

        new_g = {}
        for edge in g:
            loc1 = self.locmap.coords[edge[0]]
            loc2 = self.locmap.coords[edge[1]]
            if geo.in_area(loc1, min_lat, min_lng, max_lat, max_lng)\
                    and geo.in_area(loc2, min_lat, min_lng, max_lat, max_lng):
                new_g[edge] = g[edge]

        graph.write_graph(new_g, csv_out)
示例#3
0
def graphinfo(csv_in):
    g = graph.read_graph(csv_in)
    print('edges: %s' % (len(g),))
    degs = graph.degrees(g)
    print('nodes: %s' % (len(degs),))
    total = 0.
    max_deg = -1.
    min_deg = float("inf")
    for node in degs:
        deg = degs[node]
        total += deg
        if deg > max_deg:
            max_deg = deg
        if deg < min_deg:
            min_deg = deg
    print('degress: min: %s; max: %s, mean: %s' % (min_deg, max_deg, total / len(degs)))
示例#4
0
def graphinfo(csv_in):
    g = graph.read_graph(csv_in)
    print('edges: %s' % (len(g), ))
    degs = graph.degrees(g)
    print('nodes: %s' % (len(degs), ))
    total = 0.
    max_deg = -1.
    min_deg = float("inf")
    for node in degs:
        deg = degs[node]
        total += deg
        if deg > max_deg:
            max_deg = deg
        if deg < min_deg:
            min_deg = deg
    print('degress: min: %s; max: %s, mean: %s' %
          (min_deg, max_deg, total / len(degs)))
示例#5
0
    def compute(self, infile, outfile):
        g = graph.read_graph(infile)

        f = open(outfile, 'w')

        total_distance = 0.
        count = 0.
        for edge in g:
            loc1 = self.locmap.coords[edge[0]]
            loc2 = self.locmap.coords[edge[1]]
            weight = g[edge]
            dist = geo.distance(loc1, loc2)
            for i in range(weight):
                f.write('%s\n' % dist)
                total_distance += dist
                count += 1.

        f.close()

        mean_distance = total_distance / count
        print('mean distance: %s' % mean_distance)
示例#6
0
    def compute(self, infile, outfile):
        g = graph.read_graph(infile)

        f = open(outfile, "w")

        total_distance = 0.0
        count = 0.0
        for edge in g:
            loc1 = self.locmap.coords[edge[0]]
            loc2 = self.locmap.coords[edge[1]]
            weight = g[edge]
            dist = geo.distance(loc1, loc2)
            for i in range(weight):
                f.write("%s\n" % dist)
                total_distance += dist
                count += 1.0

        f.close()

        mean_distance = total_distance / count
        print("mean distance: %s" % mean_distance)