Register Table 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

The Register Table statement turns a spreadsheet, database, text file, table data in a GeoPackage, raster, or grid image into a MapInfo Pro table. This statement checks a non-native file, for example, a dBASE file, and builds a TAB file. Only then you can access the file as a MapInfo Pro table.

The Register Table statement does not change the non-native source file. It determines the data type of the columns in the file, and creates the TAB file. To open the new table, you must use the Open Table statement. Each file needs to be registered only once.

You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax

Register Table source_file { 
	Type OGR [ Table OgrTableName] [ Driver OgrDriverName] 
		[ Openoptions OgrDriverOpenOptions] [ Cache On|Off] 
		[Charset CharsetName][ Symbol...] [ Linestyle Pen(...) ] 
		[ Regionstyle Pen(...) Brush(...) ] [ Font... ] 
		[ Coordsys... ] [ into destination_file ]
	Type NATIVE |
	Type DBF [ Charset char_set ] |
	Type ASCII [ Delimiter delim_char ] [ Titles ] 
		[ CharSet char_set ] | 
	Type WKS [ Titles ] [ Range range_name ] |
	Type WMS Coordsys... |
	Type WFS [ Charset char_set ] Coordsys... [ Symbol... ] 
		[ Linestyle Pen(...) ] [ Regionstyle Pen(...) Brush(...) ]
		[Editable] |
	Type XLS [ Charset char_set ] [ Titles ] [ Range range_name ] [ Interactive ] | 
	Type ACCESS Table table_name 
		[ Password pwd ] [ CharSet char_set ] |
	Type ODBC
		Connection { Handle connection_number | connection_string } 
		Toolkit toolkit_name 
		[ Charset char_set ]
		[ Cache { ON | OFF } [ Type { NATIVE | NATIVEX } ] ]
		[ Autokey { ON | OFF } ]
		Table SQLQuery
		[ Versioned { ON | OFF } ]
		[ Workspace Workspace_name ]
		[ ParentWorkspace ParentWorkspace_name ]
		[ Symbol... ] [ Linestyle Pen(...) ]
		[ Regionstyle Pen(...) Brush(...) ] |
	Type GRID | Type RASTER
		[ ControlPoints ( MapX1, MapY1 ) ( RasterX1, RasterY1 ), 
			( MapX2, MapY2 ) ( RasterX2, RasterY2 ),
			( MapX3, MapY3 ) ( RasterX3, RasterY3 )
			[ , ... ] ]
		[ CoordSys... ] 
		[ Charset char_set ] |
	Type FME [ Charset char_set ] 
		CoordSys... 
		Format format_type 
		Schema feature_type 
		[ Use Color ]
		[ Database ]
		[ SingleFile ]
		[ Symbol...]
		[ Linestyle Pen(...) ] 
		[ Regionstyle Pen(...) Brush(...) ] 	
		[ Font... ]
		Settings string1 [ , string2 .. ]  |
	Type SHAPEFILE [ Charset char_set ] CoordSys Auto
		[ PersistentCache { ON | OFF } [ Type { NATIVE | NATIVEX } ] ]
		[ Symbol...] [ Linestyle Pen(...) ] 
		[ Regionstyle Pen(...) Brush(...) ]
	Type GPKG
		[ Table GeoPackageTableName ]
		[ Symbol...] [ Linestyle Pen(...) ] 
		[ Regionstyle Pen(...) Brush(...) ]
		[ Font... ]
		[ Coordsys... ]
		[ into destination_file ]
	}
	[ ReadOnly ]

OgrTableName is the name of the OGR layer in the OGR dataset to register. If not specified, the first table in the OGR dataset is opened.

OgrDriverName: is the name of the OGR driver which will be used to open this table. If not specified, MapInfo Pro uses the best available driver. List of drivers - https://gdal.org/drivers/vector/index.html

OgrDriverOpenOptions are the Ogr Driver open options applied to the dataset while opening.

Cache: This turns on or off object caching for an OGR table. Using caching improves the redraw performance of the dataset.

