Create Ranges 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

Calculates thematic ranges and stores the ranges in an array, which can then be used in a Shade statement. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

Create Ranges
	From table
	With expr
	[ Use { "Equal Ranges" | "Equal Count" | "Natural Break" | "StdDev" } ] 
	[ Quantile Using q_expr ]
	[ Number num_ranges ]
	[ Round rounding_factor ]
	Into Variable array_variable 

table is the name of the table to be shaded thematically.

expr is an expression that is evaluated for each row in the table.

q_expr is the expression used to perform quantiling.

num_ranges specifies the number of ranges (default is 4).

rounding_factor is factor by which the range break numbers should be rounded (for example, 10 to round off values to the nearest ten).

array_variable is the float array variable in which the range information will be stored.

Description

The Create Ranges statement calculates a set of range values which can then be used in a Shade statement (which creates a thematic map layer). For an introduction to thematic maps, see the MapInfo Pro documentation.

The optional Use clause specifies how to break the data into ranges. If you specify "Equal Ranges" each range covers an equal portion of the spectrum of values (for example, 0-25, 25-50, 50-75, 75-100). If you specify "Equal Count" the ranges are constructed so that there are approximately the same number of rows in each range. If you specify "Natural Break" the ranges are dictated by natural breaks in the set of data values. If you specify "StdDev" the middle range breaks at the mean of your data values, and the ranges above and below the middle range are one standard deviation above or below the mean. MapInfo Pro uses the population standard deviation (N - 1).

The Into Variable clause specifies the name of the float array variable that will hold the range information. You do not need to pre-size the array; MapInfo Pro automatically enlarges the array, if necessary, to make room for the range information. The final size of the array is twice the number of ranges, because MapInfo Pro calculates a high value and a low value for each range.

After calling Create Ranges, call the Shade statement to create the thematic map, and use the Shade statement's optional From Variable clause to read the array of ranges. The Shade statement usually specifies the same table name and column expression as the Create Ranges statement.

Quantiled Ranges

If the optional Quantile Using clause is present, the Use clause is ignored and range limits are defined according to the q_expr.

Quantiled ranges are best illustrated by example. The following statement creates ranges of buying power index (BPI) values, and uses state population statistics to perform quantiling to set the range limits.

Create Ranges From states 
	With BPI_1990 Quantile Using Pop_1990 
	Number 5 
	Into Variable f_ranges 

Because of the Number 5 clause, this example creates a set of five ranges.

Because of the With BPI_1990 clause, states with the highest BPI values will be placed in the highest range (the deepest color), and states with the lowest BPI values will be placed in the lowest range (the palest color).

Because of the Quantile Using Pop_1990 clause, the range limits for the intermediate ranges are calculated by quantiling, using a method that takes state population (Pop_1990) into account. Since the Quantile Using clause specifies the Pop_1990 column, MapInfo Pro calculates the total 1990 population for the table (which, for the United States, is roughly 250 million). MapInfo Pro divides that total by the number of ranges (in this case, five ranges), producing a result of fifty million. MapInfo Pro then tries to define the ranges in such a way that the total population for each range approximates, but does not exceed, fifty million.

MapInfo Pro retrieves rows from the States table in order of BPI values, starting with the states having low BPI values. MapInfo Pro assigns rows to the first range until adding another row would cause the cumulative population to match or exceed fifty million. At that time, MapInfo Pro considers the first range "full" and then assigns rows to the second range. MapInfo Pro places rows in the second range until adding another row would cause the cumulative total to match or exceed 100 million; at that point, the second range is full, etc.

Example

Include "mapbasic.def"

Dim range_limits() As Float, brush_styles() As Brush 
Dim col_name As Alias 

Open Table "states" Interactive

Create Styles 
	From Brush(2, CYAN, 0) 'style for LOW range
	To Brush (2, BLUE, 0) 'style for HIGH range
	Vary Color By "RGB" 
	Number 5 
	Into Variable brush_styles 
' Store a column name in the Alias variable: 
col_name = "Pop_1990" 

Create Ranges From states 
	With col_name 
	Use "Natural Break" 
	Number 5 
	Into Variable range_limits 

Map From states 

Shade states 
	With col_name 
	Ranges 
		From Variable range_limits 
		Style Variable brush_styles 

' Show the theme legend window: 
Open Window Legend 

See Also:

Create Styles statement, Set Shade statement, Shade statement