def map_nodes_to_one_city(city, city_file, node): # return a .cvs file with the name of the city in which a node is # first, compute the bounding box around the city polygon = [] with open(city_file, 'rb') as f: reader = csv.reader(f) for i, row in enumerate(reader): if len(row) >= 2 and row[1][26:-1] == city: line = row[13:] for j, e in enumerate(line): if len(e) > 0: if j == 0: polygon.append([float(e.split(' ')[-1])]) else: if j % 2 == 1: polygon[-1].append(float(e.split(' ')[1])) else: polygon.append([float(e.split(' ')[-1])]) break ps = [[node[i, 1:3][1], node[i, 1:3][0]] for i in range(node.shape[0])] return areInside(polygon, len(polygon), ps)
def map_nodes_to_one_city(city, city_file, node): # return a .cvs file with the name of the city in which a node is # first, compute the bounding box around the city polygon = [] with open(city_file, 'rb') as f: reader = csv.reader(f) for i,row in enumerate(reader): if len(row) >= 2 and row[1][26:-1] == city: line = row[13:] for j,e in enumerate(line): if len(e) > 0: if j == 0: polygon.append([float(e.split(' ')[-1])]) else: if j%2 == 1: polygon[-1].append(float(e.split(' ')[1])) else: polygon.append([float(e.split(' ')[-1])]) break ps = [[node[i,1:3][1], node[i,1:3][0]] for i in range(node.shape[0])] return areInside(polygon, len(polygon), ps)
def test_areInside(self): polygon1 = [[0, 0], [5, 5], [5, 0]] n = len(polygon1) ps = [[3, 3], [5, 1], [8, 1]] self.assertTrue(areInside(polygon1, n, ps) == [1, 1, 0])