CharsetName is the name of a character set. For details, see the CharSet clause. If not specified, then the UTF-8 charset is used.

source_file is a string that represents the name of an existing database, spreadsheet, text file, raster, or grid image. If you are registering an Access table, this argument must identify a valid Access database.

char_set is the name of a character set; see CharSet clause. If not specified, then the system character set is used.

delim_char specifies the character used as a column delimiter. If the file uses Tab as the delimiter, specify 9. If the file uses commas, specify 44.

range_name is a string indicating a named range (for WKS files) or a cell range (for XLS files). For example, an Excel range can be specified as "Sheet1!R1C1:R9C6" or as "Sheet1!A1:F9".

table_name is a string that identifies an Access table.

pwd is the database-level password for the database, to be specified when database security is turned on.

connection_number is an integer value that identifies an existing connection to an ODBC database.

connection_string is a string used to connect to a database server. See Server_ConnectInfo() function.

toolkit_name is "ODBC" or "ORAINET."

Workspace_name is the name of the current workspace in which the table will be operated. The name is case sensitive.

ParentWorkspace_name is the name of parent workspace of the current workspace.

format_type format type is a string that is used by FME to identify format that is opened.

feature_type specifies a feature type (essentially schema name).

string1 [ , string2 .. ] are Safe Software FME-specific settings that vary depending upon the format and settings options the user selects.

GeoPackageTableName is the name of the table within a GeoPackage file. A GeoPackage file may contain more than one table.

destination_file specifies the name to give to the MapInfo table (.TAB file). This string may include a path; if it does not include a path, the file is built in the same directory as the source file.

Description

Before you can use a non-native file (for example, a dBASE file) in MapInfo, you must register the file. The Register Table statement tells MapInfo Pro to examine a non-native file (for example, FILENAME.DBF) and build a corresponding table file (filename.TAB). Once the Register Table operation has built a table file, you can access the file as an MapInfo table.

The Register Table statement does not copy or alter the original data file. Instead, it scans the data, determines the datatypes of the columns, and creates a separate table file. The table is not opened automatically. To open the table, use an Open Table statement.

Note: Each data file need only be registered once. Once the Register Table operation has built the appropriate table file, subsequent MapInfo Pro sessions simply Open the table, rather than repeat the Register Table operation.

The Type clause specifies where the file came from originally. This consists of the keyword Type, followed by one of the following character constants: NATIVE, NATIVEX, DBF, ASCII, WKS, WMS, WFS, XLS, ACCESS, ODBC, GRID, RASTER, FME, SHAPEFILE, or GPKG. The other information is necessary for preparing certain types of tables. If the type of file being registered is a grid, the CoordSys string is read from the grid file and a MapInfo .TAB file is created. If a raster file is being registered, the .TAB file that is generated is the same as if the user selected "Display" when opening a raster image from the Open dialog box.

Using Cache after the Type clause sets the live cache type for an ODBC table to MapInfo TAB format (NATIVE) or MapInfo Extended TAB format (NATIVEX). If not specified, then the NATIVE type is used.

If the type of file being registered is XLS, the character set specifies the encoding to use for writing the .tab file. To allow Unicode paths or filenames for the excel file or to allow Unicode characters in the sheet names or ranges, the character set should be UTF-8.

If the type of file being registered is a GRID, the CoordSys string is read from the grid file and a MapInfo .TAB file is created. If a raster file is being registered, the .TAB file that is generated depends upon if georegistration information can be found in the image file or associated World file. If the type of file is RASTER, then the character set specifies the encoding to use for writing the .tab file. To allow Unicode paths or filenames for the raster image, the character set should be UTF-8.

The CharSet clause specifies a character set. The char_set parameter should be a string such as "WindowsLatin1". If you omit the CharSet clause, MapInfo Pro uses the system character set. See CharSet clause for more information.

