How to use the geopy.location.Location function in geopy

To help you get started, we’ve selected a few geopy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geopy / geopy / test / test_location.py View on Github external
def test_location_ne(self):
        """
        Location.__ne__
        """
        loc1 = Location(GRAND_CENTRAL_STR, GRAND_CENTRAL_POINT)
        loc2 = Location(GRAND_CENTRAL_STR, None)
        self.assertNotEqual(loc1, loc2)
github geopy / geopy / geopy / geocoders / yandex.py View on Github external
"""
            Parse each record.
            """
            try:
                place = place['GeoObject']
            except KeyError:
                raise GeocoderParseError('Failed to parse server response')

            longitude, latitude = [
                float(_) for _ in place['Point']['pos'].split(' ')
            ]

            name_elements = ['name', 'description']
            location = ', '.join([place[k] for k in name_elements if place.get(k)])

            return Location(location, (latitude, longitude), place)
github geopy / geopy / geopy / geocoders / ignfrance.py View on Github external
location = "%s %s" % (
                    place.get('postal_code', ''),
                    place.get('commune', ''),
                )
                if place.get('street'):
                    location = "%s, %s" % (
                        place.get('street', ''),
                        location,
                    )
                if place.get('building'):
                    location = "%s %s" % (
                        place.get('building', ''),
                        location,
                    )

        return Location(location, (place.get('lat'), place.get('lng')), place)
github geopy / geopy / geopy / geocoders / osm.py View on Github external
def parse_code(place):
        # TODO make this a private API
        # Parse each resource.
        latitude = place.get('lat', None)
        longitude = place.get('lon', None)
        placename = place.get('display_name', None)
        if latitude is not None and longitude is not None:
            latitude = float(latitude)
            longitude = float(longitude)
        return Location(placename, (latitude, longitude), place)
github geopy / geopy / geopy / geocoders / navidata.py View on Github external
def parse_place(place):
            '''Get the location, lat, lon from a single json result.'''
            location = place.get('description')
            latitude = place.get('lat')
            longitude = place.get('lon')
            return Location(location, (latitude, longitude), place)
github geopy / geopy / geopy / geocoders / opencage.py View on Github external
def parse_place(place):
            '''Get the location, lat, lng from a single json place.'''
            location = place.get('formatted')
            latitude = place['geometry']['lat']
            longitude = place['geometry']['lng']
            return Location(location, (latitude, longitude), place)
github geopy / geopy / geopy / geocoders / banfrance.py View on Github external
def _parse_feature(feature):
        # Parse each resource.
        latitude = feature.get('geometry', {}).get('coordinates', [])[1]
        longitude = feature.get('geometry', {}).get('coordinates', [])[0]
        placename = feature.get('properties', {}).get('label')

        return Location(placename, (latitude, longitude), feature)
github geopy / geopy / geopy / geocoders / geonames.py View on Github external
longitude = place.get('lng', None)
            if latitude and longitude:
                latitude = float(latitude)
                longitude = float(longitude)
            else:
                return None

            placename = place.get('name')
            state = place.get('adminName1', None)
            country = place.get('countryName', None)

            location = ', '.join(
                [x for x in [placename, state, country] if x]
            )

            return Location(location, (latitude, longitude), place)