def getDistancesInRange(origin, dest, course): distances = [] originLoc = origin.latlon with open("data/newairports_2.txt") as f: lines = f.readlines() for line in lines: data = line.split(", ") if (len(data) < 3): continue temp = LatLon(Latitude(data[1]), Longitude(data[2])) tempDist = originLoc.distance(temp) * km_to_nm if (tempDist < math.ceil(course[0])): distances.append( Point_Of_Interest(data[0], data[1], data[2], tempDist)) with open("data/cities.txt") as f: lines = f.readlines() for line in lines: data = line.split(", ") if (len(data) < 3): continue temp = LatLon(Latitude(data[1]), Longitude(data[2])) tempDist = originLoc.distance(temp) * km_to_nm if (tempDist < math.ceil(course[0])): distances.append( Point_Of_Interest(data[0], data[1], data[2], tempDist)) return distances
def random_ride(self, ne_lng, ne_lat, sw_lng, sw_lat, min_len=2, max_len=10): """ params are bounding box and minimum length in kilometres """ print "seeking random route" while True: a = LatLon(Latitude(random.uniform(ne_lat, sw_lat)), Longitude(random.uniform(sw_lng, ne_lng))) c = LatLon(Latitude(random.uniform(ne_lat, sw_lat)), Longitude(random.uniform(sw_lng, ne_lng))) if a.distance(c) >= min_len and a.distance(c) <= max_len: self.point = (a.lon.decimal_degree, a.lat.decimal_degree) self.destination = (c.lon.decimal_degree, c.lat.decimal_degree) router = Router(points=[self.point, self.destination]) if router.route: self.route = router.route self.save() break
def split(s, t, speed): """ returns points between s(ource) and t(arget) at intervals of size @speed """ s = LatLon(Latitude(s[1]), Longitude(s[0])) t = LatLon(Latitude(t[1]), Longitude(t[0])) heading = s.heading_initial(t) fine = [ (s.lon.decimal_degree, s.lat.decimal_degree), ] wp = s while True: dst = wp.offset(heading, speed / 1000.0) if dst.distance(t) * 1000.0 > speed: fine.append((dst.lon.decimal_degree, dst.lat.decimal_degree)) wp = dst else: fine.append((t.lon.decimal_degree, t.lat.decimal_degree)) break return fine
def calculate_distances(network): for n1 in network.adjacency.iterkeys(): node1 = network.nodes[n1] p1 = LatLon(Latitude(node1[1]), Longitude(node1[0])) updated = [] for n2, ht in network.adjacency[n1]: node2 = network.nodes[n2] p2 = LatLon(Latitude(node2[1]), Longitude(node2[0])) d = p1.distance(p2) updated.append((n2, ht, d)) network.adjacency[n1] = updated
def waypoints(coords, step): for i in range(1, len(coords)): a = LatLon(Latitude(b.point[1]), Longitude(b.point[0])) c = LatLon(Latitude(coords[i][1]), Longitude(coords[i][0])) while a.distance(c) > step: dst = a.offset(a.heading_initial(c), step) yield [dst.lon.decimal_degree, dst.lat.decimal_degree] a = LatLon(Latitude(b.point[1]), Longitude(b.point[0])) c = LatLon(Latitude(coords[i][1]), Longitude(coords[i][0])) print "reached waypoint %s" % c yield [coords[i][0], coords[i][1]]
def closest_to(self, lat, lon): origin = LatLon(Latitude(lat), Longitude(lon)) min_dist = sys.maxint closest = None for node_id, (node_lat, node_lon) in self.nodes.iteritems(): node_position = LatLon(Latitude(node_lat), Longitude(node_lon)) dist_to_origin = origin.distance(node_position) if dist_to_origin < min_dist: min_dist = dist_to_origin closest = node_id return closest
def heading_to(self, other_point): """ heading from my point to @other_point """ if 'coordinates' in self.point: a = LatLon(Longitude(self.point['coordinates'][1]), Latitude(self.point['coordinates'][0])) else: a = LatLon(Longitude(self.point[1]), Latitude(self.point[0])) b = LatLon(Longitude(other_point[1]), Latitude(other_point[0])) return a.heading_initial(b)
def obliczPolozenie(listaWspol): wykresTableX = [] wykresTableY = [] czasy = [] tetno = [] totalDistance = 0 prevCzas = listaWspol[1][2] for i, punkt in enumerate(listaWspol): if i > 0: punkt1 = LatLon(listaWspol[i - 1][0], listaWspol[i - 1][1]) punkt2 = LatLon(Latitude(listaWspol[i][0]), Longitude(listaWspol[i][1])) distance = punkt1.distance(punkt2) if distance != 0: czasDiff = listaWspol[i][2] - prevCzas prevCzas = listaWspol[i][2] totalDistance += distance try: pace = (czasDiff.total_seconds() / 60) / distance except Exception as err: pass if pace < 20: elementDoPrintu = [totalDistance, pace] wykresTableX.append(totalDistance) wykresTableY.append(pace) czasy.append(listaWspol[i][2]) tetno.append(listaWspol[i][3]) return wykresTableX, wykresTableY, totalDistance, czasy, tetno
def distance_to(self, other_point): """ distance from agent to another point, in metres """ if 'coordinates' in self.point: s = LatLon(Latitude(self.point['coordinates'][1]), Longitude(self.point['coordinates'][0])) else: s = LatLon(Latitude(self.point[1]), Longitude(self.point[0])) if 'coordinates' in other_point: t = LatLon(Latitude(other_point['coordinates'][1]), Longitude(other_point['coordinates'][0])) else: t = LatLon(Latitude(other_point[1]), Longitude(other_point[0])) return s.distance(t) * 1000.0
def __init__(self, name, lat, lon, dist=-1, data="", setting="normal"): self.name = name self.dist = dist self.lat = lat self.lon = lon self.priority = 0 self.latlon = LatLon(Latitude(lat), Longitude(lon)) self.data = data self.setting = setting return
def carpet_bomb(x, y, r): n = int(round(2 * (r / PELLET_DIST))) pellets = [None] * (n * n) middle = LatLon(Latitude(x), Longitude(y)) pelletAlpha = middle.offset(315, r) for i in range(0, n): pellets[n * i] = pelletAlpha.offset(180, PELLET_DIST * i) for j in range(1, n): pellets[n * i + j] = pellets[n * i].offset(90, PELLET_DIST * j) return pellets
def getData(filename, p, prevLoc, r, allowSpaces=False): potChanges = [] with open(filename) as f: lines = f.readlines() for line in lines: data = line.split(", ") if (len(data) < 3 or p.lower().replace(" ", "") not in data[0].replace( " ", "").lower()): continue temp = LatLon(Latitude(data[1]), Longitude(data[2])) tempDist = prevLoc.latlon.distance(temp) * km_to_nm if ( tempDist < 2 * math.ceil(r.course[0]) ): # still lets you route a course through new location that may be further away potChanges.append( Point_Of_Interest(data[0], data[1], data[2], tempDist)) return potChanges
def update(self, new_point, update_speed=False): """ updates time stamp uses @new_point to update: - point - heading - destination_heading - speed, if update_speed=True """ if 'coordinates' in self.point: a = LatLon(Longitude(self.point['coordinates'][1]), Latitude(self.point['coordinates'][0])) else: a = LatLon(Longitude(self.point[1]), Latitude(self.point[0])) if 'coordinates' in new_point: b = LatLon(Longitude(new_point['coordinates'][1]), Latitude(new_point['coordinates'][0])) else: b = LatLon(Longitude(new_point[1]), Latitude(new_point[0])) if 'coordinates' in self.destination: c = LatLon(Longitude(self.destination['coordinates'][1]), Latitude(self.destination['coordinates'][0])) else: c = LatLon(Longitude(self.destination[1]), Latitude(self.destination[0])) self.heading = a.heading_initial(b) self.destination_heading = b.heading_initial(c) if update_speed: tdelta = datetime.now() - self.stamp seconds = tdelta.total_seconds() distance = a.distance(b) / 1000.0 self.speed = distance / seconds self.stamp = datetime.now() self.point = new_point self.save()
def get_distance(sa, da, codes): return LatLon(Latitude(codes[da][1]), Longitude(codes[da][2])).distance( LatLon(Latitude(codes[sa][1]), Longitude(codes[sa][2])))
def get_point_LatLon(self): return LatLon(Longitude(self.point['coordinates'][1]), Latitude(self.point['coordinates'][0]))
def get_distance(point1, point2): point1_coordinates = LatLon(Latitude(point1[1]), Longitude(point1[0])) point2_coordinates = LatLon(Latitude(point2[1]), Longitude(point2[0])) distance = point1_coordinates.distance(point2_coordinates) return distance * 1000
import json from LatLon import LatLon, Latitude, Longitude tdata = open("masten2.json").read() jdata = json.loads(tdata) length = len(jdata) def convert(coord): ind = coord.index('\xba') degree = float(coord[:ind - 1]) temp = coord[ind + 1:].strip() ind = temp.index("'") minute = float(temp[:ind]) second = float(temp[ind + 1:].strip()) return [degree, minute, second] for i in range(0, length): lat = convert(jdata[i]["coordinates_la"].encode("utf8")) lon = convert(jdata[i]["coordinates_lo"].encode("utf8")) c = LatLon(Latitude(degree=lat[0], minute=lat[1], second=lat[2]), Longitude(degree=lon[0], minute=lon[1], second=lon[2])) jdata[i]["coordinates_la"] = float(c.lat) jdata[i]["coordinates_lo"] = float(c.lon) with open('masten3.json', 'w') as outfile: json.dump(jdata, outfile)
coordinates.lon.decimal_degree) metadata.write() print("Added geodata to: {0}".format(filename)) except ValueError, e: print("Skipping {0}: {1}".format(filename, e)) if __name__ == '__main__': if len(sys.argv) > 3: print("Usage: python move_picture.py path offset (in meters)") raise IOError("Bad input parameters.") path = sys.argv[1] if len(sys.argv) == 3: offset = float(sys.argv[2]) print("Offset value is {0} meter(s)".format(offset)) # list of file tuples sorted by timestamp imageList = list_images(path) for Img in imageList: original_coord = LatLon(Latitude(Img[1]), Longitude(Img[2])) new_coord = original_coord.offset(Img[3], (offset / 1000)) tuple_coord = new_coord.to_string('d%,%m%,%S%,%H') list_coord = ",".join(tuple_coord) list_coord = list_coord.split(",") list_coord.append(Img[3]) #import pdb; pdb.set_trace() write_exif(Img[0], new_coord) print("End of Script")
def distance(self, lon_new, lat_new, ellipse = 'sphere'): old_latlon = LatLon(Latitude(self.lat), Longitude(self.lon)) new_latlon = LatLon(Latitude(lat_new), Longitude(lon_new)) return new_latlon.distance(old_latlon, ellipse = ellipse)