--- title: "GeneralFunction" slug: "nearest" updated: 2022-09-23T14:14:16Z published: 2022-09-23T14:14:16Z canonical: "docs.datajet.app/nearest" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.datajet.app/llms.txt > Use this file to discover all available pages before exploring further. # NEAREST(LT, LN, TLT, TLN) ## Geo: NEAREST (LT, LN, TLT, TLN) ### Returns the row number of the nearest point in a lookup table of latitudes and longitudes ## Purpose Use this function to: - Identify the nearest lookup location to a set of coordinates - Find nearest geographical place - Create a continuous integer key that can be used to link to a lookup table ## Return Value | Property | Value | | --- | --- | | **FieldType** | Integer | | **FieldSize** | Continuous | | **DataType** | Continuous | | **DataSize** | Integer | ```shell Example Return Value: 1 to N, where N is the number of rows in the lookup table ``` ![Nearest_data](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/Nearest_data.PNG) ## Parameters | Parameter | JSON | Description | | --- | --- | --- | | **Table** | “targetTable”: “MyTableName” | The target table on which the new field will be created | | **Filter** | “dataset”: {DataSet_JSON} | Optional. If a filter is applied, records not in the filter DataSet will be returned as null. | | **Function** | "function":"geo" | Geo | | **Geo Function** | "p1": "NEAREST(LT,LN,TLT,TLN)" | NEAREST(LT,LN,TLT,TLN) | | **LT** | “p2”: "lat" | Required. The field on the targetTable containing the latitude value. *Supports:* - **DataType:** Discrete/Continuous - **Field Type:** Double - **Fixed Value:** #nn.nnnnnnn | | **LN** | “p3”: "lon" | Required. The field on the targetTable containing the longitude value *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:** #nn.nnnnnnn | | **TLT** | “p4”: "worldcities.lat" | Required. The fully qualified column on the lookup table that contains latitude. *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:** #nn.nnnnnnn | | **TLN** | “p5”:"worldcities.lng" | Required. The fully qualified column on the lookup table that contains longitude. *Supports:* - **DataType: Discrete/Continuous** - **Field Type: Double** - **Fixed Value:** #nn.nnnnnnn | ## JSON Sample ```json { "method": "BuildBakedField", "project": "Model1", "targetTable": "BikePoints", "overwrite": true, "name": "Nearest", "function": "geo", "p1": "NEAREST(LT,LN,TLT,TLN)", "p2": "lat", "p3": "lon", "p4": "worldcities.lat", "p5": "worldcities.lng" } ``` ## Usage Notes NEAREST returns an continuous integer key into the lookup table. Use this key to create a key to the lookup table, and then copy up specific data-points as required. Example targetTable: ![targetTable](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/targetTable.PNG) Example Lookup Table: ![LookupTable](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/LookupTable.PNG) See Also: - Distance(A, B, C, D) - DIST2NEAREST(LT, LN, TLT, TLN) - GMNearest, GMDIST2NEAREST - [Copy Up](/v1/docs/copy-up) - [Joins](/v1/docs/joins) ## Example | Example | Details | | --- | --- | | **Description** | Obtain lookup of world city that is nearest to BikePoint | | **Input** | - Table: = [BikePoint] - Function:= Geo - Filter: = [No Filter] - **Geo Function: = NEAREST(LT, LN, TLT, TLN)** - LT:= lat - LN:= lon - TLT:= worldcities.lat - TLN:= worldcities.lon - Name: =Nearest | | **Sample** | ![NEAREST_Example](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/NEAREST_Example.PNG) |