def is_lat_lon_match(self, latitude, longitude): """ Checks if the given latitude/longitude matches geographic query constraints :param: latitude : the latitude to check against the arguments geographic constraints :param: longitude : the longitude to check against the arguments geographic constraints """ if not -90 <= float(latitude) <= 90: return False elif not -180 <= float(longitude) <= 180: return False # if lat/lon box intersection elif not ph5utils.is_rect_intersection( self.args.get('minlat'), self.args.get('maxlat'), self.args.get('minlon'), self.args.get('maxlon'), latitude, longitude): return False # check if point/radius intersection elif not ph5utils.is_radial_intersection( self.args.get('latitude'), self.args.get('longitude'), self.args.get('minradius'), self.args.get('maxradius'), latitude, longitude): return False else: return True
def test_is_radial_intersection(self): """ Tests is_radial_intersection() """ # Use IU ANMO as a test case latitude = 34.946 longitude = -106.457 # point is an exact match to location self.assertTrue(ph5utils.is_radial_intersection(34.946, -106.457, 0, 1, latitude, longitude)) self.assertTrue(ph5utils.is_radial_intersection(34.946, -106.457, 0, 0, latitude, longitude)) # intersect ANMO self.assertTrue(ph5utils.is_radial_intersection(46.195, -121.553, 0, 17.623, latitude, longitude)) # intersect ANMO no min radius defined self.assertTrue(ph5utils.is_radial_intersection(46.195, -121.553, None, 17.623, latitude, longitude)) # intersect ANMO with a min radius self.assertTrue(ph5utils.is_radial_intersection(35.174, -91.846, 10, 14.377, latitude, longitude)) # does not intersect ANMO self.assertFalse(ph5utils.is_radial_intersection(46.195, -121.553, 0, 3, latitude, longitude)) self.assertFalse(ph5utils.is_radial_intersection(31.915, -106.282, 0, 0.752, latitude, longitude)) # min radius is outside ANMO self.assertFalse(ph5utils.is_radial_intersection(34.946, -106.457, 1, 4, latitude, longitude)) # min radius is outside ANMO - no max radius defined self.assertFalse(ph5utils.is_radial_intersection(34.946, -106.457, 1, None, latitude, longitude)) # all outside range self.assertFalse(ph5utils.is_radial_intersection(0, 0, 0, 0, latitude, longitude))
def check_intersection(self, sta_xml_obj, latitude, longitude): """ Checks latitude and longitude against geographic constraints :param: sta_xml_obj : PH5toStationXMLRequest object for the constraints :param: latitude : the given latitude :param: longitude : the given longitude """ # check if lat/lon box intersection if not ph5utils.is_rect_intersection( sta_xml_obj.minlatitude, sta_xml_obj.maxlatitude, sta_xml_obj.minlongitude, sta_xml_obj.maxlongitude, latitude, longitude): return False # check if point/radius intersection if not ph5utils.is_radial_intersection( sta_xml_obj.latitude, sta_xml_obj.longitude, sta_xml_obj.minradius, sta_xml_obj.maxradius, latitude, longitude): return False return True
def is_lat_lon_match(self, sta_xml_obj, station): """ Checks if the given station's latitude/longitude matches geographic query constraints and the completeness of latitude/longitude/elevation :param: sta_xml_obj : a PH5toStationXMLRequest object for checking lat/lon box intersection and point/radius intersection :param: station : a station entry of latitude, longitude and elevation to be checked """ errors = [] latitude = float(station['location/Y/value_d']) longitude = float(station['location/X/value_d']) validation.check_lat_lon_elev(station, errors) # check if lat/lon box intersection if not ph5utils.is_rect_intersection( sta_xml_obj.minlatitude, sta_xml_obj.maxlatitude, sta_xml_obj.minlongitude, sta_xml_obj.maxlongitude, latitude, longitude): errors.append( box_intersection_err(latitude, sta_xml_obj.minlatitude, sta_xml_obj.maxlatitude, longitude, sta_xml_obj.minlongitude, sta_xml_obj.maxlongitude)) # check if point/radius intersection if not ph5utils.is_radial_intersection( sta_xml_obj.latitude, sta_xml_obj.longitude, sta_xml_obj.minradius, sta_xml_obj.maxradius, latitude, longitude): errors.append( radial_intersection_err(latitude, longitude, sta_xml_obj.minradius, sta_xml_obj.maxradius, sta_xml_obj.latitude, sta_xml_obj.longitude)) return errors