The Delimiter clause is followed by a string containing the delimiter character. The default delimiter is a TAB. The Titles clause indicates that the row before the range of data in the worksheet should be used as column titles. The Range clause allows to specify a worksheet in a XLS file that you are registering, or a named range can be specified for a WKS file type. The into clause is used to override the table name or location of the .TAB file. By default, it will be named the same as the data file, and stored in the same directory. However, when reading a read-only device such as a DVD, you need to store the .TAB file on a volume that is not read-only.

ControlPoints is optional, but can be specified if the type is Grid or Raster. If the ControlPoints keyword is specified, it must be followed by at least 3 pairs of Map and Raster coordinates which are used to georegister an image. If the ControlPoints are specified, they will override and replace any control points associated with the image or an associated World file.

Interactive is optional for XLS, Grid, or Raster types. Specifying this for Grid or Raster types prompts the user for any missing control point or projection information. Not specifying this generates a .TAB file without user input, as when the user selects "Display" when opening a raster image from the Open dialog box. Interactive is not a valid parameter for registering shape (SHP) files.

Note: Specifying the Interactive keyword for the XLS type, instructs the interface to display the Set Field Properties window when importing Excel files.

The CoordSys clause is required for WMS and Shapefiles, the compiler indicates an error if it is missing. For other types, the CoordSys clause is optional. If CoordSys is specified, it overrides and replaces any coordinate system associated with the image. This is useful when registering a raster image that has an associated World file. For details, see CoordSys clause. The CoordSys supplied must be used by the input SHP file. Register Table will not re-project the input SHP file to a different coordinate system. If the source SHP file was created in a UTM Zone 18 (NAD83) coordinate system as an example, then the Register Table statement, or the Open dialog for opening a SHP file, must specify this same coordinate system to open the SHP file correctly.

Use the Auto token when the Shapefile dataset has a .PRJ file, rather than specifying the coordinate system in the statement. If the .PRJ file does not exist or the coordinate system does not convert to a MapInfo coordinate system, the command fails and the application posts an error message.

The Symbol clause sets the symbol style to use for a point object created from a shapefile, see Symbol clause.

The LineStyle clause sets a line style for line object types.

The Pen clause sets the line style to use for a line object type created from a shapefile, see Pen clause.

The Regionstyle clause sets the line style and fill style for region object types created from a shapefile, see the Pen clause and Brush clause.

If Autokey is set ON, the table is registered with key auto-increment option. If Autokey is set OFF or this option is ignored, the table is registered without key auto-increment.

SQLQuery is the SQL query used to define the MapInfo table.

Versioned indicates if the table to be opened is a version-enabled (ON) table or not (OFF).

Use the Use and Color clauses to use color information from the dataset.

Use the Database clause to specifies if the referenced datasource is from a database.

Use the SingleFile clause to specify that the referenced datasource consist of a single file.

Setting PersistentCache to ON, saves .MAP and .ID files from open Shapefiles when closing a table. Setting PersistentCache to OFF, deletes .MAP and .ID files when closing a table (they are generated each time the table opens).

You can set PersistentCache cache for shape files (SHAPEFILE clause) as MapInfo (NATIVE) or MapInfo Extended (NATIVEX) table types. If not set, this defaults to NATIVE. Tables that are not MapInfo or MapInfo Extended TAB files error. If the shape file character set is UTF-8, then only the NATIVEX cache type is allowed. The type clause for persistent cache is location dependent and must be used after the PersistentCache {ON|OFF} clause.

The ReadOnly clause indicates that the table cannot be edited.

Registering Access Tables

When you register an Access table, MapInfo Pro checks for a counter column with a unique index. If there is already a counter column, MapInfo Pro registers that column in the .TAB file. The column is read-only.

If the Access table does not have a counter column, MapInfo Pro modifies the Access table by adding a column called MAPINFO_ID with the counter datatype. In this case, the counter column does not display in MapInfo.

Note: Do not alter the counter column in any way. It must be exclusively maintained automatically by MapInfo Pro.

Access datatypes are translated into the closest MapInfo datatypes. Special Access datatypes, such as OLE objects and binary fields, are not editable in MapInfo Pro.

Registering ODBC Tables

