def build_flight_plan(flight_plan_form): new_flight_plan = flight_plan_form.save(commit=False) # PySAL wants lat/lon as lon/lat depart = (new_flight_plan.depart_longitude, new_flight_plan.depart_latitude) arrive = (new_flight_plan.arrive_longitude, new_flight_plan.arrive_latitude) interval = new_flight_plan.report_interval utc_depart_time = new_flight_plan.depart_time miles = sphere.arcdist(depart, arrive, sphere.RADIUS_EARTH_MILES) hours = miles / float(new_flight_plan.planned_speed) utc_arrive_time = utc_depart_time + timedelta(hours=hours) reports = min(int(math.floor(hours / min(interval, hours))), 50) # Provides the point to center the map on midpoint = sphere.geointerpolate(depart, arrive, 0.5) new_flight_plan.midpoint_latitude = midpoint[1] new_flight_plan.midpoint_longitude = midpoint[0] weather_reports = [] for i in range(reports): coords = sphere.geointerpolate(depart, arrive, (i * interval) / float(hours)) utc_report_time = utc_depart_time + timedelta(hours=(i * interval)) weather_reports.append( build_weather_report(coords[1], coords[0], utc_report_time)) weather_reports.append( build_weather_report(arrive[1], arrive[0], utc_arrive_time)) return (new_flight_plan, weather_reports)
def test_linear2arcdist(self): d = sphere.arcdist(self.pt0, self.pt1, sphere.RADIUS_EARTH_MILES) ad = sphere.linear2arcdist(2.0, radius=sphere.RADIUS_EARTH_MILES) self.assertEquals(d, ad)
def test_arcdist2linear(self): d = sphere.arcdist(self.pt0, self.pt1, sphere.RADIUS_EARTH_MILES) ld = sphere.arcdist2linear(d, sphere.RADIUS_EARTH_MILES) self.assertEquals(ld, 2.0)
def test_arcdist(self): d = sphere.arcdist(self.pt0, self.pt1, sphere.RADIUS_EARTH_MILES) self.assertEquals(d, math.pi * sphere.RADIUS_EARTH_MILES)
def compute_distance(a, b): return arcdist(a, b, radius=EARTH_RADIUS_IN_METERS)
from geopy.distance import great_circle with open('short.csv', 'r') as f: # with open('../tz.csv', 'r') as f: reader = csv.reader(f) next(reader) # skipp header # filter: title[starts(EMS)] accidentPoints = list(filter(lambda x: x[4].startswith("EMS:"), reader)) print("EMS item count:", len(accidentPoints)) # list: lat, lng, desc, zip, title, time, twp, e NEW_YORK = [40.678492, -73.899734] print(arcdist([0, 0], NEW_YORK)) print(great_circle([0, 0], NEW_YORK)) #this is too much - arc through center? print(arcdist([40.2978759, -75.5812935], [40.678492, -73.899734])) # this measures distance fine # great_circle is right print(great_circle([40.2978759, -75.5812935], [40.678492, -73.899734])) print(arcdist([60, -70], [60, -115])) print(great_circle([60, -70], [60, -115])) for x in accidentPoints: print("p1", x[0], ",", x[1], "p2", NEW_YORK[0], ",", NEW_YORK[1], x[3:]) print(arcdist([float(x[0]), float(x[1])], NEW_YORK)) print(great_circle([float(x[0]), float(x[1])], NEW_YORK))
from pysal.cg import sphere jfk = (-73.778925, 40.639751) sfo = (-122.374889, 37.618972) gso = (-79.937306, 36.09775) mia = (-80.290556, 25.79325) mph = 300 miles = sphere.arcdist(gso, mia, sphere.RADIUS_EARTH_MILES) hours = miles / mph print "Reach MIA from GSO in {0} hours at {1} mph".format(hours, mph) print "Hourly weather forecast coordinates:" # WeatherSource only returns hourly forecasts on the hour reports = int(round(hours)) for i in range(reports): print sphere.geointerpolate(jfk, sfo, i / float(reports))