Пример #1
0
    def setUp(self):
        # this_dir = os.path.dirname(os.path.realpath(__file__))
        # IN_FILE = os.path.join(this_dir, 'test_data', 'mastermap-itn_417209_0_brixton_sample.gml')

        self.test_data = read_gml(TEST_DATA_FILE)

        self.itn_net = ITNStreetNet.from_data_structure(self.test_data)
Пример #2
0
    def setUp(self):
        # this_dir = os.path.dirname(os.path.realpath(__file__))
        # IN_FILE = os.path.join(this_dir, 'test_data', 'mastermap-itn_417209_0_brixton_sample.gml')

        self.test_data = read_gml(TEST_DATA_FILE)

        self.itn_net = ITNStreetNet.from_data_structure(self.test_data)
Пример #3
0
def load_network_and_pickle():
    # test dataset is in a directory in the data directory called 'network_data'
    this_dir = os.path.join(settings.DATA_DIR, 'network_data')
    IN_FILE = os.path.join(this_dir, 'mastermap-itn_544003_0_camden_buff2000.gml')
    test_data = read_gml(IN_FILE)
    itn_net = ITNStreetNet.from_data_structure(test_data)

    camden = camden_boundary()

    itn_net_reduced = itn_net.within_boundary(camden.buffer(100))
    outdir = os.path.join(IN_DIR, 'networks')
    itn_net.save(os.path.join(outdir, 'camden.net'))
    itn_net_reduced.save(os.path.join(outdir, 'camden_clipped.net'))
Пример #4
0
def network_from_pickle():
    infile = os.path.join(IN_DIR, 'networks', 'camden_clipped.net')
    itn_net_reduced = ITNStreetNet.from_pickle(infile)
    return itn_net_reduced
Пример #5
0
 def setUp(self):
     self.test_data = read_gml(TEST_DATA_FILE)
     self.itn_net = ITNStreetNet.from_data_structure(self.test_data)
Пример #6
0
def toy_network(loop=False):
    g = nx.MultiGraph()
    node_coords = {
        'a': (0, 0),
        'b': (5, 0),
        'c': (5, 2),
        'd': (5, 3),
        'e': (6, 2),
        'f': (7, 0),
        'g': (7, -2),
        'h': (5, -2),
        'i': (5, -3),
        'j': (4, -2),
        'k': (0, -2),
        'l': (-1, -2),
        'm': (-2**.5 / 2., -2**.5 / 2. - 2),
        'n': (0, -3),
        'o': (1, -2),
        'p': (0, 2),
    }
    edges = [('a', 'b'), ('a', 'k'), ('k', 'l'), ('k', 'm'), ('k', 'n'),
             ('k', 'o'), ('b', 'c'), ('b', 'h'), ('c', 'd'), ('c', 'e'),
             ('b', 'f'), ('f', 'g'), ('g', 'h'), ('b', 'h'), ('h', 'j'),
             ('h', 'i'), ('a', 'p')]

    def attr_factory(start, end):
        xy0 = node_coords[start]
        xy1 = node_coords[end]
        ls = LineString([xy0, xy1])
        attr_dict = {
            'linestring': ls,
            'length': ls.length,
            'fid': start + end + '1',
            'orientation_neg': start,
            'orientation_pos': end
        }
        return attr_dict

    for i0, i1 in edges:
        attr = attr_factory(i0, i1)
        g.add_edge(i0, i1, key=attr['fid'], attr_dict=attr)

    # add 2 more multilines between a and b
    attr = attr_factory('a', 'b')
    th = np.linspace(0, np.pi, 50)[::-1]
    x = 2.5 * (np.cos(th) + 1)
    y = np.sin(th)
    ls = LineString(zip(x, y))

    attr['fid'] = 'ab2'
    attr['linestring'] = ls
    attr['length'] = ls.length
    g.add_edge('a', 'b', key=attr['fid'], attr_dict=attr)
    ls = LineString([(0, 0), (2.5, -1), (5, 0)])
    attr['fid'] = 'ab3'
    attr['linestring'] = ls
    g.add_edge('a', 'b', key=attr['fid'], attr_dict=attr)

    if loop:
        # add cycle at p
        attr = attr_factory('p', 'p')
        th = np.linspace(-np.pi / 2., 3 * np.pi / 2., 50)
        x = np.cos(th)
        y = np.sin(th) + node_coords['p'][1] + 1
        ls = LineString(zip(x, y))
        attr['linestring'] = ls
        attr['length'] = ls.length
        g.add_edge('p', 'p', key=attr['fid'], attr_dict=attr)

    # add node coords
    for k, v in node_coords.items():
        g.node[k]['loc'] = v

    net = ITNStreetNet.from_multigraph(g)
    return net
Пример #7
0
def load_test_network():
    # load some toy network data
    test_data = read_gml(TEST_DATA_FILE)
    return ITNStreetNet.from_data_structure(test_data)
Пример #8
0
    def test_fixed_distance_walk(self):
        net = toy_network()
        pt = NetPoint.from_cartesian(net, 2.5, 0)


