def find_coordinates(city, address, number_of_house, test=False): """Функция ищет координаты по задонному адресу""" coordinates = [] try: if not test: coordinate_path = os.path.join("./test_base", "Russia_coordinates.db") buildings_path = os.path.join("./test_base", "Russia_buildings.db") else: coordinate_path = os.path.join("./test_base", "test_coordinates.db") buildings_path = os.path.join("./test_base", "test_buildings.db") con1 = sqlite3.connect(coordinate_path) cur1 = con1.cursor() con2 = sqlite3.connect(buildings_path) cur2 = con2.cursor() sql = "SELECT Links FROM address_base WHERE City=? AND Address=? AND House_number=?" cur2.execute(sql, [city, address, number_of_house]) links = cur2.fetchone()[0] links = links.split() res = [] for link in links: res.append(int(link)) for i in res: sql2 = "SELECT Lat,Lon FROM coordinates_base WHERE Link=?" cur1.execute(sql2, [i]) c = cur1.fetchall() coordinates.append([c[0][0], c[0][1]]) coordinates = numpy.array(coordinates) return Geometry.find_centroid(coordinates, len(coordinates)) except TypeError: print('Нет такого адреса в базе: {}'.format( str.join(" ", [city, address, number_of_house])))
def test_centroid_finder(self): coordinates = numpy.array([[10, 10], [20, 20], [10, 20], [20, 10]]) result = [10.0, 3.333333333333332] self.assertEqual( result, list(Geometry.find_centroid(coordinates, len(coordinates))))