def get_data(self): """ Get the houses for rent """ try: data = urllib2.urlopen(self.url) #Tricky part result = json.load(data) aux = json.dumps(result) aux2 = json.dumps(json.loads(aux)) #Data Frame data_frame = pd.read_json(aux2) data_frame = data_frame.dropna() distances = [] #Compute the distance between two points useing harvesine formule #print(data_frame) for i, r in data_frame.iterrows(): ans = haversine(r['longitude'], r['latitude']) distances.append(ans) data_frame['distance'] = pd.Series(distances, index=data_frame.index) return data_frame except Exception as e: print("error", str(e)) return []
print("================ Extracting gps locations===================") max_latitude = -500 min_latitude = 500 max_longitude = -500 min_longitude = 500 lon_lat_list = [] for file in gpx_files: gpx_file = open(file,'r') gpx = gpxpy.parse(gpx_file) lon = [] lat = [] last_point = (0,0) for track in gpx.tracks: for segment in track.segments: for gps_point in segment.points: if(functions.haversine(last_point, (gps_point.longitude, gps_point.latitude)) > 2):#to avoid bias in heat in uphills, when you move slower, the haversine distance between two points has to be at least 2 meters lon.append(gps_point.longitude) lat.append(gps_point.latitude) if(max_latitude < gps_point.latitude): max_latitude = gps_point.latitude if(min_latitude > gps_point.latitude): min_latitude = gps_point.latitude if(max_longitude < gps_point.longitude): max_longitude = gps_point.longitude if(min_longitude > gps_point.longitude): min_longitude = gps_point.longitude last_point = (gps_point.longitude, gps_point.latitude) lon_lat_list.append((lon,lat)) print("Done in: ", time.time() - lap, " s") lap = time.time()
lon1 = 283.90 lat1 = -14.37 # SAm 1 lon2 = 286.76 lat2 = -33.01 # SAm 2 lon3 = 143.07 lat3 = 25.33 # Mariana rad_km = 6378. thresh_dist = 200. # every-so-often case num = 0 for n in range(len(dips)): lon = dips[n, 0] lat = dips[n, 1] dist1 = haversine(lon, lat, lon1, lat1, rad_km) dist2 = haversine(lon, lat, lon2, lat2, rad_km) dist3 = haversine(lon, lat, lon3, lat3, rad_km) if dist1 < thresh_dist or dist2 < thresh_dist or dist3 < thresh_dist: pass else: num = num + 1 dips_new = np.zeros((num, 3)) num = 0 for i in range(len(dips)): lon = dips[i, 0] lat = dips[i, 1] dist1 = haversine(lon, lat, lon1, lat1, rad_km) dist2 = haversine(lon, lat, lon2, lat2, rad_km) dist3 = haversine(lon, lat, lon3, lat3, rad_km)
num_obs = len(dips_lall) slab2_dips_LallLocations = np.zeros((num_obs, 4)) for i in range(num_obs): lon_obs = dips_lall[i, 0] lat_obs = dips_lall[i, 1] dist_max = 5000.0 dist_ind = 1e6 for j in range(len(dips_slab2_full)): lon_calc = dips_slab2_full[j, 0] lat_calc = dips_slab2_full[j, 1] dist = haversine(lon_obs, lat_obs, lon_calc, lat_calc, 6378.) if dist < dist_max: dist_max = dist dist_ind = j if dist_ind != 1e6: slab2_dips_LallLocations[i, 0] = dips_slab2_full[dist_ind, 0] slab2_dips_LallLocations[i, 1] = dips_slab2_full[dist_ind, 1] slab2_dips_LallLocations[i, 2] = dips_slab2_full[dist_ind, 2] slab2_dips_LallLocations[i, 3] = dist_max slab2cont_dips_LallLocations = np.zeros((num_obs, 4)) for i in range(num_obs): lon_obs = dips_lall[i, 0] lat_obs = dips_lall[i, 1]
seg_dist = np.zeros((num_obs)) is_trench_fixed = np.zeros((num_obs)) is_just_upper_mant = np.zeros((num_obs)) num_good_subds = 0 for i in range(num_obs): lon_obs = dips_obs_tmp[i, 0] lat_obs = dips_obs_tmp[i, 1] dist_max = 1000.0 for j in range(num_DPs): lon_mod = DPs_mod[j, 0] lat_mod = DPs_mod[j, 1] dist = haversine(lon_obs, lat_obs, lon_mod, lat_mod, 6378.) if dist < dist_max and iwall[j] == 1: dist_max = dist dist_ind = j lon_mod = DPs_mod[dist_ind, 0] lat_mod = DPs_mod[dist_ind, 1] DP = DPs_mod[dist_ind, 4] age = sp_ages[dist_ind, 2] vc = DPs_mod[dist_ind, 5] vt = DPs_mod[dist_ind, 6] crust_density = 3450 # rho_eclogite [kg/m3], C-T Lee, W-P Chen, 2007, EPSL crust_thick = 7.5e3 # m # fill array...
# get age coordinates if iwall[i] == 1: if polarity[i] == 1: # dipping to left age_azim = alpha[i] + (np.pi/2.) else: # dipping to right age_azim = alpha[i] - (np.pi/2.) lon_age_rad , lat_age_rad = project_to_point(np.deg2rad(lono[i]), np.deg2rad(lato[i]), age_azim, age_len_ratio) if lon_age_rad < 0.: lon_age_rad = (2.*np.pi) + lon_age_rad sp_ages[i,0] = math.degrees(lon_age_rad) sp_ages[i,1] = math.degrees(lat_age_rad) dist_max = 1.e9 for j in range(0,len(age_txt)): dist_pt = haversine(sp_ages[i,0], sp_ages[i,1], age_txt[j,0], age_txt[j,1],6378.) if dist_pt < dist_max: dist_max = dist_pt closest_ind = j print i sp_ages[i,2] = age_txt[closest_ind,2] print "getting rid of nans..." for i in range(len(sp_ages)): if np.isnan(sp_ages[i,2]): dist_max = 1.e9 for k in range(0,len(sp_ages)): dist_pt = haversine(sp_ages[i,0], sp_ages[i,1], sp_ages[k,0], sp_ages[k,1],6378.)
import json sys.path.append("..") from functions import generate_random_string, haversine from app import app from models import db, Stops, Links, Edges, Routes index = 0.0 with app.app_context(): stops = Stops.query.all() num_stops = len(stops) * 1.0 for begin_stop in stops: index += 1.0 print(begin_stop.id) print(str(index / num_stops)) for end_stop in stops: if begin_stop.id != end_stop.id: distance = haversine(begin_stop.lng, begin_stop.lat, end_stop.lng, end_stop.lat) existing_edge = Edges.query.filter_by( beginning_stop=begin_stop.id).filter_by( ending_stop=end_stop.id).first() if existing_edge == None: if distance < 1: new_edge = Edges(generate_random_string(10, 20), begin_stop.id, end_stop.id, distance) db.session.add(new_edge) db.session.commit() print("Finished")