MariosMelach / Marios-Thesis

Transport Mode
1 stars 0 forks source link

Route elevation estimation algorithms. #4

Closed argythana closed 8 months ago

argythana commented 8 months ago

Create a separate notebook. Use a file that includes only geolocation data for home and work (addresses. Postal Codes, City, etc.)

Try existing open source solutions. Detailed examples of algorithms you tried.

MariosMelach commented 8 months ago

καλημέρα, μετα απο πολλά που δοκίμασα, βρήκατα τον συγκεκριμένο κώδικα για να υπολογίσει τις αποστάσεις μεταξύ των διευθύνσεων χρησιμοποιόντας την βιβλιοθήκη geopy: from geopy.geocoders import Nominatim from geopy.distance import geodesic

Create a geolocator instance with a unique user agent

geolocator = Nominatim(user_agent="MyGeocodingApp_Marios_Melachroinos_v21.21")

Function to get coordinates for an address

def get_coordinates(address): location = geolocator.geocode(address) if location: return location.latitude, location.longitude else: return None

Function to calculate distance between home and work coordinates

def calculate_distance(row): home_coords = get_coordinates(row['Home_adress']) work_coords = get_coordinates(row['Work_adress'])

if home_coords and work_coords:
    return geodesic(home_coords, work_coords).kilometers
else:
    return None

Apply the calculate_distance function to each row in the DataFrame

df['distance_km'] = df.apply(calculate_distance, axis=1)

Από τις 400 σειρές περίπου τις 130 δεν τις αναγνώρισε οπότε επέστρεψε τιμές NaN έχω 2 επιλογές. Η να κρατήσω τις αποστάσεις όπως τις βρήκα manually και να αναφέρω στην μεθοδολογία ότι ο παραπάνω κώδικας μπορει να αυτοματοποιήσει την διαδικασία όταν έχουμε παρα πολλα data. Ο άλλος τρόπος είναι να κρατήσω αποστάσεις από αυτά που μπόρεσε να υπολογίσει και σε αυτά που επέστρεψε NaN να τα αντικαταστήσω με αυτά που υπολόγισα μόνος. Ποιο πιστεύετε είναι καλύτερο

argythana commented 8 months ago

Ο άλλος τρόπος είναι να κρατήσω αποστάσεις από αυτά που μπόρεσε να υπολογίσει και σε αυτά που επέστρεψε NaN να τα αντικαταστήσω με αυτά που υπολόγισα μόνος.

This is the optimal way for your use-case (time constrain and project scope).

In a real life, big-data scenario, you should explore options to fill-in all addresses. For example:
You could manually check to see what the problem is with the missing addresses and correct the addresses. Or find what are the reasons for not finding the geolocation.