⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 translate.cpp

📁 GemoMedia 应用 演示了其使用方法
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		if (!pADOConn->OnInitADOConn(m_strUser,m_strPassWord,m_strDataBase,m_strDB))
		{
			AfxMessageBox("连接"+m_strDataBase+"数据库失败!");
			return false;
		}
	}
	
	map<CString,bool>  Tbmap;
	list<CGeoObj*>::iterator Item;

	for (Item = m_GEOList.begin();Item!= m_GEOList.end();Item++)
	{
		CGeoObj* pGeoObj = *Item;
		CString strTable =  pGeoObj->m_strTable;
		Tbmap[strTable]=false;
	}

	//检查特征集是否存在
	for(map<CString,bool>::iterator item = Tbmap.begin();item!= Tbmap.end(); item++)
	{
		CString strtable = item->first;
		strtable.TrimLeft();
		strtable.TrimRight();


		_bstr_t vSQL = "select * from  GFeatures  where FeatureName ='"+ strtable+"'";
		
		if (m_strDbType=="ORACLE")
		{
			m_strDataBase.MakeUpper();
			strtable.MakeUpper();
			vSQL = "select * from  GDOSYS.GFeaturesBase  where FeatureName ='"+ m_strDataBase+"."+strtable +"'";
		}

		ADODB::_RecordsetPtr pDS = pADOConn->GetRecordSet(vSQL);
		
		if (!pDS->adoEOF)
		{
			Tbmap[strtable] = true;									
		}
		
		pDS->Close();

	}

	bool bresult=true;
	
	for (item = Tbmap.begin();item!= Tbmap.end();item++)
	{
		if (!item->second)
		{
			CString strTbName = item->first;
			SendMsg("数据库没有对应的表"+strTbName+"存在!");
			bresult = false;
		}
	}

	//清理数据库连接对象
	pADOConn->ExitConnect();

	return bresult;
}

//创建地理数据库连接
bool CTranslate::InitGeoDbConnect()
{
	//初始化地理据库连接
	m_strDbType.MakeUpper();
	try
	{
		if (m_ptrDVIConnection==NULL)
		{
			m_ptrDVIConnection.CreateInstance(__uuidof(Connection));
		}
		
		//Access数据库连接
		if (m_strDbType == "ACCESS")
		{
			//设置数据仓库路径
			m_ptrDVIConnection->put_Location(_bstr_t(m_strAccess));
			//数据仓库类型
			m_ptrDVIConnection->put_Type(L"Access.GDatabase");
			m_ptrDVIConnection->Connect();
			
			//Oracle数据库连接
		}else if (m_strDbType == "ORACLE")
		{
			//"用户名/密码@数据库服务名"
			CString strConnectInfo = m_strUser+"/"+m_strPassWord+"@"+m_strDataBase;
			m_ptrDVIConnection->put_Location(_bstr_t("Oracle"));
			m_ptrDVIConnection->PutType(_bstr_t("OracleORW.GDatabase"));
			m_ptrDVIConnection->put_ConnectInfo(_bstr_t(strConnectInfo));
			m_ptrDVIConnection->put_Mode(1);
			
			m_ptrDVIConnection->Connect();
			
			//SQLSERVER数据库连接
		}else if (m_strDbType == "SQLSERVER")
		{
			/*
			Server=;]Database=<databaseName>;[UID=<userName>;[PWD=<password>;]|Trusted_Connection=yes;]"
			*/
			
			CString strConnectInfo = "Uid="+m_strUser+";Pwd="+m_strPassWord+";Database="+m_strDB+"; SERVER="+ m_strDataBase+";Trusted_Connection=yes;";
			
			m_ptrDVIConnection->put_Location(_bstr_t("SQL Sever"));
			m_ptrDVIConnection->PutType(_bstr_t("SQLServerRW.Gdatabase"));
			m_ptrDVIConnection->put_ConnectInfo(_bstr_t(strConnectInfo));
			m_ptrDVIConnection->put_Mode(1);
			
			m_ptrDVIConnection->Connect();				
		}	
		
		//全局数据存储服务
		m_ptrGSS.CreateInstance(__uuidof(GeometryStorageService));
		
	}catch (_com_error e) {
		AfxMessageBox(e.Description());
		return false;
	}

	return true;
}


