SuperMap iObjects C++ workspace, data source, dataset management

Author: Xian

1. Background

  SuperMap iObjects C++It is the basic kernel of the SuperMap GIS series software, which is developed using standard C++ and integrates SuperMap's high-performance, cross-platform technology. Provide users with basic GIS functions in the form of C++ API.

  Although the iObjects C++ component has high performance, the development example DEMO provided in the iObjects C++ component is less than that of the iObjects .NET / Java component. It is difficult for customers to develop iObjects C++ components, so this tutorial and the corresponding sample DEMO are provided for reference.

  This tutorial is based on SuperMap iObjects C++11i components to implement workspace , data source, and dataset management functions, including: new workspace, open, save, save, close; data source new, open, save, close; point, line, surface, 3D point, 3D line, 3D surface, CAD, model, raster, image, attribute table and other datasets can be created and closed.

  These features are part of the iObjects C++Core Components module, so only the Core Components license is required for proper use. iObjects C++Component license module details are as follows:
iObjects C++ license module comparison table.png

2. Development environment configuration

2.1. Development environment dependencies

Software Products Version download link Remark
SuperMap iObjects C++ 11i SuperMap iObjects C++ 11i download address It is recommended to use SuperMap iObjects C++ 11i version components
Visual Studio 2022 Visual Studio 2022 Community Edition Download Address When installing Visual Studio 2022, you need to follow the C++ library

2.2. Build MFC project

  • Create MFC applications from Visual Studio 2022 Community Edition Visual Studio 2022 New MFC Application.png

  • Create a dialog- based MFC , select the application type , and click Finish Create a dialog-based MFC application.png

  After the above two steps are completed, the simplest MFC application program has been successfully created. Next, it is necessary to further configure the component development environment dependencies on the created MFCSuperMap iObjects C++ 11i application program .

