Importing from an Oracle Spatial Database

AutoCAD Map 3D ObjectARX

 
Importing from an Oracle Spatial Database
 
 
 

The following sample illustrates importing spatial data from an Oracle database to a project drawing.

The sample is in two parts. First, it defines a query to specify a condition for the objects to import, and then it imports them.

Note The sample assumes that there is an open project drawing, and that an import query has been defined already through the Import dialog box in the UI (use the MAPOSEREAD command). It also assumes that the connection object is actually connected to a database. Click "Connecting to an Oracle Database" for sample code.

Connecting to an Oracle Spatial Database

Querying and importing data

Code samples

    
#include "StdAfx.h"
#include "StdArx.h"
#include "AdMapOracleConnection.h"
#include "AdMapOracleQuery.h"
#include "AdMapOracleImport.h"
      
BOOL ImportFromOracle()
{
        
// Define Query
        
// Get connection pointer
AcMapOSEConnection *pConnection = AcMapOSEGetConnection();
        
// Declare query interface
AcmapOSEQuery *pQuery = new AcMapOSEQuery(pConnection);
        
// Initialize query interface with the current import query 
// (defined through the user interface) of an open project 
// drawing; in this case, the current project drawing
pQuery->InitWithCurrent(
acdbHostApplicationServices()->workingDatabase());
        
// Or initialize with a NULL database, which has the same 
// effect as the previous call
pQuery->InitWithCurrent();
        
// Or initialize with specific condition(s)
// Empty vector of features means query all features in the 
// Oracle database
std::vector<std::string> vFeatureNames;
pQuery->AddWhereConditionInFeatures( 
vFeatureNames,
"AdMapEntityType IS NOT NULL");
        
// You can clear the query with pQuery->Clear(),
// but not right now; we still need it
        
// Check the query with ConvertToSql()
char *psql = pQuery->ConvertToSql();
        
// Save the query to the Oracle database
pQuery->Save("MyQuery");
        
// Load the saved query into another query object
AcMapOSEQuery *pNewQuery = new AcMapOSEQuery(pConnection);
pNewQuery->Load("MyQuery");
        
// Compare old and new queries
char *pNewSql = pNewQuery->ConvertToSql();
        
if(strcmp(pSql,pNewSql) == 0)
acutPrintf("Query Load/Save works!\n");
else
acutPrintf("Query Load/Save failed!\n");
        
// Import Data
        
AcMapOSEImport *pImport = new AcMapOSEImport(pConnection);
        
// Use query defined above to import data
if(pImport->Import(pQuery))
acutPrintf("\n Import successful\n");
else
acutPrintf("\n Import failed\n");
        
delete pQuery;
delete pImport;
}