Appendix: Filtering Geolocation Data

The Less Than or Equal To Distance and Greater Than or Equal To Distance filter operators let you fetch rows containing geospatial coordinates, based on their comparative distance from another set of coordinates.

Filters written using the Less Than or Equal To Distance or Greater Than or Equal To Distance operators can only be applied to SQL Server data sources - including T-SQL data sources.

You can only filter Geography data type columns in the target table. Fields containing literal values for latitude and longitude cannot be used for this method of filtering. Refer to Writing Geolocation Values to a Data Source for more information about working with this type of data.

KnowledgeKube will first compare the latitude and longitude values in each row of the data source against equivalent values you provide, and evaluate the distance in metres between them. The filter will then exclude rows where the distance is greater than, less than, or equal to a specific number of metres away from the specified location - depending on the chosen operator type.

The Condition Type must be set to Expression, and the expression written in the Condition field must provide appropriate values for latitude, longitude and distance (in metres) as a comma-separated list.

An example of a valid expression is shown below:

"51.512028, -0.116740, 2500"

The latitude and longitude values used in this expression represent the centre of London, and the comparative distance is 2,500 metres. A filter that combines this condition with a Greater Than or Equal To Distance operator will only return rows containing locations that are at least 2,500 metres from the centre of London.

Instead of using literal values for your condition, you can use dynamic ones stored in question or variable keywords. To do this, you will need the FormatString function to combine the keywords into a suitable string. This also allows you to use latitude and longitude values assigned to variables by the GetLocationInfo function.

The following expression demonstrates how FormatString can be used to create a string using variable and literal values:

FormatString("{0},{1},{2}", "VARCurrentLatitude,VARCurrentLongitude,3500");

An example of a fully configured filter is shown below:

Conditions for a correctly configured filter.

The filter in this example will compare the geospatial data from the Street field with a comma-separated list of values created using FormatString, and exclude any rows where the locations are more than 3,500m away.