2.3. Configure iObjects C++ 11i component development environment dependencies

  • Configure the C/C++ environment

    • Add the iObjects C++ directory\include and iObjects C++ directory\include\private directory to the C/C++ Additional Include Directories itemConfigure MFC additional include directory.png

    • Configure _UGUNICODE to C/C++ "preprocessor definition itemConfigure MFC preprocessor definition.png

    • Configure WChar_t as a built-in type in the language item of C/C++Treat WChar_t as a built-in type.png

    • Add /bigobj to the C/C++" command line itemConfigure MFC command line.png

  • Configure linker environment

    • Add the iObjects C++ directory\lib\lib_x64 to the Linker >Additional Library Directories itemConfigure MFC additional library directory.png

    • Add the following library files to the Linker "Additional Dependencies" item

      SuAllocation.lib
      SuAnalyst3D.lib
      SuAnimation.lib
      SuBase.lib
      SuBase3D.lib
      SuBGDataCompiler.lib
      SuBPlusTree.lib
      SuCacheBuilder.lib
      SuCacheBuilder3D.lib
      SuCacheFile.lib
      SuChartBase.lib
      SuChartToolkit.lib
      SuCompactFile.lib
      SuCVToolkit.lib
      SuDataCheck.lib
      SuDataExchange.lib
      SuDB2CI.lib
      SuDCPackager.lib
      SuDCToolkits.lib
      SuDrawing.lib
      SuDrawing3D.lib
      SuDrawingLayout.lib
      SuElement.lib
      SuEngine.lib
      SuEngineBaiduMaps.lib
      SuEngineBingMaps.lib
      SuEngineDB2.lib
      SuEngineES.lib
      SuEngineExtendFile.lib
      SuEngineGanos.lib
      SuEngineGaoDeMaps.lib
      SuEngineGBase.lib
      SuEngineGoogleMaps.lib
      SuEngineImagePlugin.lib
      SuEngineMapWorldMaps.lib
      SuEngineMySQL.lib
      SuEngineODBC.lib
      SuEngineOGC.lib
      SuEngineOGDC.lib
      SuEngineOpenStreetMaps.lib
      SuEngineOracle.lib
      SuEnginePG.lib
      SuEnginePGis.lib
      SuEngineRest.lib
      SuEngineSCV.lib
      SuEngineSMCloud.lib
      SuEngineSpatialite.lib
      SuEngineSQLPLUS.lib
      SuEngineSsp.lib
      SuEngineUDB.lib
      SuEngineXYZTile.lib
      SuFileParser.lib
      SuFileParser3DModel.lib
      SuFileParser3ds.lib
      SuFileParserAcad.lib
      SuFileParserBitMap.lib
      SuFileParserCSV.lib
      SuFileParserDEM.lib
      SuFileParserE00.lib
      SuFileParserENC.lib
      SuFileParserFME.lib
      SuFileParserGDAL.lib
      SuFileParserKML.lib
      SuFileParserLidar.lib
      SuFileParserMAPGIS.lib
      SuFileParserMitab.lib
      SuFileParserNetCDF.lib
      SuFileParserOGR.lib
      SuFileParserPointCloud.lib
      SuFileParserRAW.lib
      SuFileParserS3MB.lib
      SuFileParserSCV.lib
      SuFileParserSGM.lib
      SuFileParserTEMS.lib
      SuFMELicense.lib
      SuGeneralization.lib
      SuGeoCode.lib
      SuGeometricNetwork.lib
      SuGeometry.lib
      SuGeometry3D.lib
      SuGeometryCAD.lib
      SuGeometryConverter.lib
      SuGeometryLayout.lib
      SuGeometryPlot.lib
      SuGeoOperation.lib
      SuGeoOperation3D.lib
      SuGraphics.lib
      SuGraphics3D.lib
      SuGraphics3DGameEngine.lib
      SuGraphics3DOGRE.lib
      SuGraphicsPDF.lib
      SuGraphicsPS.lib
      SuGraphicsW.lib
      SuGridAnalyst.lib
      SuGridAnalystOpenCL.lib
      SuGridModeling.lib
      SuLayer3DDataset.lib
      SuLayer3DDatasetModel.lib
      SuLayer3DFile.lib
      SuLayer3DMap.lib
      SuLayer3DTree.lib
      SuLayoutEditor.lib
      SuLinearReference.lib
      SuLogistics.lib
      SuMap.lib
      SuMapEditor.lib
      SuMapMatching.lib
      SuMapServiceStub.lib
      SuMGAnimationExp.lib
      SuMGAuxiliaryPlotting.lib
      SuMGCommon.lib
      SuMGMapData.lib
      SuMGMovingTarget.lib
      SuMGObjects.lib
      SuMGSituation.lib
      SuMGSituationMonitor.lib
      SuMGSituationSimulation.lib
      SuMongoCI.lib
      SuMosaic.lib
      SuMosaicOpenCV.lib
      SuMySQLCI.lib
      SuNetToolkit.lib
      SuNetworkBuilder.lib
      SuNetworkEnvironment.lib
      SuNTopoDataCompiler.lib
      SuNTopoIndexTree.lib
      SuODBCCI.lib
      SuOGCParser.lib
      SuOGDC.lib
      SuOracleCI.lib
      SuOverlay.lib
      SuParticleSystem.lib
      SuPathAnalyst.lib
      SuPathAnalystCH.lib
      SuPathNavi.lib
      SuPluginCommon.lib
      SuPluginGECache.lib
      SuPluginGlobalCache.lib
      SuPluginGridCache.lib
      SuPluginMapCache.lib
      SuPluginMapCache50.lib
      SuPluginWebCache.lib
      SuPostgreSQLCI.lib
      SuProjection.lib
      SuProjectionProj.lib
      SuProjectionWKT.lib
      SuProximity.lib
      SuPublicTransport.lib
      SuRasterData.lib
      SuRectify.lib
      SuRender.lib
      SuRepresentation.lib
      SuRStarTree.lib
      SuScene.lib
      SuSceneEditor.lib
      SuSpatialIndex.lib
      SuSpatialQuery.lib
      SuSQLiteCI.lib
      SuStream.lib
      SuSymbol.lib
      SuSymbolAlgo1.lib
      SuSymbolAlgo2.lib
      SuSymbolAlgo3.lib
      SuSymbolAlgo4.lib
      SuSymbolAlgo5.lib
      SuSymbolAlgo6.lib
      SuSymbolAlgo7.lib
      SuSymbolExchange.lib
      SuSymbolMarker3D.lib
      SuTheme3DBase.lib
      SuTileStorage.lib
      SuToolkit.lib
      SuToolkit3D.lib
      SuToolkitPointCloud.lib
      SuToolkitVDB.lib
      SuTopoBase.lib
      SuTopoBuilder.lib
      SuVRDevices.lib
      SuWorkspace.lib
      SuWrapc.lib
      SuAlgorithm.lib
      SuAlgorithm3D.lib
      

