?? geoobj.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 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("")
{
m_pADOConn=NULL;
}
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;
m_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")
{
m_ptrGSS->SetGeometry(ptrAddRs->GFields->Item[(long)i],ptrOrientPoint);
}
if (m_strType=="LINE")
{
m_ptrGSS->SetGeometry(ptrAddRs->GFields->Item[(long)i],ptrLine);
}
if (m_strType=="POLYGON")
{
m_ptrGSS->SetGeometry(ptrAddRs->GFields->Item[(long)i],ptrPolygon);
}
if (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 != 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;
}
//設置參數
void CGeoObj::SetParam(ADOConn* pADOConn,DGMConnectionPtr ptrDVIConn,DGMGeometryStorageServicePtr ptrGSS)
{
m_pADOConn = pADOConn;
m_ptrDVIConnection = ptrDVIConn;
m_ptrGSS = ptrGSS;
}
//得到地理對象對應的數據表表名
bool CGeoObj::GetTableName()
{
try
{
if (m_pADOConn==NULL)
{
m_pADOConn = new ADOConn;
}
if (!m_pADOConn->m_bConnect)
{
if (!m_pADOConn->OnInitADOAcess(GetPathFile()))
{
AfxMessageBox("連接數據庫失敗!");
return false;
}
}
CString strGeoCode(m_strGeoCode.c_str());
CString strSQL = "Select * from SvfToGeoMedia where svf代碼='"+strGeoCode+"'";
ADODB::_RecordsetPtr pDS = m_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();
}
}
//得到路徑
CString CGeoObj::GetPathFile()
{
char szFile[500];
GetModuleFileName(NULL,szFile,_MAX_PATH);
char szDriver[_MAX_DRIVE];
char szDir[_MAX_DIR];
_splitpath(szFile,szDriver,szDir,NULL,NULL);
CString strDriver(szDriver);
CString strDir(szDir);
return szDriver+strDir+"\\DataConv.mdb";
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -