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

Produces a raster grid file, which MapBasic displays as a raster table in a Map window. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

Create Grid 
	From tablename 
	With expression [ Ignore value_to_ignore ]
	Into filespec [ Type grid_type ]
		[ Coordsys... ]
	[ Clipping { Object obj } | { Table tablename } ]
	Inflect num_inflections [ By Percent ] at
	color : inflection_value [ color : inflection_value ...] 
	[ Round rounding_factor ]
	{[ Cell Size cell_size [ Units distance_unit ]] | [ Cell Min n_cells ]}
		 [ Border numcells ]
	Interpolate With interpolator_name Version version_string 
		Using num_parameters parameter_name : parameter_value 
		[ parameter_name : parameter_value ... ] 

tablename is the "alias" name of an open table from which to get data points.

expression is the expression by which the table will be shaded, such as a column name.

value_to_ignore is a value to be ignored; this is usually zero. No grid theme will be created for a row if the row's value matches the value to be ignored.

filespec specifies the fully qualified path and name of the new grid file. It will have a .MIG extension.

grid_type is a string expression that specifies the type of grid file to create. By default, .MIG format files are created using "mig.ghl". If using a custom grid handler, then supply the name of that custom grid handler, such as "dted.ghl".

Coordsys is an optional CoordSys clause which is the coordinate system that the grid will be created in. If not provided, the grid will be created in the same coordinate system as the source table. Refer to CoordSys clause for more information.

obj is an object to clip grid cells to. Only the portion of the grid theme within the object will display. If a grid cell is not within the object, that cell value will not be written out and a null cell is written in its place.

tablename is the name of a table of region objects which will be combined into a single region object and then used for clipping grid cells.

num_inflections is a numeric expression, specifying the number of color:inflection_value pairs.

color is a color expression of, part of a color:value inflection pair.

inflection_value is a numeric expression, specifying the value of a color:inflection_value pair as a number or a percentage.

rounding_factor is a numeric expression, specifying the rounding factor applied to the inflection values.

cell_size is a numeric expression, specifying the size of a grid cell in distance units.

distance_unit is a string expression specifying the units for the preceding cell size. This is an optional parameter. If not present, the distance units from the table's coordinate system are used.

n_cells is a numeric expression that specifies the height or width of the grid in cells only.

numcells defines the number of cells to be added around the edge of the original grid bounds. numcells will be added to the left, right, top, and bottom of the original grid dimensions.

interpolator_name is a string expression specifying the name of the interpolator to use to create the grid. MapInfo built-in interpolators are "IDW" or "TIN."

version_string is a string expression specifying the version of the interpolator that the parameters are meant for. (Version 100 of the IDW interpolator shipped with MapInfo Pro 5.0 and Version 200 of the TIN and IDW interpolators shipped with MapInfo Pro 5.5 and later.)

num_parameters is a numeric expression, that specifies the number of parameter_name: parameter_value pairs to use.

  • parameter_name is a string expression, specifying the name part of this pair.
  • parameter_value is a numeric expression, specifying the value part of this pair.

Description

A grid surface theme is a continuous raster grid produced by an interpolation of point data. The Create Grid statement takes a data column from a table of points, and passes those points and their data values to an interpolator. The interpolator produces a raster grid file, which MapBasic displays as a raster table in a Map window.

The Create Grid statement reads (x, y, z) values from the table specified in the From clause. It gets the z values by evaluating the expression specified in the With clause with respect to the table.

The dimensions of the grid can be specified in two ways. One is by specifying the size of a grid cell in distance units, such as miles. The other is by specifying a minimum height or width of the grid in terms of grid cells. For example, if you wanted the grid to be at least 200 cells wide by 200 cells high, you would specify "cell min 200". Depending on the aspect ratio of the area covered by the grid, the actual grid dimensions would not be 200 by 200, but it would be at least that wide and high.

By Percent at specifies that the subsequent color:Inflection_value pairs represent a color value and Percentage value. If not used, then the Inflection_value represents a numeric value such as elevation or temperature.

For more about grids, see Grid Description. For details about specific interpolators, see IDW Interpolator, and TIN Interpolator.

Example

Open Table "C:\States.tab" Interactive
Map From States
Open Table "C:\Us_elev.tab" Interactive
Add Map Auto Layer Us_elev
set map redraw off
Set Map Layer 1 Display Off
set map redraw on

create grid 
	from Us_elev 
	with Elevation_FT 
	into "C:\Us_elev_grid" 
	clipping table States 
	inflect 5 at 
		RGB(0, 0, 255) : 13
		RGB(0, 255, 255) : 3632.5 
		RGB(0, 255, 0) : 7252 
		RGB(255, 255, 0) : 10871.5 
		RGB(255, 0, 0) : 14491 
	cell min 200
	interpolate 
		with "IDW" version "100" 
		using 4 
			"EXPONENT": "2" 
			"MAX POINTS": "25" 
			"MIN POINTS": "1" 
			"SEARCH RADIUS": "100"