if __name__ == "__main__":
    b_plot = False

    # mini test dataset

    # test dataset is in a directory in the same path as this module called 'test_data'
    this_dir = os.path.dirname(os.path.realpath(__file__))
    IN_FILE = os.path.join(this_dir, 'test_data',
                           'mastermap-itn_417209_0_brixton_sample.gml')
    test_data = read_gml(IN_FILE)
    itn_net = ITNStreetNet.from_data_structure(test_data)

    # buffered Camden dataset from raw data
    # test dataset is in a directory in the data directory called 'network_data'
    # this_dir = os.path.join(settings.DATA_DIR, 'network_data')
    # IN_FILE = os.path.join(this_dir, 'mastermap-itn_544003_0_camden_buff2000.gml')
    # test_data = read_gml(IN_FILE)
    # itn_net = ITNStreetNet.from_data_structure(test_data)

    # buffered Camden dataset from pickle
    # this_dir = os.path.dirname(os.path.realpath(__file__))
    # IN_FILE = os.path.join(this_dir, 'test_data', 'mastermap-itn_544003_0_camden_buff2000.pickle')
    # itn_net = ITNStreetNet.from_pickle(IN_FILE)

    # get the spatial extent of the network
Пример #9
0
 def setUp(self):
     self.test_data = read_gml(TEST_DATA_FILE)
     self.itn_net = ITNStreetNet.from_data_structure(self.test_data)
Пример #10
0
def toy_network(loop=False):
    g = nx.MultiGraph()
    node_coords = {
        'a': (0, 0),
        'b': (5, 0),
        'c': (5, 2),
        'd': (5, 3),
        'e': (6, 2),
        'f': (7, 0),
        'g': (7, -2),
        'h': (5, -2),
        'i': (5, -3),
        'j': (4, -2),
        'k': (0, -2),
        'l': (-1, -2),
        'm': (-2 ** .5 / 2., -2 ** .5 / 2. - 2),
        'n': (0, -3),
        'o': (1, -2),
        'p': (0, 2),
    }
    edges = [
        ('a', 'b'),
        ('a', 'k'),
        ('k', 'l'),
        ('k', 'm'),
        ('k', 'n'),
        ('k', 'o'),
        ('b', 'c'),
        ('b', 'h'),
        ('c', 'd'),
        ('c', 'e'),
        ('b', 'f'),
        ('f', 'g'),
        ('g', 'h'),
        ('b', 'h'),
        ('h', 'j'),
        ('h', 'i'),
        ('a', 'p')
    ]
    def attr_factory(start, end):
        xy0 = node_coords[start]
        xy1 = node_coords[end]
        ls = LineString([xy0, xy1])
        attr_dict = {
            'linestring': ls,
            'length': ls.length,
            'fid': start + end + '1',
            'orientation_neg': start,
            'orientation_pos': end
        }
        return attr_dict

    for i0, i1 in edges:
        attr = attr_factory(i0, i1)
        g.add_edge(i0, i1, key=attr['fid'], attr_dict=attr)

    # add 2 more multilines between a and b
    attr = attr_factory('a', 'b')
    th = np.linspace(0, np.pi, 50)[::-1]
    x = 2.5 * (np.cos(th) + 1)
    y = np.sin(th)
    ls = LineString(zip(x, y))

    attr['fid'] = 'ab2'
    attr['linestring'] = ls
    attr['length'] = ls.length
    g.add_edge('a', 'b', key=attr['fid'], attr_dict=attr)
    ls = LineString([
        (0, 0),
        (2.5, -1),
        (5, 0)
    ])
    attr['fid'] = 'ab3'
    attr['linestring'] = ls
    g.add_edge('a', 'b', key=attr['fid'], attr_dict=attr)

    if loop:
        # add cycle at p
        attr = attr_factory('p', 'p')
        th = np.linspace(-np.pi / 2., 3 * np.pi / 2., 50)
        x = np.cos(th)
        y = np.sin(th) + node_coords['p'][1] + 1
        ls = LineString(zip(x, y))
        attr['linestring'] = ls
        attr['length'] = ls.length
        g.add_edge('p', 'p', key=attr['fid'], attr_dict=attr)


    # add node coords
    for k, v in node_coords.items():
        g.node[k]['loc'] = v

    net = ITNStreetNet.from_multigraph(g)
    return net
Пример #11
0
def load_test_network():
    # load some toy network data
    test_data = read_gml(TEST_DATA_FILE)
    return ITNStreetNet.from_data_structure(test_data)
Пример #12
0
    def test_fixed_distance_walk(self):
        net = toy_network()
        pt = NetPoint.from_cartesian(net, 2.5, 0)



if __name__ == "__main__":
    b_plot = False

    # mini test dataset

    # test dataset is in a directory in the same path as this module called 'test_data'
    this_dir = os.path.dirname(os.path.realpath(__file__))
    IN_FILE = os.path.join(this_dir, 'test_data', 'mastermap-itn_417209_0_brixton_sample.gml')
    test_data = read_gml(IN_FILE)
    itn_net = ITNStreetNet.from_data_structure(test_data)

    # buffered Camden dataset from raw data
    # test dataset is in a directory in the data directory called 'network_data'
    # this_dir = os.path.join(settings.DATA_DIR, 'network_data')
    # IN_FILE = os.path.join(this_dir, 'mastermap-itn_544003_0_camden_buff2000.gml')
    # test_data = read_gml(IN_FILE)
    # itn_net = ITNStreetNet.from_data_structure(test_data)

    # buffered Camden dataset from pickle
    # this_dir = os.path.dirname(os.path.realpath(__file__))
    # IN_FILE = os.path.join(this_dir, 'test_data', 'mastermap-itn_544003_0_camden_buff2000.pickle')
    # itn_net = ITNStreetNet.from_pickle(IN_FILE)

    # get the spatial extent of the network
def network_from_pickle():
    IN_FILE = 'camden_clipped.pickle'
    itn_net_reduced = ITNStreetNet.from_pickle(IN_FILE)
    return itn_net_reduced