def test_parse_location(): expect('%.3f;%.3f' % parse_location('52.015;-0.221')) == '52.015;-0.221' expect('%.3f;%.3f' % parse_location('52.015,-0.221')) == '52.015;-0.221' expect('%.3f;%.3f' % parse_location('52.015 -0.221')) == '52.015;-0.221' expect('%.3f;%.3f' % parse_location('52.015N 0.221W')) == '52.015;-0.221' expect('%.3f;%.3f' % parse_location('52.015 N 0.221 W')) == '52.015;-0.221' expect('%.3f;%.3f' % parse_location('52d00m54s N 0d13m15s W')) == \ '52.015;-0.221' expect('%.3f;%.3f' % parse_location('52d0m54s N 000d13m15s W')) == \ '52.015;-0.221' expect('%.3f;%.3f' % parse_location('''52d0'54" N 000d13'15" W''')) == \ '52.015;-0.221'
def import_locations(self, locations): """Import locations from arguments. :type locations: ``list`` of 2 ``tuple`` of ``str`` :param locations: Identifiers and locations """ for identifier, location in locations: data = utils.parse_location(location) if data: latitude, longitude = data else: latitude, longitude = utils.from_grid_locator(location) self[identifier] = Point(latitude, longitude, self.units)
def import_locations(self, locations, config_locations): """Import locations from arguments. :type locations: ``list`` of ``str`` :param locations: Location identifiers :param dict config_locations: Locations imported from user's config file """ for number, location in enumerate(locations): if config_locations and location in config_locations: latitude, longitude = config_locations[location] self.append(NumberedPoint(latitude, longitude, location, self.units)) else: try: data = utils.parse_location(location) if data: latitude, longitude = data else: latitude, longitude = utils.from_grid_locator(location) self.append(NumberedPoint(latitude, longitude, number + 1, self.units)) except ValueError: raise LocationsError(data=(number, location))
def test_parse_location(location, result): assert '%.3f;%.3f' % parse_location(location) == result