CentroidX() function - 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

Returns the x-coordinate of the centroid of an object. You can call this function from the MapBasic window in MapInfo Pro.

Syntax

CentroidX( obj_expr )

obj_expr is an object expression

Return Value

Float

Description

The CentroidX() function returns the X coordinate (e.g., Longitude) component of the centroid of the specified object. See the Centroid() function for a discussion of what the concept of a centroid position means with respect to different types of graphical objects (lines vs. regions, etc.).

The coordinate information is returned in MapBasic's current coordinate system; by default, MapBasic uses a Longitude/Latitude coordinate system. The Set CoordSys statement allows you to change the coordinate system used.

Examples

The following example shows how the CentroidX() function can calculate the longitude of a single geographic object.

Dim x As Float
Open Table "world"
Fetch First From world
x = CentroidX(world.obj) 

You can also use the CentroidX() function within the Select statement. The following Select statement extracts information from the World table, and stores the results in a temporary table called Results. Because the Select statement includes the CentroidX() function and the CentroidY() function, the Results table will include columns which display the longitude and latitude of the centroid of each country.

Open Table "world"
Select country, CentroidX(obj), CentroidY(obj)
	From world Into results 

See Also:

Centroid() function, CentroidY() function, Set CoordSys statement