Before accessing a table live from a remote database, it is highly recommended that you first open a map table (for example, CANADA.TAB) for the database table. If you do not open a map table, the entire database table will be downloaded all at once, which could take a long time.

Open a map table and zoom in to an area that corresponds to a subset of rows you wish to see from the database table. For example, if you want to download rows pertaining to Ontario, zoom in to Ontario on the map. As a result, when you open the database table, only rows within the map window's MBR (minimum bounding rectangle), in this case Ontario, will be downloaded.

The following is a list of known problems/issues with live access:

  • Every table must have a single unique key column.
  • FastEdit is not supported.
  • With MS ACCESS if the key is character, it does not display rows where the key value is less than the full column width for example, if the key is char(5) the value 'aaaa' will look like a deleted row.
  • For Live Access, the ReadOnly checkbox on the save table dialog box is grayed out.
  • Changes made by another user are not visible until a browser is scrolled or somehow refreshed. Inserts by another user are not seen until either: 1). An MBR search returns the row or 2). PACK command is issued in addition if cache is on another users updates may not appear until the cache is invalidated by a pan or zooming out.
  • There will be a problem if a client-side join (through the SQL Select menu item or MapBasic) is done against two or more SPATIALWARE tables that are stored in different coordinate systems. This is not an efficient thing to do (it is better to do the join in the SQL statement that defines the table) but it is a problem in the current build.
  • Oracle 7 tables that are indexed on a decimal field larger than 8 bytes will cause MapInfo Pro to crash when editing.
  • If the server is Oracle, Autokey is the indicator to tell if the new feature, key auto-increment, will be used or not.
  • If the Cache OFF statement is before the connection string an error will be generated at compile time.

Registering Shapefiles

When you register shapefiles, they can be opened in MapInfo Pro with read-only access. Since a shapefile itself does not contain projection information, you must specify a CoordSys clause. It is also possible to set styles that will be used when shapefile objects are displayed in MapInfo Pro. Projection and style information is stored as metadata in the TAB file.

Note: Interactive is not a valid parameter to use when registering SHP files.

Example: OGR

Register Table "C:\Downloads\OGRData\GB\GB.csv"  
	TYPE "OGR"  TABLE "GB"  DRIVER "CSV" 
	OpenOptions "AUTODETECT_TYPE=YES;KEEP_GEOM_COLUMNS=NO"  
	CoordSys Earth Projection 1, 0  Charset "UTF-8"  Cache On  
	Symbol (67,16776960,18)
	Into "C:\Downloads\OGRData\GB\GB.tab"

Example: DBF

Register Table "c:\mapinfo\data\rpt23.dbf"
	Type DBF
	Into "Report23" 

Open Table "c:\mapinfo\data\Report23"

Example: ODBC

Open Table "C:\Data\CANADA\Canada.tab" Interactive
Map From Canada
set map redraw off
Set Map Zoom 1000 Units "mi"
set map redraw on
Register Table "odbc_cancaps" 
	TYPE ODBC 
	TABLE "Select * From schemaname.can_caps" 
	CONNECTION 
		DSN=dsnname;UID=username;PWD=password;DATABASE=dbname
		SERVER=servername
	Into 
		"D:\MI\odbc_cancaps.TAB"
Open Table "D:\MI\odbc_cancaps.TAB" Interactive
Map From odbc_cancaps

Example: RASTER

Registering a completely georeferenced raster image (the raster handler can return at least three control points and a projection).

Register Table "GeoRef.tif" type RASTER into "GeoRef.TAB"

Registering a raster image that has an associated World file containing control point information, but no projection.

Register Table "RasterWithWorld.tif" type RASTER coordsys earth projection 
9, 62, "m", -96, 23, 29.5, 45.5, 0, 0 into "RasterWithWorld.TAB"

Registering a raster image that has no control point or projection information.

Register Table "NoRegistration.BMP" type RASTER controlpoints (1000,2000) 
(1,2), (2000,3000) (2, 3), (5000,6000) (5,6) coordsys earth projection 9, 
62, "m", -96, 23, 29.5, 45.5, 0, 0 into "NoRegistration.tab"