bool CTranslate::WriteGeoObjToDb(CGeoObj *pGeoObj)
{
	//创建地理对象
	//IDispatch* objGeom;
	_DGMOrientedPointGeometryPtr ptrOrientPoint;
	_DGMPolylineGeometryPtr ptrLine;
	_DGMPolygonGeometryPtr ptrPolygon;
	_DGMTextPointGeometryPtr ptrTextPoint;

	pGeoObj->m_strTable.TrimLeft() ;
	pGeoObj->m_strTable.TrimRight();
	pGeoObj->m_strType.MakeUpper();

	if (pGeoObj->m_strType=="POINT")
	{
		//_DGMOrientedPointGeometryPtr ptrOrientPoint;
		ptrOrientPoint.CreateInstance(__uuidof(OrientedPointGeometry));

		ptrOrientPoint->Orientation->I = 1;
		ptrOrientPoint->Orientation->J= 0;
		ptrOrientPoint->Orientation->K= 0;		
		
		Node node = *(pGeoObj->m_PosList.begin());
		ptrOrientPoint->Origin->X =node.fPosX;
		ptrOrientPoint->Origin->Y =node.fPosY;
		ptrOrientPoint->Origin->Z =node.fPosH;	
		
		//objGeom = ptrOrientPoint;
	}
	
	//线
	if (pGeoObj->m_strType=="LINE")
	{
		//_DGMPolylineGeometryPtr ptrLine;
		ptrLine.CreateInstance(__uuidof(PolylineGeometry));
		
		for(list<Node>::const_iterator item = pGeoObj->m_PosList.begin();item!= pGeoObj->m_PosList.end();item++)
		{
			Node node = *item;
			_DGMPointPtr pPoint;
			pPoint.CreateInstance("GeoMedia.Point");
			pPoint->X = node.fPosX;
			pPoint->Y = node.fPosY;
			pPoint->Z = node.fPosH;
			
			ptrLine->Points->Add(pPoint);
		}
		//objGeom = ptrLine;
	}

	//面
	if (pGeoObj->m_strType=="POLYGON")
	{		
		//_DGMPolygonGeometryPtr ptrPolygon;
		ptrPolygon.CreateInstance(__uuidof(PolygonGeometry));
		
		for(list<Node>::const_iterator item = pGeoObj->m_PosList.begin();item!= pGeoObj->m_PosList.end();item++)
		{
			Node node = *item;
			_DGMPointPtr pPoint;
			pPoint.CreateInstance("GeoMedia.Point");
			pPoint->X = node.fPosX;
			pPoint->Y = node.fPosY;
			pPoint->Z = node.fPosH;
			
			ptrPolygon->Points->Add(pPoint);
		}
		
		//最后加入起点
		Node Nodefirst = *(pGeoObj->m_PosList.begin());
		_DGMPointPtr pPoint;
		pPoint.CreateInstance("GeoMedia.Point");
		pPoint->X = Nodefirst.fPosX;
		pPoint->Y = Nodefirst.fPosY;
		pPoint->Z = Nodefirst.fPosH;

		ptrPolygon->Points->Add(pPoint);

		//objGeom = ptrPolygon;
	}

	//注记
	if (pGeoObj->m_strType=="ANNO")
	{
		//_DGMTextPointGeometryPtr ptrTextPoint;
		ptrTextPoint.CreateInstance(__uuidof(TextPointGeometry));

		Node node = *(pGeoObj->m_PosList.begin());

		ptrTextPoint->Origin->X = node.fPosX;
		ptrTextPoint->Origin->Y = node.fPosY;
		ptrTextPoint->Origin->Z = node.fPosH;

		ptrTextPoint->Alignment = gmaBottomLeft;
		ptrTextPoint->Normal->I = 0;
		ptrTextPoint->Normal->J = 0;
		ptrTextPoint->Normal->K = 1;
		
		//注记内容
		CString strcontext("");
		//字高
		double  dfontH=0;
		//转角
		double dfontR =0;
		//字体
		CString strFont("");
		   
		for (list<Attr>::const_iterator item = pGeoObj->m_AttrList.begin(); item!= pGeoObj->m_AttrList.end();item++)
		{
			Attr attr = *item;
			CString strAttrName(attr.strAttrName.c_str());
			if (strAttrName == "注记")
				strcontext = attr.strAttr.c_str();

			if (strAttrName == "字高")
				dfontH = atof(attr.strAttr.c_str());

			if (strAttrName =="转角")
				dfontR = atof(attr.strAttr.c_str());

			if (strAttrName =="字体")
				strFont = attr.strAttr.c_str();
		}

		if (ptrTextPoint->Format == 0 )
		{
			ptrTextPoint->RichText = _bstr_t(strcontext);
		}
		else
		{
			ptrTextPoint->text = _bstr_t(strcontext);
		}
		
		ptrTextPoint->Rotation = dfontR;
		
		//objGeom = ptrTextPoint;
	}

	//添加地理对象到数据表中
	//访问数据库
	/*
	GDatabasePtr ptrdatabase=m_ptrDVIConnection->Database;

	CString str = pGeoObj->m_strTable;

	GRecordsetPtr ptrAddRs= ptrdatabase->OpenRecordset(_bstr_t(str),vtMissing,vtMissing,vtMissing,vtMissing,_variant_t("GeoMetry"));
	*/
	
	OriginatingPipePtr ptrOrigPipe;
	m_ptrDVIConnection->CreateOriginatingPipe(&ptrOrigPipe);

	ptrOrigPipe->put_GeometryFieldName(_variant_t("Geometry"));
	
	CString str = pGeoObj->m_strTable;

	ptrOrigPipe->put_Table(_bstr_t(pGeoObj->m_strTable));
				
	GRecordsetPtr ptrAddRs;
	ptrOrigPipe->get_OutputRecordset(&ptrAddRs);
	
		
	////////////////////////////////////////////////////////////////
	//取得目前最大记录
	long temp_v=0;
	if (!ptrAddRs->_EOF)
	{
		ptrAddRs->MoveLast();
		for(int i = 0;i < ptrAddRs->GFields->Count;i++)
		{
			BSTR fieldname;
			ptrAddRs->GFields->Item[(long)i]->get_Name(&fieldname);
			CString strfieldname = fieldname;
			//if(strfieldname == "GMIPrimaryKey") 
			if(strfieldname == "ID") 
				temp_v = ptrAddRs->GFields->Item[(long)i]->Value;
		}
	}
	
	temp_v++;
	
	list<Attr>::const_iterator item_attr = pGeoObj->m_AttrList.begin();

	ptrAddRs->AddNew();
	int count = ptrAddRs->GFields->Count;
	for(int i = 0;i < ptrAddRs->GFields->Count;i++)
	{
		BSTR fieldname;
		ptrAddRs->GFields->Item[(long)i]->get_Name(&fieldname);
		CString strfieldname = fieldname;
		strfieldname.MakeUpper();
		
		if(strfieldname == "GEOMETRY")
		{
			if (pGeoObj->m_strType=="POINT")
			{
				m_ptrGSS->SetGeometry(ptrAddRs->GFields->Item[(long)i],ptrOrientPoint);
			}
		
			if (pGeoObj->m_strType=="LINE")
			{
				m_ptrGSS->SetGeometry(ptrAddRs->GFields->Item[(long)i],ptrLine);
			}

			if (pGeoObj->m_strType=="POLYGON")
			{
				m_ptrGSS->SetGeometry(ptrAddRs->GFields->Item[(long)i],ptrPolygon);
			}

			if (pGeoObj->m_strType=="ANNO")
			{
				m_ptrGSS->SetGeometry(ptrAddRs->GFields->Item[(long)i],ptrTextPoint);
			}

		}	else if(strfieldname == "ID")
			ptrAddRs->GFields->Item[(long)i]->put_Value(_variant_t((long)temp_v));		
		//else if(strfieldname == "Geometry_sk")
		//	ptrAddRs->GFields->Item[(long)i]->put_Value(_variant_t("1Bm,zRm{"));
		else if (item_attr != pGeoObj->m_AttrList.end())
		{
			Attr node_attr = *item_attr;
			ptrAddRs->GFields->Item[(long)i]->put_Value(_variant_t(_bstr_t(node_attr.strAttr.c_str())));

			item_attr++;
		}


	}
	ptrAddRs->Update();	
	ptrAddRs->Close();
	
	pGeoObj->m_nID = temp_v;

	return true;
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -