Beispiel #1
0
 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
Beispiel #2
0
 def test_is_rect_intersection(self):
     """
     Tests is_rect_intersection()
     """
     latitude = 35.0
     longitude = -106.0
     # exact point
     self.assertTrue(ph5utils.is_rect_intersection(35.0, 35.0,
                                                   -106.0, -106.0,
                                                   latitude, longitude))
     # box around point
     self.assertTrue(ph5utils.is_rect_intersection(34.0, 36.0,
                                                   -107.0, -105.0,
                                                   latitude, longitude))
     # box touching point longitude
     self.assertTrue(ph5utils.is_rect_intersection(34.0, 36.0,
                                                   -107.0, -106.0,
                                                   latitude, longitude))
     # box touching point latitude
     self.assertTrue(ph5utils.is_rect_intersection(35.0, 36.0,
                                                   -108.0, -105.0,
                                                   latitude, longitude))
     # box outside point - latitude too small
     self.assertFalse(ph5utils.is_rect_intersection(31.0, 34.9,
                                                    -107.0, -105.0,
                                                    latitude, longitude))
     # box outside point - latitude too large
     self.assertFalse(ph5utils.is_rect_intersection(35.1, 37.0,
                                                    -108.1, -100.0,
                                                    latitude, longitude))
     # box outside point - longitude too small
     self.assertFalse(ph5utils.is_rect_intersection(33.0, 36.0,
                                                    -120.0, -106.1,
                                                    latitude, longitude))
     # box outside point - longitude too large
     self.assertFalse(ph5utils.is_rect_intersection(34.0, 36.0,
                                                    -105.9, -100.0,
                                                    latitude, longitude))
     # all outside range
     self.assertFalse(ph5utils.is_rect_intersection(0, 0,
                                                    0, 0,
                                                    latitude, longitude))
Beispiel #3
0
 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
Beispiel #4
0
    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