首页 / 浏览问题 / 组件GIS / 问题详情
工作空间与数据源
35EXP 2019年11月05日

组件iobjectscpp910   win10  64 位

在新建工作空间、数据源、数据集时候时候,出现工作空间无法关联数据源的情况

用桌面版可以打开数据源,无法用代码直接关联。

QString path = QFileDialog::getSaveFileName(this, QStringLiteral("新建"),
		"C:/personal/SuperMap/supermap-iobjectscpp/sample/data", tr("smwu(*.smwu)"));    //获取文件夹路径
	workspace = new UGWorkspace();
	UGWorkspaceConnection wc = workspace->m_WorkspaceConnection;
	if(path != nullptr)
	{
		wc.m_strServer = Translator::QStr2UGStr(path);
		wc.m_nVersion = UG_WORKSPACE_VERSION_20120328;
		wc.m_bFailIfExists = false;
		wc.m_nWorkspaceType = UGWorkspace::UGWorkspaceType::WS_Version_SMWU;
	}
	workspace->Open(wc);

	QString path1 = path.replace(".smwu",".udb");
	UGDataSource *ds = UGDataSourceManager::CreateDataSource(UGEngineType::UDB);
	ds->GetConnectionInfo().m_nType = UGC::UDB;
	ds->GetConnectionInfo().m_bReadOnly = false;
	ds->GetConnectionInfo().m_bExclusive = true;
	ds->GetConnectionInfo().m_strServer = Translator::QStr2UGStr(path1);
	if(ds->Create())
	{
		//默认点数据集创建
		UGDatasetVectorInfo* info1 = new UGDatasetVectorInfo ();
		info1->m_nType = UGC ::UGDataset ::DatasetType ::Point;
		UGString name1 = ds->GetUnoccupiedDatasetName(_U ("myPoint"));
		info1->m_strName = name1 ;
		info1->m_strTableName =name1 ;
		UGDatasetVector* datasetresult1 = ds->CreateDatasetVector(*info1);
			
		//默认线数据集创建
		UGDatasetVectorInfo* info2 = new UGDatasetVectorInfo ();
		info2->m_nType = UGC ::UGDataset ::DatasetType ::Line;
		UGString name2 = ds->GetUnoccupiedDatasetName(_U("myLine"));
		info2->m_strName = name2 ;
		info2->m_strTableName =name2 ;
		UGDatasetVector * datasetresult2 = ds->CreateDatasetVector(*info2);
	
		//默认面数据集创建
		UGDatasetVectorInfo* info3 = new UGDatasetVectorInfo ();
		info3->m_nType = UGC ::UGDataset ::DatasetType ::Region;
		UGString name3 = ds->GetUnoccupiedDatasetName(_U ("myPlane"));
		info3->m_strName = name3 ;
		info3->m_strTableName =name3 ;
		UGDatasetVector * datasetresult3 = ds->CreateDatasetVector(*info3);
	}

	if(ds->Open())
		UGDataSource *dd = workspace->OpenDataSource(ds->GetConnectionInfo());
	workspace->SaveAs(wc);

1个回答

您得用工作空间去打开数据源,然后保存,数据源就在这个工作空间里面了。具体看下组件api
1,255EXP 2019年11月06日
代码最后是使用工作空间打开数据源的

workspace->OpenDataSource(ds->GetConnectionInfo());
...