首页 / 浏览问题 / 组件GIS / 问题详情
新建对象成功但程序退出
35EXP 2020年05月12日

 iobjectscpp    win10  x64

在使用点数据集生成线数据集时候程序异常退出,但是下次打开时候线存在。

​
            UGDatasetVector * dataset = (UGDatasetVector *) m_pWorkspace ->GetDataSource(0)->GetDataset (_U("Tower_R"));

			dataset->Open();
			UGQueryDef query = UGQueryDef();   
			UGRecordset* recordset = dataset->Query(query); 
			recordset->MoveFirst();

			UGDatasetVectorInfo* info = new UGDatasetVectorInfo();
			info ->m_nType = UGC ::UGDataset ::DatasetType::Line;
			QString str_name = "Design_L";
			UGString result = Translator::QStr2UGStr(str_name);
			UGString name = m_pWorkspace ->GetDataSource(0)->GetUnoccupiedDatasetName(result);
			if(name != result)
				m_pWorkspace ->GetDataSource(0)->DeleteDataset(result);
			info ->m_strName = result ;
			info ->m_strTableName = result ;
			UGDatasetVector * newDataset = m_pWorkspace ->GetDataSource(0)->CreateDatasetVector(*info);
			newDataset->Open();
			if(info)
			{
				delete info;
				info = nullptr;
			}

			UGQueryDef query1 = UGQueryDef();
			UGRecordset *re = newDataset->Query(query1);

			UGGeoLine *line_1 = new UGGeoLine();
			UGGeoLine *line_2 = new UGGeoLine();
			UGPoint2D *points_1 = new UGPoint2D[];
			UGPoint2D *points_2 = new UGPoint2D[];

			int j = 0;
			for (int i = 0; i < recordset->GetRecordCount(); i++)  
			{
				recordset->MoveTo(i);
				UGGeometry * pTempGeomtry = nullptr;
				recordset->GetGeometry(pTempGeomtry);
				UGGeoRegion * pPoint = dynamic_cast<UGGeoRegion*>(pTempGeomtry);
				if(j == 0)
				{
					points_1[0] = pPoint->GetInnerPoint();
					if(i > 0)
						points_2[1] = pPoint->GetInnerPoint();
				}
				if(j == 1)
				{
					points_1[1] = pPoint->GetInnerPoint();
					points_2[0] = pPoint->GetInnerPoint();
				}
				j++;
				if(j == 2)
				{
					j = 0;
					line_1->AddSub(points_1,2);
					re->AddNew(line_1);
					re->Update();
				}
				if(i > 1 && j == 1)
				{
					line_2->AddSub(points_2,2);
					re->AddNew(line_2);
					re->Update();
				}
			}

			if(line_1 != nullptr)
			{
				delete line_1;
				line_1 = nullptr;
			}
			if(line_2 != nullptr)
			{
				delete line_2;
				line_2 = nullptr;
			}
				points_1 = nullptr;
				points_2 = nullptr;

			UGLayer *lay = m_pMap->m_Layers.AddDataset(newDataset);
			m_pMap->m_Layers.MoveTo(0, 5);
			UGStyle sty_L = UGStyle();
			sty_L.SetLineColor(85735);
			sty_L.SetLineWidth(0.3);
			lay->SetStyle(sty_L);
			qMapControl->Refresh();

​

依然不行

1个回答

将几何对象或者是UGRecordset在每个用完后都要进行释放
4,620EXP 2020年05月12日
是的,进去直接点构线是可以的,然后绘制新的对象,再点击就会结束
重现了,有结果有给您回复
UGString result = _U("Design_L");
    UGString name = m_pWorkspace->GetDataSource(0)->GetUnoccupiedDatasetName(result);
    UGDatasetVector * newDataset = NULL;
    if (name != result)
    {
        newDataset = (UGDatasetVector *)m_pWorkspace->GetDataSource(0)->GetDataset(_U("Design_L"));
        newDataset->Open();
        UGQueryDef query = UGQueryDef();
        UGRecordset* recordset = newDataset->Query(query);
        recordset->DeleteAll();
        recordset->Update();
    }
    else
    {
        info->m_strName = result;
        info->m_strTableName = result;
        newDataset = m_pWorkspace->GetDataSource(0)->CreateDatasetVector(*info);
    }
    newDataset->Open();

中间新建数据集这段代码的逻辑换一下,如果已经存在这个数据集,将数据集里内容清空,如果不存在则新建一个新的数据集。
或者是如果数据集已经存在的情况下,判断地图中是否已经有这个图层,如果有,将图层先移除,然后再去执行数据集删除。接下来流程不变
好的,我测试一下,谢谢您
...