1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Camparison closeness coordinates from two files

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024 às 04:42.

  1. Stack

    Stack Membro Participativo

    I need to check two csv files containing coordinates, line by line, if any point from one file is close (less than 10 meters) in the second file, it returns True, unfortunately in the attached code, the second loop, I don't know why, is executed only once. Besides, maybe there is a faster way?

    Below is my code:

    def comparison_closeness_two_files(filename1, filename2):

    threshold_meters = 10/1000 # 10 meters

    file1 = open(filename1, 'r')
    file1 = csv.reader(file1, delimiter=',')
    file2 = open(filename2, 'r')
    file2 = csv.reader(file2, delimiter=',')

    for index, fc1 in enumerate(file1):
    if (len(fc1) != 4):
    continue
    lat1 = float(fc1[2])
    lon1 = float(fc1[3])

    for index, fc2 in enumerate(file2):
    if (len(fc2) != 4):
    continue
    lat2 = float(fc2[2])
    lon2 = float(fc2[3])
    distance = get_distance_between(lat1, lon1, lat2, lon2)
    if (distance <= threshold_meters):
    return True

    return False

    Continue reading...

Compartilhe esta Página