Configure MFC additional dependencies.png

  Here, for convenience SuperMap iObjects C++, all the dependencies of are directly added to the MFC application dependencies. If you feel SuperMap iObjects C++that there are too many dependencies , you can add some dependencies .

3. Function realization

  Next is the core function call interface and implementation logic of workspace, data source, and dataset management. For specific code implementation, please refer to the following implementation code directly.

3.1. Open the workspace

  The operation of opening a workspace mainly includes two steps: 1. Construct the workspace connection information (workspace path, version, type and name); 2. Open the pointed workspace according to the constructed workspace connection information. Detailed coding can refer to the following implementation:

// 构建工作空间连接信息
UGWorkspaceConnection workspaceConnection = UGWorkspaceConnection();
workspaceConnection.m_strServer = workspaceFilePath;
workspaceConnection.m_nVersion = UG_WORKSPACE_VERSION_20120328;
workspaceConnection.m_nWorkspaceType = GetWorkspaceType(workspaceFileExt);
workspaceConnection.m_bFailIfExists = false;
workspaceConnection.m_strWorkspaceName = workspaceFileName;

// 打开工作空间
m_workspace = new UGWorkspace();
if (m_workspace->Open(workspaceConnection))
{
    
    
    m_workspace->SetName(workspaceConnection.m_strWorkspaceName);
    m_workspace->SetCaption(workspaceConnection.m_strWorkspaceName);
}

3.2. Save workspace as another

  The operation process of saving a workspace is the same as that of opening a workspace. For detailed coding, please refer to the following implementation:

// 构建工作空间连接信息
UGWorkspaceConnection workspaceConnection = UGWorkspaceConnection();
workspaceConnection.m_strServer = workspaceFilePath;
workspaceConnection.m_nVersion = UG_WORKSPACE_VERSION_20120328;
workspaceConnection.m_nWorkspaceType = GetWorkspaceType(workspaceFileExt);
workspaceConnection.m_bFailIfExists = false;
workspaceConnection.m_strWorkspaceName = workspaceFileName;

m_workspace->SetName(workspaceConnection.m_strWorkspaceName);
m_workspace->SetCaption(workspaceConnection.m_strWorkspaceName);

// 另存工作空间
if (m_workspace->SaveAs(workspaceConnection)) {
    
    }

3.3. Create a new file-type data source

  To create a new file-type data source, you need to specify the file path, file alias, and data source type. Among them, UGEngineType::Spatialite corresponds to the UDBX file-type data source, and UGEngineType::UDB corresponds to the UDB file-type data source. It is recommended to set the appropriate data source type according to actual needs .

  Note: When obtaining the data source connection information, you need to obtain its reference, otherwise the connection information inside the data source object cannot be modified correctly, which will cause the execution failure when creating a new data source.

// 构建数据源信息
UGDataSource* datasource = UGDataSourceManager::CreateDataSource(UGEngineType::Spatialite);
UGDsConnection& dsConn = datasource->GetConnectionInfo();
dsConn.m_strServer = filePath;
dsConn.m_strAlias = fileTitle;
dsConn.m_nType = UGEngineType::Spatialite;

// 新建数据源
if (!datasource->Create())
{
    
    
  datasource->Close();
  delete datasource;
}
else
{
    
    
  // 数据源新建成功,添加到当前工作空间中
  if (!m_workspace->m_DataSources.Insert(dsConn.m_strAlias, datasource) || !m_workspace->Save()) {
    
    }
}

3.4. Open file data source

  The operation process of opening a file-type data source is the same as that of creating a new file-type data source. For detailed coding, please refer to the following implementation:

// 构建数据源信息
UGDataSource* datasource = UGDataSourceManager::CreateDataSource(UGEngineType::Spatialite);
UGDsConnection& dsConn = datasource->GetConnectionInfo();
dsConn.m_strServer = filePath;
dsConn.m_strAlias = fileTitle;
dsConn.m_nType = UGEngineType::Spatialite;

