📄 geodataengine.cpp
字号:
//将面要素空间数据写入表中当前记录的
//CGeoRecordset& rs -- 表对象(以记录集形式)
//POLYGONFEATURE* pdata -- 面要素结构指针
{
long i, j, size;
CByteArray byarray;
BYTE *pvalue;
// rs.SetField(PolygonFs[0].csName, &COleVariant(pdata->ID));
rs.SetField(PolygonFs[1].csName, &COleVariant(pdata->byType));
size = pdata->arrayLineID.GetSize();
byarray.SetSize(sizeof(long)*size);
for (i=0; i<size; i++)
{
pvalue = (BYTE*)&pdata->arrayLineID[i];
for (j=0; j<sizeof(long); j++)
byarray[sizeof(long)*i+j] = pvalue[j];
}
rs.SetField(PolygonFs[2].csName, &COleVariant(byarray));
byarray.RemoveAll();
size = pdata->arrayIslandID.GetSize();
byarray.SetSize(sizeof(long)*size);
for (i=0; i<size; i++)
{
pvalue = (BYTE*)&pdata->arrayIslandID[i];
for (j=0; j<sizeof(long); j++)
byarray[sizeof(long)*i+j] = pvalue[j];
}
rs.SetField(PolygonFs[3].csName, &COleVariant(byarray));
rs.SetField(PolygonFs[4].csName, &COleVariant(pdata->lParentID));
rs.SetField(PolygonFs[5].csName, &COleVariant(pdata->ptCentroid.x));
rs.SetField(PolygonFs[6].csName, &COleVariant(pdata->ptCentroid.y));
rs.SetField(PolygonFs[7].csName, &COleVariant(pdata->rectBound.x1));
rs.SetField(PolygonFs[8].csName, &COleVariant(pdata->rectBound.y1));
rs.SetField(PolygonFs[9].csName, &COleVariant(pdata->rectBound.x2));
rs.SetField(PolygonFs[10].csName, &COleVariant(pdata->rectBound.y2));
rs.SetField(PolygonFs[11].csName, &COleVariant(pdata->lAttriCode));
}
//---------------------------------------------------------------------------
void CGeoDataEngine::GetPolygonSpatialData(CGeoRecordset& rs, POLYGONFEATURE* pdata)
//获取面要素表中当前记录的空间数据
//CGeoRecordset& rs -- 表对象(以记录集形式)
//POLYGONFEATURE* pdata -- 面要素结构指针
{
long i, num;
COleVariant v;
long* pvalue;
v = rs.GetField(PolygonFs[0].csName); pdata->ID = v.lVal;
v = rs.GetField(PolygonFs[1].csName); pdata->byType = (BYTE)v.bVal;
v = rs.GetField(PolygonFs[2].csName);
num = v.parray->rgsabound[0].cElements/sizeof(long);
pvalue = (long*)v.parray->pvData;
pdata->arrayLineID.RemoveAll();
pdata->arrayLineID.SetSize(num);
for (i=0; i<num; i++)
pdata->arrayLineID[i] = pvalue[i];
v = rs.GetField(PolygonFs[3].csName);
num = v.parray->rgsabound[0].cElements/sizeof(long);
pvalue = (long*)v.parray->pvData;
pdata->arrayIslandID.RemoveAll();
pdata->arrayIslandID.SetSize(num);
for (i=0; i<num; i++)
pdata->arrayIslandID[i] = pvalue[i];
v = rs.GetField(PolygonFs[4].csName); pdata->lParentID = v.lVal;
v = rs.GetField(PolygonFs[5].csName); pdata->ptCentroid.x = v.dblVal;
v = rs.GetField(PolygonFs[6].csName); pdata->ptCentroid.y = v.dblVal;
v = rs.GetField(PolygonFs[7].csName); pdata->rectBound.x1 = v.dblVal;
v = rs.GetField(PolygonFs[8].csName); pdata->rectBound.y1 = v.dblVal;
v = rs.GetField(PolygonFs[9].csName); pdata->rectBound.x2 = v.dblVal;
v = rs.GetField(PolygonFs[10].csName); pdata->rectBound.y2 = v.dblVal;
v = rs.GetField(PolygonFs[11].csName); pdata->lAttriCode = v.lVal;
}
//---------------------------------------------------------------------------
void CGeoDataEngine::SetTextData(CGeoRecordset& rs, TEXTFEATURE* pdata)
//将文本要素数据写入表中当前记录的
//CGeoRecordset& rs -- 表对象(以记录集形式)
//TEXTFEATURE* pdata -- 要素文本结构指针
{
// rs.SetField(TextFs[0].csName, &COleVariant(pdata->ID));
rs.SetField(TextFs[1].csName, &COleVariant(pdata->ptPosition.x));
rs.SetField(TextFs[2].csName, &COleVariant(pdata->ptPosition.y));
rs.SetField(TextFs[3].csName, &COleVariant(pdata->csContent, VT_BSTRT));
rs.SetField(TextFs[4].csName, &COleVariant(pdata->byAlignment));
rs.SetField(TextFs[5].csName, &COleVariant(pdata->dVerticalSpace));
rs.SetField(TextFs[6].csName, &COleVariant(pdata->csFaceName, VT_BSTRT));
rs.SetField(TextFs[7].csName, &COleVariant(pdata->lEffect));
rs.SetField(TextFs[8].csName, &COleVariant(pdata->size.cx));
rs.SetField(TextFs[9].csName, &COleVariant(pdata->size.cy));
rs.SetField(TextFs[10].csName, &COleVariant(pdata->lCharExtra));
rs.SetField(TextFs[11].csName, &COleVariant(pdata->dAngle));
rs.SetField(TextFs[12].csName, &COleVariant((long)pdata->rgbFore));
rs.SetField(TextFs[13].csName, &COleVariant((long)pdata->rgbFore));
}
//---------------------------------------------------------------------------
void CGeoDataEngine::GetTextData(CGeoRecordset& rs, TEXTFEATURE* pdata)
//获取文本要素表中当前记录的数据
//CGeoRecordset& rs -- 表对象(以记录集形式)
//TEXTFEATURE* pdata -- 要素注记结构指针
{
COleVariant v;
v = rs.GetField(TextFs[0].csName); pdata->ID = v.lVal;
v = rs.GetField(TextFs[1].csName); pdata->ptPosition.x = v.dblVal;
v = rs.GetField(TextFs[2].csName); pdata->ptPosition.y = v.dblVal;
v = rs.GetField(TextFs[3].csName); pdata->csContent = (LPCTSTR)v.bstrVal;
v = rs.GetField(TextFs[4].csName); pdata->byAlignment = (BYTE)v.bVal;
v = rs.GetField(TextFs[5].csName); pdata->dVerticalSpace = v.dblVal;
v = rs.GetField(TextFs[6].csName); pdata->csFaceName = (LPCTSTR)v.bstrVal;
v = rs.GetField(TextFs[7].csName); pdata->lEffect = v.lVal;
v = rs.GetField(TextFs[8].csName); pdata->size.cx = v.lVal;
v = rs.GetField(TextFs[9].csName); pdata->size.cy = v.lVal;
v = rs.GetField(TextFs[10].csName); pdata->lCharExtra = v.lVal;
v = rs.GetField(TextFs[11].csName); pdata->dAngle = v.dblVal;
v = rs.GetField(TextFs[12].csName); pdata->rgbFore = (COLORREF)v.lVal;
v = rs.GetField(TextFs[13].csName); pdata->rgbBack = (COLORREF)v.lVal;
}
//---------------------------------------------------------------------------
void CGeoDataEngine::SetLabelData(CGeoRecordset& rs, LABELFEATURE* pdata)
//将要素注记数据写入表中当前记录的
//CGeoRecordset& rsj -- 表对象(以记录集形式)
//LABELFEATURE* pdata -- 要素注记结构指针
{
long i, j, size;
CByteArray byarray;
BYTE *pvalue;
// rs.SetField(LabelFs[0].csName, &COleVariant(pdata->ID));
// rs.SetField(LabelFs[1].csName, &COleVariant(pdata->byType));
rs.SetField(LabelFs[0].csName, &COleVariant(pdata->lGeoObjID));
rs.SetField(LabelFs[1].csName, &COleVariant(pdata->csFieldName, VT_BSTRT));
rs.SetField(LabelFs[2].csName, &COleVariant(pdata->csContent));
size = pdata->arrayLocation.GetSize();
byarray.SetSize(sizeof(DPOINT)*size);
for (i=0; i<size; i++)
{
pvalue = (BYTE*)&pdata->arrayLocation[i];
for (j=0; j<sizeof(DPOINT); j++)
byarray[sizeof(DPOINT)*i+j] = pvalue[j];
}
rs.SetField(LabelFs[3].csName, &COleVariant(byarray));
rs.SetField(LabelFs[4].csName, &COleVariant(pdata->byPlaceStyle));
rs.SetField(LabelFs[5].csName, &COleVariant(pdata->csFaceName, VT_BSTRT));
rs.SetField(LabelFs[6].csName, &COleVariant(pdata->lEffect));
rs.SetField(LabelFs[7].csName, &COleVariant(pdata->size.cx));
rs.SetField(LabelFs[80].csName, &COleVariant(pdata->size.cy));
rs.SetField(LabelFs[9].csName, &COleVariant(pdata->lCharExtra));
rs.SetField(LabelFs[10].csName, &COleVariant(pdata->dAngle));
rs.SetField(LabelFs[11].csName, &COleVariant((long)pdata->rgbFore));
rs.SetField(LabelFs[12].csName, &COleVariant((long)pdata->rgbFore));
}
//---------------------------------------------------------------------------
void CGeoDataEngine::GetLabelData(CGeoRecordset& rs, LABELFEATURE* pdata)
//获取要素注记表中当前记录的数据
//CGeoRecordset& rs -- 表对象(以记录集形式)
//LABELFEATURE* pdata -- 要素注记结构指针
{
long i, num;
COleVariant v;
DPOINT* pvalue;
// v = rs.GetField(LabelFs[0].csName); pdata->ID = v.lVal;
// v = rs.GetField(LabelFs[1].csName); pdata->byType = (BYTE)v.bVal;
v = rs.GetField(LabelFs[0].csName); pdata->lGeoObjID = v.lVal;
v = rs.GetField(LabelFs[1].csName); pdata->csFieldName = (LPCTSTR)v.bstrVal;
v = rs.GetField(LabelFs[2].csName); pdata->csContent = (LPCTSTR)v.bstrVal;
v = rs.GetField(LabelFs[3].csName);
num = v.parray->rgsabound[0].cElements/sizeof(DPOINT);
pvalue = (DPOINT*)v.parray->pvData;
pdata->arrayLocation.RemoveAll();
pdata->arrayLocation.SetSize(num);
for (i=0; i<num; i++)
pdata->arrayLocation[i] = pvalue[i];
v = rs.GetField(LabelFs[4].csName); pdata->byPlaceStyle = (BYTE)v.bVal;
v = rs.GetField(LabelFs[5].csName); pdata->csFaceName = (LPCTSTR)v.bstrVal;
v = rs.GetField(LabelFs[6].csName); pdata->lEffect = v.lVal;
v = rs.GetField(LabelFs[7].csName); pdata->size.cx = v.lVal;
v = rs.GetField(LabelFs[8].csName); pdata->size.cy = v.lVal;
v = rs.GetField(LabelFs[9].csName); pdata->lCharExtra = v.lVal;
v = rs.GetField(LabelFs[10].csName); pdata->dAngle = v.dblVal;
v = rs.GetField(LabelFs[11].csName); pdata->rgbFore = (COLORREF)v.lVal;
v = rs.GetField(LabelFs[12].csName); pdata->rgbBack = (COLORREF)v.lVal;
}
//---------------------------------------------------------------------------
void CGeoDataEngine::SetSymbolData(CGeoRecordset& rs, SYMBOLFEATURE* pdata)
//将要素符号数据写入表中当前记录的
//CGeoRecordset& rsj -- 表对象(以记录集形式)
//SYMBOLFEATURE* pdata -- 要素符号结构指针
{
// rs.SetField(SymbolFs[0].csName, &COleVariant(pdata->ID));
// rs.SetField(SymbolFs[1].csName, &COleVariant(pdata->byType));
rs.SetField(SymbolFs[0].csName, &COleVariant(pdata->lGeoObjID));
rs.SetField(SymbolFs[1].csName, &COleVariant(pdata->lCode));
rs.SetField(SymbolFs[2].csName, &COleVariant(pdata->dSize));
rs.SetField(SymbolFs[3].csName, &COleVariant((long)pdata->rgbFore));
rs.SetField(SymbolFs[4].csName, &COleVariant((long)pdata->rgbBack));
rs.SetField(SymbolFs[5].csName, &COleVariant(pdata->dDistance));
}
//---------------------------------------------------------------------------
void CGeoDataEngine::GetSymbolData(CGeoRecordset& rs, SYMBOLFEATURE* pdata)
//获取要素符号表中当前记录的数据
//CGeoRecordset& rs -- 表对象(以记录集形式)
//SYMBOLFEATURE* pdata -- 要素符号结构指针
{
COleVariant v;
// v = rs.GetField(SymbolFs[0].csName); pdata->ID = v.lVal;
// v = rs.GetField(SymbolFs[1].csName); pdata->byType = (BYTE)v.bVal;
v = rs.GetField(SymbolFs[0].csName); pdata->lGeoObjID = v.lVal;
v = rs.GetField(SymbolFs[1].csName); pdata->lCode = v.lVal;
v = rs.GetField(SymbolFs[2].csName); pdata->dSize = v.dblVal;
v = rs.GetField(SymbolFs[3].csName); pdata->rgbFore = (COLORREF)v.lVal;
v = rs.GetField(SymbolFs[4].csName); pdata->rgbBack = (COLORREF)v.lVal;
v = rs.GetField(SymbolFs[5].csName); pdata->dDistance = v.dblVal;
}
//---------------------------------------------------------------------------
void CGeoDataEngine::SetLayerData(CGeoRecordset& rs, LAYERFEATURE* pdata)
//将要素层数据写入要素层表的当前记录
//CGeoRecordset& rs -- 表对象(以记录集形式)
//LAYERFEATURE* pdata -- 要素层对象指针
{
rs.SetField(LayerFs[0].csName, &COleVariant(pdata->csName, VT_BSTRT));
rs.SetField(LayerFs[1].csName, &COleVariant(pdata->byType));
rs.SetField(LayerFs[2].csName, &COleVariant(pdata->ptLocation.x));
rs.SetField(LayerFs[3].csName, &COleVariant(pdata->ptLocation.y));
rs.SetField(LayerFs[4].csName, &COleVariant(pdata->lScale));
rs.SetField(LayerFs[5].csName, &COleVariant(pdata->dMinView));
rs.SetField(LayerFs[6].csName, &COleVariant(pdata->dMaxView));
rs.SetField(LayerFs[7].csName, &COleVariant(pdata->byVisible));
}
//---------------------------------------------------------------------------
void CGeoDataEngine::GetLayerData(CGeoRecordset& rs, LAYERFEATURE* pdata)
//获取要素层表当前记录的有关层的数据
//CGeoRecordset& rs -- 表对象(以记录集形式)
//LAYERFEATURE* pdata -- 要素层对象指针
{
COleVariant v;
v = rs.GetField(LayerFs[0].csName); pdata->csName = (LPCTSTR)v.bstrVal;
v = rs.GetField(LayerFs[1].csName); pdata->byType = (BYTE)v.bVal;
v = rs.GetField(LayerFs[2].csName); pdata->ptLocation.x = v.dblVal;
v = rs.GetField(LayerFs[3].csName); pdata->ptLocation.y = v.dblVal;
v = rs.GetField(LayerFs[4].csName); pdata->lScale = v.lVal;
v = rs.GetField(LayerFs[5].csName); pdata->dMinView = v.dblVal;
v = rs.GetField(LayerFs[6].csName); pdata->dMaxView = v.dblVal;
v = rs.GetField(LayerFs[7].csName); pdata->byVisible = (BYTE)v.bVal;
}
//---------------------------------------------------------------------------
void CGeoDataEngine::SetWorkspaceData(CGeoRecordset& rs, WORKSPACEFEATURE* pdata)
//将工作区数据写入工作区数据库表
//CGeoRecordset& rs -- 数据库表记录集对象
//WORKSPACEFEATURE* pdata -- 工作区对象指针
{
rs.MoveFirst();
rs.Edit();
rs.SetField(WorkspaceFs[0].csName, &COleVariant(pdata->csName, VT_BSTRT));
rs.SetField(WorkspaceFs[1].csName, &COleVariant(pdata->dtDate));
rs.SetField(WorkspaceFs[2].csName, &COleVariant(pdata->csLevel, VT_BSTRT));
rs.SetField(WorkspaceFs[3].csName, &COleVariant(pdata->dLongitude1));
rs.SetField(WorkspaceFs[4].csName, &COleVariant(pdata->dLatitude1));
rs.SetField(WorkspaceFs[5].csName, &COleVariant(pdata->dLongitude2));
rs.SetField(WorkspaceFs[6].csName, &COleVariant(pdata->dLatitude2));
rs.SetField(WorkspaceFs[7].csName, &COleVariant(pdata->x1));
rs.SetField(WorkspaceFs[8].csName, &COleVariant(pdata->y1));
rs.SetField(WorkspaceFs[9].csName, &COleVariant(pdata->x2));
rs.SetField(WorkspaceFs[10].csName, &COleVariant(pdata->y2));
rs.SetField(WorkspaceFs[11].csName, &COleVariant(pdata->byXYSystem));
rs.SetField(WorkspaceFs[12].csName, &COleVariant(pdata->byZSystem));
rs.SetField(WorkspaceFs[13].csName, &COleVariant(pdata->byProjection));
rs.SetField(WorkspaceFs[14].csName, &COleVariant(pdata->byUnit));
rs.SetField(WorkspaceFs[15].csName, &COleVariant(pdata->byStyle));
rs.SetField(WorkspaceFs[16].csName, &COleVariant(pdata->byDisplayProjection));
}
//---------------------------------------------------------------------------
void CGeoDataEngine::GetWorkspaceData(CGeoRecordset& rs, WORKSPACEFEATURE* pdata)
//获取工作区数据库表的数据
//CGeoRecordset& rs -- 数据库表记录集对象
//WORKSPACEFEATURE* pdata -- 工作区对象指针
{
COleVariant v;
rs.MoveFirst();
v = rs.GetField(WorkspaceFs[0].csName); pdata->csName = (LPCTSTR)v.bstrVal;
v = rs.GetField(WorkspaceFs[1].csName); pdata->dtDate = COleDateTime(v.date);
v = rs.GetField(WorkspaceFs[2].csName); pdata->csLevel= (LPCTSTR)v.bstrVal;
v = rs.GetField(WorkspaceFs[3].csName); pdata->dLongitude1 = v.dblVal;
v = rs.GetField(WorkspaceFs[4].csName); pdata->dLatitude1 = v.dblVal;
v = rs.GetField(WorkspaceFs[5].csName); pdata->dLongitude2 = v.dblVal;
v = rs.GetField(WorkspaceFs[6].csName); pdata->dLatitude2 = v.dblVal;
v = rs.GetField(WorkspaceFs[7].csName); pdata->x1 = v.dblVal;
v = rs.GetField(WorkspaceFs[8].csName); pdata->y1 = v.dblVal;
v = rs.GetField(WorkspaceFs[9].csName); pdata->x2 = v.dblVal;
v = rs.GetField(WorkspaceFs[10].csName); pdata->y2 = v.dblVal;
v = rs.GetField(WorkspaceFs[11].csName); pdata->byXYSystem = (BYTE)v.bVal;
v = rs.GetField(WorkspaceFs[12].csName); pdata->byZSystem = (BYTE)v.bVal;
v = rs.GetField(WorkspaceFs[13].csName); pdata->byProjection = (BYTE)v.bVal;
v = rs.GetField(WorkspaceFs[14].csName); pdata->byUnit = (BYTE)v.bVal;
v = rs.GetField(WorkspaceFs[15].csName); pdata->byStyle = (BYTE)v.bVal;
v = rs.GetField(WorkspaceFs[16].csName); pdata->byDisplayProjection = (BYTE)v.bVal;
}
//---------------------------------------------------------------------------
BOOL CGeoDataEngine::CreateNewLayer(CGeoDatabase& db, LAYERFEATURE* pdata)
//建立一个新的要素层及相关的数据库表
{
CdbRecordset rs;
CdbField fd;
rs = db.TableDefs[comLayerTableName].OpenRecordset(dbOpenTable, dbAppendOnly);
rs.AddNew();
SetLayerData(rs, pdata);
rs.Update();
rs.Close();
if (!CreatePointTable(db, pdata->csName+(LPCTSTR)comPointSuffix)) return(FALSE);
if (!CreateSymbolTable(db, pdata->csName+(LPCTSTR)comPointSymbolSuffix)) return(FALSE);
if (!CreateLabelTable(db, pdata->csName+(LPCTSTR)comPointLabelSuffix)) return(FALSE);
if (!CreateLineTable(db, pdata->csName+(LPCTSTR)comLineSuffix)) return(FALSE);
if (!CreateSymbolTable(db, pdata->csName+(LPCTSTR)comLineSymbolSuffix)) return(FALSE);
if (!CreateLabelTable(db, pdata->csName+(LPCTSTR)comLineLabelSuffix)) return(FALSE);
if (!CreatePointTable(db, pdata->csName+(LPCTSTR)comPolygonSuffix)) return(FALSE);
if (!CreateSymbolTable(db, pdata->csName+(LPCTSTR)comPolygonSymbolSuffix)) return(FALSE);
if (!CreateLabelTable(db, pdata->csName+(LPCTSTR)comPolygonLabelSuffix)) return(FALSE);
if (!CreateTextTable(db, pdata->csName+(LPCTSTR)comTextSuffix)) return(FALSE);
return(TRUE);
}
//---------------------------------------------------------------------------
void CGeoDataEngine::RenameLayer(CGeoDatabase& db, CString oldname, CString newname)
//更新一个要素层及相关的数据库表的名字
{
CdbTableDef td;
db.TableDefs[oldname+(LPCTSTR)comPointSuffix].SetName(newname+(LPCTSTR)comPointSuffix);
db.TableDefs[oldname+(LPCTSTR)comPointSymbolSuffix].SetName(newname+(LPCTSTR)comPointSymbolSuffix);
db.TableDefs[oldname+(LPCTSTR)comPointLabelSuffix].SetName(newname+(LPCTSTR)comPointLabelSuffix);
db.TableDefs[oldname+(LPCTSTR)comLineSuffix].SetName(newname+(LPCTSTR)comLineSuffix);
db.TableDefs[oldname+(LPCTSTR)comLineSymbolSuffix].SetName(newname+(LPCTSTR)comLineSymbolSuffix);
db.TableDefs[oldname+(LPCTSTR)comLineLabelSuffix].SetName(newname+(LPCTSTR)comLineLabelSuffix);
db.TableDefs[oldname+(LPCTSTR)comPolygonSuffix].SetName(newname+(LPCTSTR)comPolygonSuffix);
db.TableDefs[oldname+(LPCTSTR)comPolygonSymbolSuffix].SetName(newname+(LPCTSTR)comPolygonSymbolSuffix);
db.TableDefs[oldname+(LPCTSTR)comPolygonLabelSuffix].SetName(newname+(LPCTSTR)comPolygonLabelSuffix);
db.TableDefs[oldname+(LPCTSTR)comTextSuffix].SetName(newname+(LPCTSTR)comTextSuffix);
}
//---------------------------------------------------------------------------
void CGeoDataEngine::BeginTrans()
//开始启动一个新事务
{
m_dbWorkspace.BeginTrans();
}
//---------------------------------------------------------------------------
void CGeoDataEngine::CommitTrans()
//完成事务处理
{
m_dbWorkspace.CommitTrans();
}
//---------------------------------------------------------------------------
void CGeoDataEngine::Rollback()
//回滚事务处理
{
m_dbWorkspace.Rollback();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -