def test_center_from_points_qs(self): qs = Address.objects.all() centre = centre_from_points_qs(qs) self.assertEqual( centre.wkt, "POINT (0.7195476867864934 52.0965233704130242)" )
def geocode_point_only(self): addresses = Address.objects.filter(postcode=self.postcode) if not addresses: raise ObjectDoesNotExist('No addresses found for postcode %s' % (self.postcode)) centre = centre_from_points_qs(addresses) return { 'source': 'addressbase', 'wgs84_lon': centre.x, 'wgs84_lat': centre.y, }
def geocode_point_only(postcode): """ Try to get centre of the point from AddressBase, fall back to MapIt """ addresses = Address.objects.filter(postcode=postcode) if not addresses: time.sleep(1.3) return geocode(postcode) centre = centre_from_points_qs(addresses) return { 'wgs84_lon': centre.x, 'wgs84_lat': centre.y, }
def geocode(self): addresses = Address.objects.filter(postcode=self.postcode) if not addresses: raise ObjectDoesNotExist('No addresses found for postcode %s' % (self.postcode)) codes = self.get_codes(self.get_uprns(addresses)) centre = centre_from_points_qs(addresses) return { 'source': 'addressbase', 'wgs84_lon': centre.x, 'wgs84_lat': centre.y, 'council_gss': codes['council_gss'], 'gss_codes': codes['gss_codes'], }
def test_center_from_points_qs(self): qs = Address.objects.all() centre = centre_from_points_qs(qs) self.assertEqual(centre.wkt, "POINT (0.7195476867864934 52.0965233704130242)")