def test_deg_to_rad(self): # Test degree to radian conversion loc1 = GeoLocation.from_degrees(26.062951, -80.238853) loc2 = GeoLocation.from_radians(loc1.rad_lat, loc1.rad_lon) assert (loc1.rad_lat == loc2.rad_lat and loc1.rad_lon == loc2.rad_lon and loc1.deg_lat == loc2.deg_lat and loc1.deg_lon == loc2.deg_lon)
def getPhotoObject(self): os.chdir('..') execution_path = os.getcwd() detector = ObjectDetection() detector.setModelTypeAsYOLOv3() detector.setModelPath(os.path.join(execution_path, "yolo.h5")) detector.loadModel() media_path = self.navigateToMediaDir() photos = {} for name in os.listdir('.'): with open(name, "r") as read_file: data = json.load(read_file) for key in data['photos']: detection_types = self.getObjectTypes( detector, media_path, key['uri']) geolocation = GeoLocation() geo_loc = geolocation.getLongLatFromIP( str(key['media_metadata']['photo_metadata'] ['upload_ip'])) photos[str(key['uri']).split('/')[2]] = { 'category': data['name'], 'uri': str(key['uri']).split('/')[2], 'geo': geo_loc, 'detection_types': detection_types } return photos
def bbox_to_square(bbox): """bbox is lat-lon, wkt-poly is lon-lat """ sw_point = bbox[0] ne_point = bbox[1] se_point = gl.from_degrees(sw_point.deg_lat, ne_point.deg_lon) nw_point = gl.from_degrees(ne_point.deg_lat, sw_point.deg_lon) return (sw_point, nw_point, ne_point, se_point, sw_point)
def main(): print() print("------------------M Y P L A C E S------------------") eiffel_tower = make_eiffel() louvre_museum = make_louvre() space_needle = make_needle() statue_of_liberty = make_liberty() leaning_tower_of_pisa = make_pisa() print(eiffel_tower) print("-----------------------------------------------------") print(louvre_museum) print("-----------------------------------------------------") print(space_needle) print("-----------------------------------------------------") print(statue_of_liberty) print("-----------------------------------------------------") print(leaning_tower_of_pisa) print("-----------------------------------------------------\n") print("---------------D I S T A N C E F R O M--------------") print("Louvre Museum from Eiffel Tower:", round(eiffel_tower.distance_from(louvre_museum), 2)) print("Louvre Museum from Statue of Liberty:", round(statue_of_liberty.distance_from(louvre_museum), 2)) print("Statue of Liberty from Leaning Tower of Pisa:", round(leaning_tower_of_pisa.distance_from(statue_of_liberty), 2)) print("-----------------------------------------------------\n") print("------F I N D P L A C E W I T H G E O L O C A T I O N------") search(GeoLocation(48.859556, 2.294441)) print("-----------------------------------------------------")
def generate_bbox_around_point(point, distance): #distance in km point_lat = point[0] point_lon = point[1] loc = GeoLocation.from_degrees(point_lat, point_lon) SW_loc, NE_loc = loc.bounding_locations(distance) return [SW_loc.deg_lat, SW_loc.deg_lon, NE_loc.deg_lat, NE_loc.deg_lon]
def get_bbox(current_location): print 'no' latitude, longitude = current_location print 'no' loc = GeoLocation.from_degrees(float(latitude), float(longitude)) print 'no' distance = 1 # 1 kilometer print 'no' SW_loc, NE_loc = loc.bounding_locations(distance) print 'no' print SW_loc print NE_loc print 'no' sw_string = SW_loc.__str__() sw_degrees = sw_string.split('=')[0] sw_degrees = sw_degrees[1:-1] south = sw_degrees[:7] west = sw_degrees[-12:-4] print 'no' ne_string = NE_loc.__str__() ne_degrees = ne_string.split('=')[0] ne_degrees = ne_degrees[1:-1] print 'no' north = ne_degrees[:7] east = ne_degrees[-12:-4] print 'no' return "{},{},{},{}".format(west, south, east, north)
def __init__(self, lat, lon, meters=1000, description=None): self.lat = lat self.lon = lon self.meters = meters self.description = description self.point = GeoLocation.from_degrees(lat, lon) self.state = None
def test_geolocation(self): loc1 = GeoLocation.from_degrees(26.062951, -80.238853) loc2 = GeoLocation.from_radians(loc1.rad_lat, loc1.rad_lon) self.assertTrue(loc1.rad_lat == loc2.rad_lat and loc1.rad_lon == loc2.rad_lon and loc1.deg_lat == loc2.deg_lat and loc1.deg_lon == loc2.deg_lon) # Test distance between two locations loc1 = GeoLocation.from_degrees(26.062951, -80.238853) loc2 = GeoLocation.from_degrees(26.060484, -80.207268) self.assertTrue(loc1.distance_to(loc2) == loc2.distance_to(loc1)) # Test bounding box loc = GeoLocation.from_degrees(26.062951, -80.238853) distance = 1 # 1 kilometer SW_loc, NE_loc = loc.bounding_locations(distance) self.assertTrue(SW_loc.deg_lon < NE_loc.deg_lon and SW_loc.deg_lat < NE_loc.deg_lat)
def set_min_radius(self, radius=None): # Radius in Km if radius is None: return bbox = GeoLocation.from_degrees( self.latitude(), self.longitude() ).bounding_locations(radius) self.south = min(self.south, bbox[0].deg_lat) self.north = max(self.north, bbox[1].deg_lat) self.west = min(self.west, bbox[0].deg_lon) self.east = max(self.east, bbox[1].deg_lon)
def circToBB(self,lon,lat,radius,unit="kilometers"): loc = GeoLocation.from_degrees(lat,lon) sw, ne = loc.bounding_locations(radius,unit) bb = { 'lon_min': sw.deg_lon, 'lon_max': ne.deg_lon, 'lat_min': sw.deg_lat, 'lat_max': ne.deg_lat } return bb
def check(self, item): lat = item['lat'] lon = item['lon'] tid = item['tid'] topic = item['topic'] try: here = GeoLocation.from_degrees(lat, lon) for wp in self.wplist: trigger = None meters = 0 try: meters = here.distance_to(wp.point) * 1000. except: pass km = "{:.2f}".format( float(meters / 1000.0) ) movement = { 'km' : km, 'tid' : tid, 'topic' : topic, 'event' : None, } very_near = meters <= wp.meters if very_near is False: if topic in self.tlist: if self.tlist[topic] == wp: trigger = TRIGGER_LEAVE self.alert(wp, trigger, item, meters, km) del self.tlist[topic] self.tlist.sync() if very_near is True: if topic not in self.tlist: trigger = TRIGGER_ENTER self.tlist[topic] = wp self.tlist.sync() self.alert(wp, trigger, item, meters, km) else: # Optional: # msg = "%s STILL AT %s (%s km)" % (topic, self.tlist[topic], km) # print msg return except: raise pass
def get_hospital_records_within_distance(zip_code, distance_in_kilometers): url = 'https://services1.arcgis.com/Hp6G80Pky0om7QvQ/arcgis/rest/services/Hospitals_1/FeatureServer/0/query' lon, lat = get_user_long_lat(zip_code) loc = GeoLocation.from_degrees(lat, lon) SW_loc, NE_loc = loc.bounding_locations(distance_in_kilometers) params = { 'where': f'(LATITUDE BETWEEN {SW_loc.deg_lat} AND {NE_loc.deg_lat}) AND (LONGITUDE BETWEEN {SW_loc.deg_lon} AND {NE_loc.deg_lon})', 'f': 'json', 'outFields': '*', 'returnGeometry': 'false' } r = requests.get(url, params=params) if r: return r.json()['features'] else: raise ValueError( f"Could not complete request! Responded with code {r.status_code}")
def gen_bbox(lat, lon, distance): center = gl.from_degrees(lat, lon) SW_loc, NE_loc = center.bounding_locations(distance) return (SW_loc, NE_loc)
end_time = time.time() print "Time for generating " + str(number_of_points) + " points: " + str( end_time - start_time) return gps_tuples def printKnn(kNN): for result in kNN: print str(result[0]) + ", distance: " + str(result[1]) print "" if __name__ == "__main__": #gps_tuples = generate_test_points() gps_tuples = generate_random_points() geolocation = GeoLocation() start_time = time.time() geolocation.load_points(gps_tuples) end_time = time.time() print "Time for creating the kd-Tree: " + str(end_time - start_time) #geolocation.load_points(gps_tuples) test_point = GPSPoint("Maze 9 Tel Aviv", 12.3234, -12.234) #test_point = Point("Bastille paris", 48.862592, 2.347260) #lat = raw_input("Test point - Latitude: ") #lon = raw_input("Test point - Longitude: ") for k in xrange(1, 2): #print testPoint.distance(ny); #k = int(raw_input("How many nearest neighbors? (K): "))
def make_louvre(): louvre_name = "Louvre Museum" louvre_address = "Cour Carrée, 75001 Paris, France" louvre_tag = "France Museum" louvre_location = GeoLocation(48.860717, 2.337708) return Place(louvre_name, louvre_address, louvre_tag, louvre_location)
def test_bounding_locations_invalid_distance(self): loc = GeoLocation.from_degrees(0, 0) self.assertRaises(ValueError, loc.bounding_locations, 100, -5)
def test_bounding_locations_invalid_radius(self): loc = GeoLocation.from_degrees(0, 0) self.assertRaises(ValueError, loc.bounding_locations, -1)
def test_eq(self): loc = GeoLocation.from_degrees(26.062951, -80.238853) loc2 = GeoLocation.from_degrees(26.062951, -80.238853) assert loc == loc2
def test_distance(self): # Test distance between two locations loc1 = GeoLocation.from_degrees(26.062951, -80.238853) loc2 = GeoLocation.from_degrees(26.060484, -80.207268) assert loc1.distance_to(loc2) == loc2.distance_to(loc1)
def find_bounds(lat, lng, d): loc = GeoLocation.from_degrees(lat, lng) SW_loc, NE_loc = loc.bounding_locations(d) return (SW_loc.deg_lat, SW_loc.deg_lon, NE_loc.deg_lat, NE_loc.deg_lon)
def make_needle(): needle_name = "Space Needle" needle_address = "Queen Anne, Seattle, WA 98109" needle_tag = "Seattle Tower" needle_location = GeoLocation(47.620761, -122.348531) return Place(needle_name, needle_address, needle_tag, needle_location)
def make_liberty(): liberty_name = "Statue of Liberty" liberty_address = "Liberty Island, New York, NY 10004" liberty_tag = "New York Monument" liberty_location = GeoLocation(40.689355, -74.044468) return Place(liberty_name, liberty_address, liberty_tag, liberty_location)
def make_pisa(): pisa_name = "Leaning Tower of Pisa" pisa_address = "56126 Pisa, Province of Pisa, Italy" pisa_tag = "Italy Tower" pisa_location = GeoLocation(43.723099, 10.396629) return Place(pisa_name, pisa_address, pisa_tag, pisa_location)
def make_eiffel(): eiffel_name = "Eiffel Tower" eiffel_address = "Eiffel Tower, 75007 Paris, France" eiffel_tag = "France Tower" eiffel_location = GeoLocation(48.859556, 2.294441) return Place(eiffel_name, eiffel_address, eiffel_tag, eiffel_location)