// 打开数据源
if (!datasource->Open())
{
    
    
  datasource->Close();
  delete datasource;
}
else
{
    
    
  // 数据源打开成功,添加到当前工作空间中
  if (!m_workspace->m_DataSources.Insert(dsConn.m_strAlias, datasource) || !m_workspace->Save()) {
    
    }
}

3.5. Create a new vector dataset

  The operation process of creating a new vector dataset is the same, only the dataset type is different, so the following interfaces are simply encapsulated to reuse and create different types of vector datasets, including: 2D point ( UGC::UGDataset:: Point ), 2D line ( UGC::UGDataset::Line ), 2D area ( UGC::UGDataset::Region ), 3D point ( UGC::UGDataset::PointZ ), 3D line ( UGC::UGDataset::LineZ ), 3D surface ( UGC::UGDataset::RegionZ ), model ( UGC::UGDataset::Model ), CAD ( UGC::UGDataset::CAD ), attribute table ( UGC::UGDataset::Tabular ), etc.

/// <summary>
/// 创建矢量数据集
/// </summary>
/// <param name="workspace">工作空间</param>
/// <param name="datasetType">数据集类型</param>
/// <param name="datasetName">数据集名称</param>
/// <returns>是否创建成功</returns>
UGbool CWDDManagerDlg::CreateDefaultDatasetVector(UGWorkspace* workspace, UGDataset::DatasetType datasetType, std::string datasetName)
{
    
    
  UGbool isCreated = FALSE;
  int datasourcesCount = workspace->m_DataSources.GetCount();
  if (datasourcesCount > 0)
  {
    
    
    UGString datasourceAlias;
    UGDataSource* datasource;
    if (workspace->m_DataSources.GetAt(0, datasourceAlias, datasource) && datasource != nullptr)
    {
    
    
      // 获取可用的数据集名称
      UGString strName;
      strName = GetAvailableDatasetName(datasource, strName.FromStd(datasetName));

      // 构建矢量数据集信息
      UGDatasetVectorInfo datasetVectorInfo;
      datasetVectorInfo.m_strName = strName;
      datasetVectorInfo.m_strTableName = strName;
      datasetVectorInfo.m_nCodecType = UGDataCodec::CodecType::envNONE;
      datasetVectorInfo.m_nSmIDType = UGDataset::SmIDType::INT64;
      datasetVectorInfo.m_nType = datasetType;

      // 根据矢量数据集信息新建矢量数据集
      UGDatasetVectorPtr datasetVector = datasource->CreateDatasetVector(datasetVectorInfo);
      if (datasetVector == nullptr)
      {
    
    
        return isCreated;
      }
      else
      {
    
    
        isCreated = TRUE;
      }
    }
  }
  return isCreated;
}

3.6. Create a new raster dataset

  Creating a new raster dataset is similar to creating a new vector dataset. The following interfaces can be encapsulated to build simple single-band raster ( UGC::UGDataset::Grid ) and image ( UGC::UGDataset::Image ) datasets.

