Farthest statement - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Find the object in a table that is farthest from a particular object. The result is a two-point Polyline object representing the farthest distance. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

Farthest [ N | All ] 
	From { Table fromtable | Variable fromvar }
	To totable Into intotable 
	[ Type { Spherical | Cartesian } ] 
	[ Ignore [ Contains ] [ Min min_value ] 
		[ Max max_value ] Units unitname ] 
	[ Data clause ]

N is an optional parameter for the number of "farthest" objects to find. The default is 1. If All is used, then a distance object is created for every combination.

fromtable is a table of objects from which you want to find farthest distances.

fromvar is a MapBasic variable representing an object that you want to find the farthest distances from.

totable is a table of objects that you want to find farthest distances to.

intotable is a table to place the results into.

min_value is the minimum distance to include in the results.

max_value is the maximum distance to include in the results.

unitname is string representing the name of a distance unit (for example, "km") used for min_value and/or max_value.

Description

The Farthest statement finds all the objects in the fromtable that is furthest from a particular object. Every object in the fromtable is considered. For each object in the fromtable, the furthest object in the totable is found. If N is defined, then the N farthest objects in the totable are found. A two-point Polyline object representing the farthest points between the fromtable object and the chosen totable object is placed in the intotable. If All is specified, then an object is placed in the intotable representing the distance between the fromtable object and each totable object.

If there are multiple objects in the totable that are the same distance from a given fromtable object, then only one of them may be returned. If multiple objects are requested (for example, if N is greater than 1), then objects of the same distance will fill subsequent slots. If a tie exists at the second farthest object, and three objects are requested, then one of the second farthest objects will become the third farthest object.

The types of the objects in the fromtable and totable can be anything except Text objects. For example, if both tables contain Region objects, then the minimum distance between Region objects is found, and the two-point Polyline object produced represents the points on each object used to calculate that distance. If the Region objects intersect, then the minimum distance is zero, and the two-point Polyline returned will be degenerate, where both points are identical and represent a point of intersection.

The distances calculated do not take into account any road route distance. It is strictly a "as the bird flies" distance.

The Ignore clause can be used to limit the distances to be searched, and can effect how many totable objects are found for each fromtable object. One use of the Min distance could be to eliminate distances of zero. This may be useful in the case of two point tables to eliminate comparisons of the same point. For example, if there are two point tables representing Cities, and we want to find the closest cities, we may want to exclude cases of the same city.

The Max distance can be used to limit the objects to consider in the totable. This may be most useful in conjunction with N or All. For example, we may want to search for the five airports that are closest to a set of cities (where the fromtable is the set of cities and the totable is a set of airports), but we do not care about airports that are farther away than 100 miles. This may result in less than five airports being returned for a given city. This could also be used in conjunction with the All parameter, where we would find all airports within 100 miles of a city.

Supplying a Max parameter can improve the performance of the Farthest statement, since it effectively limits the number of totable objects that are searched.

The effective distances found are strictly greater than the min_value and less than or equal to the max_value:

min_value < distance <= max_value

This can allow ranges or distances to be returned in multiple passes using the Farthest statement. For example, the first pass may return all objects between 0 and 100 miles, and the second pass may return all objects between 100 and 200 miles, and the results should not contain duplicates (for example, a distance of 100 should only occur in the first pass and never in the second pass).

Type is the method used to calculate the distances between objects. It can either be Spherical or Cartesian. The type of distance calculation must be correct for the coordinate system of the intotable or an error will occur. If the Coordsys of the intotable is NonEarth and the distance method is Spherical, then an error will occur. If the Coordsys of the intotable is Latitude/Longitude, and the distance method is Cartesian, then an error will occur.

The Ignore clause limits the distances returned. Any distances found which are less than or equal to min_value or greater than max_value are ignored. min_value and max_value are in the distance unit signified by unitname. If unitname is not a valid distance unit, an error will occur. See Set Distance Units statement for the list of available unit names. The entire Ignore clause is optional, as are the Min and Max sub clauses within it.

Normally, if one object is contained within another object, the distance between the objects is zero. For example, if fromtable is WorldCaps and totable is World, then the distance between London and the United Kingdom would be zero. If the Contains keyword is used within the Ignore clause, then the distance will not be automatically be zero. Instead, the distance from London to the boundary of the United Kingdom will be returned. In effect, this will treat all closed objects, such as regions, as polylines for the purpose of this operation.

The Data clause can be used to mark which fromtable object and which totable object the result came from.

Data Clause

Data IntoColumn1=column1, IntoColumn2=column2

The IntoColumn on the left hand side of the equals sign must be a valid column in intotable. The column name on the right hand side of the equals sign must be a valid column name from either totable or fromtable. If the same column name exists in both totable and fromtable, then the column in totable will be used (e.g., totable is searched first for column names on the right hand side of the equals sign).

To avoid any conflicts such as this, the column names can be qualified using the table alias. For example:

Data name1=states.state_name, name2=county.state_name

To fill a column in the intotable with the distance, we can either use the Update Column functionality from the menu or use the Update statement.

See Also:

Nearest statement, CartesianObjectDistance() function, ObjectDistance() function, SphericalObjectDistance() function, CartesianConnectObjects() function, ConnectObjects() function, SphericalConnectObjects() function