Export 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

Exports a table to another file format. You can issue this statement from the MapBasic window in MapInfo Pro.

Syntax 1 (for exporting MIF/MID files, DBF files, or ASCII text files)

Export table 
	Into file_name 
	[ Type 
		{ "MIF" |
		"DBF" [ Charset char_set ] |
		"ASCII" [ Charset char_set ] [ Delimiter "d " ] [ Titles ] |
		"CSV" [ Charset char_set ] [ Titles ]
		"OGR" [ Charset char_set ] [ Driver driver_name ] 
			[ Drivercreateoptions driver_create_options ] 
			[ Layercreateoptions layer_create_options ] 
			[Background [Into Variable var_name] 
			[Calling calling_sub_with_one_param_and_errortrap]]
 } ]
	[ Overwrite ]

Syntax 2 (for exporting DXF files)

Export table 
	Into file_name 
	[ Type "DXF" ] 
	[ Overwrite ]
	[ Preserve 
		[ AttributeData ] [ Preserve ] [ MultiPolygonRgns [ As Blocks ] ] ] 
	[ { Binary | ASCII [ DecimalPlaces decimal_places ] } ]
	[ Version { 12 | 13 } ] 
	[ Transform
		( MI_x1, MI_y1 ) ( MI_x2, MI_y2 ) 
		( DXF_x1, DXF_y1 ) ( DXF_x2, DXF_y2 ) ] 

table is the name of an open table; do not use quotation marks around this name.

file_name is a string specifying the file name to contain the exported data; if the file name does not include a path, the export file is created in the current working directory.

char_set is the name of a character set; see CharSet clause.

d is a character used as a delimiter when exporting an ASCII file.

driver_name is the OGR driver name (Compulsory). https://gdal.org/drivers/vector/index.html

driver_create_options are the OGR driver creation options, specific to each OGR driver.

layer_create_options are the OGR driver layer creation options, specific to each OGR driver.

Note: For csv driver - saving regions with geometry=as_XY will give you x=0 and y=0.

Background : This token indicates that the export command will be executed on a non-blocking background thread.

Note: Background token can only be used for exporting a source table of type GPKG, OGR (TAB_DATA_FORMAT_OGR), Native or NativeX.

Into is the task id of the background task for use in TaskInfo() function.

If a Calling clause is specified, then the task handler is called asynchronously after the task is completed and MapInfo Pro is idle. The task handler accepts one numeric argument with no return type and should have an error trap in it. Parameter to the task handler is the ID of the task.

decimal_places is a small integer (from 0 to 16, default value is 6), which controls the number of decimal places used when exporting floating-point numbers in ASCII.

MI_x1, MI_y1, etc. are numbers that represent bounds coordinates in the MapInfo Pro table.

DXF_x1, DXF_y1, etc. are numbers that represent bounds coordinates in the DXF file.

Description

The Export statement copies the contents of a MapInfo table to a separate file, using a file format which other packages could then edit or import. For example, you could export the contents of a table to a DXF file, then use a CAD software package to import the DXF file. The Export statement does not alter the original table.

Specifying the File Format

The optional Type clause specifies the format of the file you want to create.

Type clause File Format Specified
Type "MIF" MapInfo Interchange File format. For information on the MIF file format, see the MapInfo Pro documentation.
Type "DXF" DXF file (a format supported by CAD packages, such as AutoCAD).
Type "DBF" dBASE file format.
Note: Map objects are not exported when you specify DBF format.
Type "ASCII" Text file format.
Note: Map objects are not exported when you specify ASCII format.
Type "CSV" Comma-delimited text file format.
Note: Map objects are not exported when you specify CSV format.
Type "OGR" A type of TAB file that uses the GDAL OGR Vector File library to read and write many file types.

If you omit the Type clause, MapInfo Pro assumes that the file extension indicates the desired file format. For example, if you specify the file name "PARCELS.DXF" MapInfo Pro creates a DXF file.

If you include the optional Overwrite keyword, MapInfo Pro creates the export file, regardless of whether a file by that name already exists. If you omit the Overwrite keyword, and the file already exists, MapInfo Pro does not overwrite the file.

Exporting ASCII Text Files

When you export a table to an ASCII or CSV text file, the text file will contain delimiters. A delimiter is a special character that separates the fields within each row of data. CSV text files automatically use a comma (,) as the delimiter. No other delimiter can be specified for CSV export.

The default delimiter for an ASCII text file is the TAB character (Chr$(9)). To specify a different delimiter, include the optional Delimiter clause. The following example uses a colon (:) as the delimiter:

Export sites Into "sitedata.txt" Type "ASCII"
	Delimiter ":" Titles

When you export to an ASCII or CSV text file, you may want to include the optional Titles keyword. If you include Titles, the first row of the text file will contain the table's column names. If you omit Titles, the column names will not be stored in the text file (which could be a problem if you intend to re-import the file later).

Exporting DXF Files

If you export a table into DXF file, using Syntax 2 as shown above, the Export statement can include the following DXF-specific clauses:

Include the Preserve AttributeData clause if you want to export the table's tabular data as attribute data in the DXF file.

Include the Preserve MultiPolygonRgns As Blocks clause if you want MapInfo Pro to export each multiple-polygon region as a DXF block entity. If you omit this clause, each polygon from a multiple-polygon region is stored separately.

Include the Binary keyword to export into a binary DXF file; or, include the ASCII keyword to export into an ASCII text DXF file. If you do not include either keyword, MapInfo Pro creates an ASCII DXF file. Binary DXF files are generally smaller, and can be processed much faster than ASCII. When you export as ASCII, you can specify the number of decimal places used to store floating-point numbers (0 to 16 decimal places; 6 is the default).

The Version 12 or Version 13 clause controls whether MapInfo Pro creates a DXF file compliant with AutoCAD 12 or 13. If you omit the clause, MapInfo Pro creates a version 12 DXF file.

Transform specifies a coordinate transformation. In the Transform clause, you specify the minimum and maximum x- and y-bounds coordinates of the MapInfo table, and then specify the minimum and maximum coordinates that you want to have in the DXF file.

Example

The following example takes an existing MapInfo table, Facility, and exports the table to a DXF file called "FACIL.DXF".

Open Table "facility"

Export facility
	Into "FACIL.DXF"
	Type "DXF" 
	Overwrite
	Preserve AttributeData 
	Preserve MultiPolygonRgns As Blocks 
	ASCII DecimalPlaces 3 
	Transform (0, 0) (1, 1) (0, 0) (1, 1)