Creates and opens a GSB file; initializes the import subsystem.
Syntax
intl pipImportInit ( pipHandle h, pstr outputFileName,
pipObjectFileInfoStruct *pFileInfo, pipImporter *imp_h );
Arguments
h
The handle returned by pipInit for the current instance of Spatial+. Input.
outputFileName
The path and filename of the Spatial+ object file to create from the imported file. Input.
*pFileInfo
Structure containing initialization information. Input.
*imp_h
The import handle returned by the function. This handle should be used by all other import functions. Output.
Return Value
PIP_OK
PIP_ERROR
Prerequisites
pipInit
Alternates
None
Notes
This function sets up the Spatial+ library to import one or more BNA,
MIF/MID, SHP, or TAB files. (See ESRI BNA Format and MapInfo® MIF/MID Format for complete descriptions of these file formats.)
The *pInfo structure contains the necessary information to initialize the import of objects to an object file. The structure is as follows:
char userData[256] | Data set by user |
intl maxHeapSize | Size of largest object (without buffer information.) |
intl maxPointCount | Number of points in largest object. |
intl maxPolygonCount | Max number of polygons in any one object. |
intl xmin, ymin, xmax, ymax | Geographic extents of the file. |
intl coordSys | PIP_COORDS_USER or PIP_COORDS_LL |
intl flags | PIP_IMPORT_BUFFERS, PIP_IMPORT_COMPRESS, etc. |
intl reserved[8] | Reserved for future use. |
These parameters are explained in detail below:
Parameter | Explanation |
---|---|
userData | This can be any data specified by the user. If this is NULL, then a standard header is applied by Spatial+. |
maxHeapSize | This parameter is not used during import and is ignored. |
maxPointCount |
This is the maximum number of points that are in any one object. Max points = 55000000. This parameter controls the memory allocated to hold the largest object. Each point requires 36 bytes with buffers or 8 bytes without. |
maxPolygonCount |
Maximum number of sub-polygons in a single object. Max polygons = 16383. Each sub-polygon requires 4 bytes. |
xmin, ymin, xmax, ymax | These parameters are not used during import and are ignored. |
coordSys |
This parameter is used to indicate which type of coordinates the points and responses will be given in. There are two possible settings: PIP_COORDS_USER—Coordinates are user defined, and Euclidean distances are returned in user units. PIP_COORDS_LL—Coordinates are in millionths of degrees, and distances are returned in feet. |
flags |
This is any combination of the following flags added together: PIP_IMPORT_BUFFERS creates buffer information in the file (and roughly triples the file's size). PIP_IMPORT_COMPRESS stores compressed information, but significantly slows processing speed. This parameter is recommended when batch speed is not an issue, such as in a real-time, interactive application. |
reserved | This parameter is reserved for future use and is ignored. |
Spatial+ has the ability to assign buffers on the fly to polygons, lines and points. However, doing so requires generating extra information when importing a file. This information makes the resulting file larger than if buffers were not used.
This function returns a pipImporter handle via a pointer. This handle should be used instead of pipHandle for all other pipImport_ functions.
Example
/* This code example demonstrates an import operation using a sample
MapInfo MIF/MID files. Only minor changes would be necessary to use
this sample to import ESRI BNA, SHP or TAB files */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pipapi.h>
int main( int argc, char **argv )
{
pipHandle h; pipObjectFileInfoStruct pFileInfo; pipImporter imp_h;
intl percent; intl line;
char name[32]; char errMsg[256]; char errDetail[256];
intl ret_val; intl completed = TRUE;
/* Define pipObjectFileInfoStruct variables */
memset( &pFileInfo, 0,
sizeof(pFileInfo)); pFileInfo.maxPointCount = 26214;
pFileInfo.maxPolygonCount = 256; pFileInfo.coordSys = PIP_COORDS_LL;
/* Initialize Spatial+ handle */
h = pipInit( 11111111, "c:\\lic\\SPATIAL.LIC" );
/* Get handle for import functions */
ret_val = pipImportInit( h, "c:\\spatial\\trade.gsb", &pInfo, &imp_h );
if(ret_val == PIP_ERROR)
{
pipErrorGet(h, errMsg, errDetail);
printf("An error has occurred: %s, %s\n", errMsg, errDetail);
return 1;
}
/* Open MIF file for importing */
ret_val = pipImportOpenMIF2( imp_h, "c:\\spatial\\trade.mif", "TradeArea", "Owner");
if(ret_val == PIP_ERROR)
{
pipErrorGet(h, errMsg, errDetail);
printf("An error has occurred: %s, %s\n", errMsg, errDetail); return 1;
}
/* Read MIF file until no more objects are found */
do
{
ret_val = pipImportRead( imp_h, name, sizeof(name), &percent, &line);
if(ret_val == PIP_ERROR)
{
if (percent < 100)
{
completed = FALSE;
}
break;
}
printf("Percent: %d\r", percent);
} while( ret_val != PIP_NOT_FOUND );
/* Done importing, close import file */
pipImportClose( imp_h );
/* Done importing, terminate import subsystem */
pipImportTerm(imp_h, completed );
/* Finished with Spatial+ processing. Free handle */
pipTerm(h);
return 0;
}