If the impact layer has a distance field, it will return the distance to
    the nearest place in metres.

    e.g. distance_to_nearest_place() -> 1234
766717
def distance_to_nearest_place(feature, parent):
    
    _ = feature, parent  # NOQA

    layer = exposure_summary_layer()
    if not layer:
        return None

    index = layer.fields().lookupField(
        distance_field['field_name'])
    if index < 0:
        return None

    feature = next(layer.getFeatures())
    return feature[index]
479480
def nearbys(radius = 20, options = {})
      return nil unless geocoded?
      options.merge!(:exclude => self) unless send(self.class.primary_key).nil?
      self.class.near(self, radius, options)
    end
997108
def k_closest(points, k, origin=(0, 0)):
    # Time: O(k+(n-k)logk)
    # Space: O(k)
    
    heap = [(-distance(p, origin), p) for p in points[:k]]
    heapify(heap)

    """
    For every point p in points[k:],
    check if p is smaller than the root of the max heap;
    if it is, add p to heap and remove root. Reheapify.
    """
    for p in points[k:]:
        d = distance(p, origin)

        heappushpop(heap, (-d, p))  # heappushpop does conditional check
        """Same as:
            if d < -heap[0][0]:
                heappush(heap, (-d,p))
                heappop(heap)

        Note: heappushpop is more efficient than separate push and pop calls.
        Each heappushpop call takes O(logk) time.
        """

    return [p for nd, p in heap]
316382
def layer_distance(a, b):
    """"""
    # pylint: disable=unidiomatic-typecheck
    if type(a) != type(b):
        return 1.0
    if is_layer(a, "Conv"):
        att_diff = [
            (a.filters, b.filters),
            (a.kernel_size, b.kernel_size),
            (a.stride, b.stride),
        ]
        return attribute_difference(att_diff)
    if is_layer(a, "Pooling"):
        att_diff = [
            (a.padding, b.padding),
            (a.kernel_size, b.kernel_size),
            (a.stride, b.stride),
        ]
        return attribute_difference(att_diff)
    return 0.0
1253947
def distance(self,rng):
    
    if self.chr != rng.chr: return -1
    c = self.cmp(rng)
    if c == 0: return 0
    if c < 0:
      return rng.start - self.end-1
    return self.start - rng.end-1
567328
def edit_distance(x, y):
    

    ret = layers_distance(x.layers, y.layers)
    ret += Constant.KERNEL_LAMBDA * skip_connections_distance(
        x.skip_connections, y.skip_connections
    )
    return ret
755941
def get_nearest_site(sites, lat, lon):
    
    for site in sites:
        site.distance_to_coords(lat, lon)
    sites.sort(key=operator.attrgetter("distance"))
    return sites[0].ident
964444
def distance(self, piecex, piecey):
        ''''''
        return max(abs(piecex[0] - piecey[0]), abs(piecex[1], piecey[1]))
213960
def near(lat, lng, max_dist=None, unit_miles=False):
        
        filters = {
            "$nearSphere": {
                "$geometry": {
                    "type": "Point",
                    "coordinates": [lng, lat],
                }
            }
        }
        if max_dist:
            if unit_miles:  # pragma: no cover
                max_dist = max_dist / 1609.344
            filters["$nearSphere"]["$maxDistance"] = max_dist
        return filters
1369516
def distance_between(self, place_1, place_2, unit='km'):
        
        pickled_place_1 = self._pickle(place_1)
        pickled_place_2 = self._pickle(place_2)
        try:
            return self.redis.geodist(
                self.key, pickled_place_1, pickled_place_2, unit=unit
            )
        except TypeError:
            return None
1291055
static int closestCorner4(Grid g ) {
		double bestDistance = g.get(0,0).center.normSq();
		int bestIdx = 0;

		double d = g.get(0,g.columns-1).center.normSq();
		if( d < bestDistance ) {
			bestDistance = d;
			bestIdx = 3;
		}
		d = g.get(g.rows-1,g.columns-1).center.normSq();
		if( d < bestDistance ) {
			bestDistance = d;
			bestIdx = 2;
		}
		d = g.get(g.rows-1,0).center.normSq();
		if( d < bestDistance ) {
			bestIdx = 1;
		}

		return bestIdx;
	}
959608
def nearest_term_256(byte)
      for i in 0..4
        lower, upper = BYTEPOINTS_256[i], BYTEPOINTS_256[i + 1]
        next unless byte.between?(lower, upper)

        distance_from_lower = (lower - byte).abs
        distance_from_upper = (upper - byte).abs
        closest = distance_from_lower < distance_from_upper ? lower : upper
      end
      closest
    end
1186531
def distance_to(self, address, measure="Miles", httpclient=None):
        
        if isinstance(address, Address) and self.latlng and address.latlng:
            lat1, lon1 = map(float, self.latlng)
            lat2, lon2 = map(float, address.latlng)
        elif self.latlng and type(address) is tuple:
            lat1, lon1 = map(float, self.latlng)
            lat2, lon2 = address
        else:
            raise ValueError(":address must be type tuple or Address")
            
        radius = 6371 # km          
        dlat = math.radians(lat2 - lat1)
        dlon = math.radians(lon2 - lon1)
        a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.radians(lat1)) \
          * math.cos(math.radians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2)
        c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
        d = radius * c
        # d is in kilometers
        if measure == self.KILOMETERS:
            return d
        elif measure == self.METERS:
            return d / 1000
        elif measure == self.MILES:
            return d * .621371
        else:
            return d
581979
def get_nearest_site(self, latitude=None,  longitude=None):
        
        warning_message = 'This function is deprecated. Use get_nearest_forecast_site() instead'
        warn(warning_message, DeprecationWarning, stacklevel=2)

        return self.get_nearest_forecast_site(latitude, longitude)
1303556
def nearest_base(cls, bases):
    '''
    '''
    if cls in bases:
        return cls

    dists = {base: index(mro(cls), base) for base in bases}
    dists2 = {dist: base for base, dist in dists.items() if dist is not None}
    if not dists2:
        return None
    return dists2[min(dists2)]
123015
def get_nearest_by_coordinates(
        data: list, latitude_key: str, longitude_key: str,
        target_latitude: float, target_longitude: float) -> Any:
    """"""
    return min(
        data,
        key=lambda p: haversine(
            target_latitude,
            target_longitude,
            float(p[latitude_key]),
            float(p[longitude_key])
        ))
133096
def formfield(self, **kwargs):
        
        kwargs.update({
            'max_value': 90,
            'min_value': -90,
        })
        return super(LatitudeField, self).formfield(**kwargs)