/// <summary>
/// 创建栅格数据集
/// </summary>
/// <param name="workspace">工作空间</param>
/// <param name="datasetType">数据集类型</param>
/// <param name="datasetName">数据集名称</param>
/// <returns>是否创建成功</returns>
UGbool CWDDManagerDlg::CreateDefaultDatasetRaster(UGWorkspace* workspace, UGDataset::DatasetType datasetType, std::string datasetName)
{
    
    
  UGbool isCreated = FALSE;
  int datasourcesCount = workspace->m_DataSources.GetCount();
  if (datasourcesCount > 0)
  {
    
    
    UGString datasourceAlias;
    UGDataSource* datasource;
    if (workspace->m_DataSources.GetAt(0, datasourceAlias, datasource) && datasource != nullptr)
    {
    
    
      // 获取可用的数据集名称
      UGString strName;
      strName = GetAvailableDatasetName(datasource, strName.FromStd(datasetName));

      // 构建栅格数据集信息
      UGDatasetRasterInfo datasetRasterInfo;
      datasetRasterInfo.m_strName = strName;
      datasetRasterInfo.m_strTableName = strName;
      datasetRasterInfo.m_rc2Bounds = UGRect2D(-200.0, -200.0, 200.0, 200.0);
      datasetRasterInfo.m_eBlockSize = UGDatasetRasterInfo::IBSizeOption::IBS_64;
      datasetRasterInfo.m_nHeight = 800;
      datasetRasterInfo.m_nWidth = 800;
      datasetRasterInfo.m_nType = datasetType;
      datasetRasterInfo.SetPixelFormat(OGDC::PixelFormat::IPF_DOUBLE);
      datasetRasterInfo.SetNoValue(-9999.0);

      // 构建栅格波段信息
      UGBandInfo bandInfo;
      bandInfo.m_bAvail = TRUE;
      bandInfo.m_dMaxZ = 10000.0;
      bandInfo.m_dMinZ = -1000.0;
      bandInfo.m_nBandID = 1;
      bandInfo.m_nIndex = 1;
      bandInfo.m_nCodecType = UGDataCodec::CodecType::enrNONE;
      bandInfo.SetPixelFormat(OGDC::PixelFormat::IPF_DOUBLE);
      bandInfo.SetNoValue(-9999.0);
      datasetRasterInfo.Add(bandInfo);

      // 根据栅格数据集信息新建栅格数据集
      UGDatasetRasterPtr datasetRaster = datasource->CreateDatasetRaster(datasetRasterInfo);
      if (datasetRaster == nullptr)
      {
    
    
        return isCreated;
      }
      else
      {
    
    
        isCreated = TRUE;
      }
    }
  }
  return isCreated;
}

3.7. Closing the dataset

  When closing a dataset, you need to perform two steps: 1. Close the dataset itself; 2. Remove the dataset from the data source where the dataset needs to be closed. After the execution of these two steps is completed, the data set is completely closed.

  Note: It is recommended to call the data source compression interface (Compact) after closing the dataset, otherwise the file size occupied by the current data source on disk will not be refreshed, and the file size before closing the dataset will still be retained.

/// <summary>
/// 关闭数据集
/// </summary>
/// <param name="workspace">工作空间</param>
/// <param name="datasetType">数据集类型</param>
/// <returns>是否关闭成功</returns>
UGbool CWDDManagerDlg::CloseDataset(UGWorkspace* workspace, UGDataset::DatasetType datasetType)
{
    
    
  if (IsExistedDataset(workspace, datasetType))
  {
    
    
    UGbool isDeleted = FALSE;
    UGint datasourcesCount = workspace->m_DataSources.GetCount();
    for (size_t i = 0; i < datasourcesCount; i++)
    {
    
    
      UGString datasourceAlias;
      UGDataSource* datasource;
      if (workspace->m_DataSources.GetAt(0, datasourceAlias, datasource) && datasource != nullptr)
      {
    
    
        UGint datasetCount = datasource->GetDatasetCount();
        OgdcUnicodeStringArray datasetNames = datasource->GetDatasetNames();
        for (size_t j = 0; j < datasetNames.GetSize(); j++)
        {
    
    
          UGDatasetPtr dataset = datasource->GetDataset(datasetNames.GetAt(j));
          if (dataset->GetType() == datasetType)
          {
    
    
            // 关闭数据集
            dataset->Close();
            
            // 从数据源中删除数据集
            if (!datasource->DeleteDataset(dataset->GetName()) || !datasource->SaveInfo() || !datasource->Compact(TRUE))
            {
    
    
              return isDeleted;
            }
            else
            {
    
    
              isDeleted = TRUE;
              break;
            }
          }
        }
      }
      if (isDeleted)
      {
    
    
        break;
      }
    }
    return isDeleted;
  }
}

4. Summary

  Through the above-mentioned core function logic, the management of workspace, data source, and data set can be realized very easily based on SuperMap iObjects C++ 11icomponents . The demo demonstration is as follows:
WDDManager Demo demo.gif

  If you have carefully read the above process and the implementation logic, you still feel that you have no way to start. It is not clear how to implement the code based on these core logics and how to combine them in the MFC window program. Don’t worry or worry. The MFC sample project "Management of Workspace, Data Source, and Dataset Based on iObjects C++ 11i Components" implemented based on the above core logic can be downloaded directly. The sample project can be easily run after configuring the development environment according to this blog.

Guess you like

Origin blog.csdn.net/supermapsupport/article/details/130505033