Example: SHAPEFILE

The following example registers a shapefile.

Register Table "C:\Shapefiles\CNTYLN.SHP" TYPE SHAPEFILE Charset 
"WindowsLatin1" CoordSys Earth Projection 1, 33 PersistentCache Off 
linestyle Pen (2,26,16711935) Into "C:\Temp\CNTYLN.TAB"
Open Table "C:\Temp\CNTYLN.TAB" Interactive 
Map From CNTYLN

Example: ODBC

The following example creates a tab file and then opens the tab file.

Register Table "SMALLINTEGER"  TYPE ODBC 
	TABLE "Select *  From ""MIPRO"".""SMALLINTEGER""" 
	CONNECTION "SRVR=scout;UID=mipro;PWD=mipro " 
	toolkit  "ORAINET"
	Autokey ON
	Into
	"C:\projects\data\testscripts\english\remote\SmallIntEGER.TAB"
Open Table "C:\Projects\Data\TestScripts\English\remote\SmallIntEGER.TAB" 
Interactive
Map From SMALLINTEGER

The following example creates a tab file and then opens the tab file. This example uses a workspace.

Register Table "Gwmusa" TYPE ODBC 
	 TABLE "Select * From ""MIUSER"".""GWMUSA""" 
	 CONNECTION "SRVR=troyny;UID=miuser;PWD=miuser"
	 toolkit "ORAINET"
	 Versioned On
	 Workspace "MIUSER"
	 ParentWorkspace "LIVE"
	 Into "C:\projects\data\testscripts\english\remote\Gwmusa.tab"
Open Table "C:\Projects\Data\TestScripts\English\remote\Gwmusa.TAB"
Interactive Map From Gwmusa

Example: FME (Universal Data)

Register Table "D:\MUT\DWG\Data\africa_miller.DWG" Type FME
	CoordSys Earth Projection 11, 104, "m", 0 Format "ACAD"
	Schema "africa_miller" Use Color SingleFile Symbol (35,0,16) 
	Linestyle Pen (1,2,0) RegionStyle Pen (1,2,0)
	Brush (2,16777215,16777215) Font ("Arial",0,9,0)
	Settings "RUNTIME_MACROS", "METAFILE,acad,_EXPAND_BLOCKS,yes,ACAD_IN_USE_BLOCK_HEAD
	ER_LAYER,yes,ACAD_IN_RESOLVE_ENTITY_COLOR,yes,_EXPAND_VISIBLE,yes,_BULGES
	_AS_ARCS,no,_STORE_BULGE_INFO,no,_READ_PAPER_SPACE,no,ACAD_IN_READ_GROUPS
	,no,_IGNORE_UCS,no,_ACADPreserveComplexHatches,no,_MERGE_SCHEMAS,YES", 
	"META_MACROS", "Source_EXPAND_BLOCKS,yes,SourceACAD_IN_USE_BLOCK_HEADER_LA
	YER,yes,SourceACAD_IN_RESOLVE_ENTITY_COLOR,yes,Source_EXPAND_VISIBLE,yes,
	Source_BULGES_AS_ARCS,no,Source_STORE_BULGE_INFO,no,Source_READ_PAPER_SPA
	CE,no,SourceACAD_IN_READ_GROUPS,no,Source_IGNORE_UCS,no,Source_ACADPreser
	veComplexHatches,no", "METAFILE", "acad", "COORDSYS", "", "IDLIST", ""
	Into "C:\Temp\africa_miller.tab"
Open table  "C:\Temp\africa_miller.tab"
Map From "africa_miller"

Example: GPKG (GeoPackage)

Register Table "D:\Maps\gpkg\asia.gpkg" Type GPKG
	Table "asia_regions"
	Symbol (35,0,16)  Linestyle Pen (1,2,0)
	RegionStyle Pen (1,2,0) Brush (2,16777215,16777215) 
	Font ("Arial",0,9,0)
	Into "D:\Maps\gpkg\asia.tab"