Open davidmasp opened 1 year ago
For the grasshopper API I am creating an account on here in the free plan. According to the website it should give me access to the main Matrix API which is what I would need for this to work.
https://docs.graphhopper.com/#operation/postRoute
https://www.graphhopper.com/pricing/
I checked the API and it works!
I have a working implementation of the api in python, I need to decide how to select the coordinates.
I have the problem of how to calculate linear distance between coordinates. I got a chatgpt implementation in python. Hope that works?
import math
def haversine(lat1, lon1, lat2, lon2):
R = 6371 # Radius of the Earth in kilometers
lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2])
dlat = lat2 - lat1
dlon = lon2 - lon1
a = math.sin(dlat / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2) ** 2
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
distance = R * c
return distance
# Example usage:
lat1 = 52.5200
lon1 = 13.4050
lat2 = 48.8566
lon2 = 2.3522
distance = haversine(lat1, lon1, lat2, lon2)
print(f"The distance between the two points is {distance:.2f} kilometers.")
The HAVERSINE formula is described here https://en.wikipedia.org/wiki/Haversine_formula
I did check using google maps and the answer is correct!
I had the problem of how to actually get the dimensions from the map into a csv. According to this reddit post I can draw polygons into the map and then export coordinates of the polygon using google maps (or rather my maps from gmaps)
possible cities I have selected:
EU
USA
China
Other
Mountain
Sea level
There is also another service, OpenRouteService
They have a iso-travel time (see tutorial here)
The idea is to make a visualization of driving time/distance compared to the actual ditance measured in the map. Original ideas were: