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

📄 geoobj.cpp

📁 GemoMedia 应用 演示了其使用方法
💻 CPP
字号:
// GeoObj.cpp: implementation of the CGeoObj class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SvfToGeoMedia.h"
#include "GeoObj.h"
#include "ADOConn.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

extern ADOConn*  G_pADOConn; 
extern DGMConnectionPtr G_ptrDVIConnection ;
extern DGMGeometryStorageServicePtr G_ptrGSS;

extern CString GetFieldStr(char* str,ADODB::_RecordsetPtr pDS);
extern void SendMsg(CString str);

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGeoObj::CGeoObj():m_nID(-1),m_strGeoCode(""),m_strTable("")
,m_strType("")
{

}

CGeoObj::~CGeoObj()
{

}

//写地理对象到数据库
bool CGeoObj::WriteGeoObjToDataBase()
{
	//创建地理对象
	//IDispatch* objGeom;
	_DGMOrientedPointGeometryPtr ptrOrientPoint;
	_DGMPolylineGeometryPtr ptrLine;
	_DGMPolygonGeometryPtr ptrPolygon;
	_DGMTextPointGeometryPtr ptrTextPoint;

	m_strTable.TrimLeft() ;
	m_strTable.TrimRight();
	m_strType.MakeUpper();

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

		ptrOrientPoint->Orientation->I = 1;
		ptrOrientPoint->Orientation->J= 0;
		ptrOrientPoint->Orientation->K= 0;		
		
		Node node = *m_PosList.begin();
		ptrOrientPoint->Origin->X =node.fPosX;
		ptrOrientPoint->Origin->Y =node.fPosY;
		ptrOrientPoint->Origin->Z =node.fPosH;	
		
		//objGeom = ptrOrientPoint;
	}
	
	//线
	if (m_strType=="LINE")
	{
		//_DGMPolylineGeometryPtr ptrLine;
		ptrLine.CreateInstance(__uuidof(PolylineGeometry));
		
		for(list<Node>::const_iterator item = m_PosList.begin();item!= 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 (m_strType=="POLYGON")
	{		
		//_DGMPolygonGeometryPtr ptrPolygon;
		ptrPolygon.CreateInstance(__uuidof(PolygonGeometry));
		
		for(list<Node>::const_iterator item = m_PosList.begin();item!= 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 = *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 (m_strType=="ANNO")
	{
		//_DGMTextPointGeometryPtr ptrTextPoint;
		ptrTextPoint.CreateInstance(__uuidof(TextPointGeometry));

		Node node = *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 = m_AttrList.begin(); item!= 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;
	}
	
	//添加地理对象到数据表中
	//访问数据库
	OriginatingPipePtr ptrOrigPipe;
	G_ptrDVIConnection->CreateOriginatingPipe(&ptrOrigPipe);
	ptrOrigPipe->put_GeometryFieldName(_variant_t("Geometry"));
	ptrOrigPipe->put_Table(_bstr_t(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 = 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;
		if(strfieldname == "Geometry")
		{
			if (m_strType=="POINT")
			{
				G_ptrGSS->SetGeometry(ptrAddRs->GFields->Item[(long)i],ptrOrientPoint);
			}
		
			if (m_strType=="LINE")
			{
				G_ptrGSS->SetGeometry(ptrAddRs->GFields->Item[(long)i],ptrLine);
			}

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

			if (m_strType=="ANNO")
			{
				G_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 != 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();
	
	//
	m_nID = temp_v;

	return true;
}

//得到地理对象对应的数据表表名
bool CGeoObj::GetTableName()
{
	try
	{	
		if (G_pADOConn==NULL)
		{
			G_pADOConn = new ADOConn;
		}
		else
		{
			if (!G_pADOConn->m_bConnect)
			{
				if (!G_pADOConn->OnInitADOAcess("DataConv.mdb"))
				{
					AfxMessageBox("连接数据库失败!");
					return false;
				}
			}
		}
	
		

		CString strGeoCode(m_strGeoCode.c_str());
		CString strSQL = "Select * from SvfToGeoMedia where svf代码='"+strGeoCode+"'";
		ADODB::_RecordsetPtr pDS = G_pADOConn->GetRecordSet((_bstr_t)strSQL);
		
		if (pDS->adoEOF)
		{
			SendMsg("在SvfToGeoMedia表中没有查到Svf代码为"+strGeoCode+"对应的表!");
			//AfxMessageBox("在SvfToGeoMedia表中没有查到Svf代码为"+strGeoCode+"对应的表!");			
			pDS->Close();
			return false;
		}

		m_strTable = GetFieldStr("数据表",pDS);
		m_strType  = GetFieldStr("地物类型",pDS);

		pDS->Close();

		//检查表是否存在

		return true;
	}
	catch (CException* e)
	{
		e->Delete();
		
	}		
}

//从地理数据库中删除地理对象
bool CGeoObj::DelGeoObj()
{
	//G_ptrDVIConnection

	return true;
}

⌨️ 快捷键说明

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