1.配置shapelib环境:拷贝shapelib.lib 和shapefil.h到工程目录下面。并且配置lib
操作DBF文件:
BOOL CSecurityMatainWnd::ImportFromDBF(const CString sFileName)
{
DBFHandle pdbf = DBFOpen((char *)C22<MAX_PATH>(sFileName), "r+b");
if (pdbf)
{
//> 获取DBF行数和列数目
int iColCount = DBFGetFieldCount(pdbf);
int iRowCount = DBFGetRecordCount(pdbf);//行数仅仅是内容的行数,不包含行头
DBFFieldType filedType[64];
char szfiledName[64] = "";
int nWidth = 0;
int nDecimal = 0;
//保存没一列的数据类型
for (int iCol = 0; iCol < iColCount; ++iCol)
{
filedType[iCol] = DBFGetFieldInfo(pdbf, iCol, szfiledName, &nWidth, &nDecimal);
}
for (int iRow = 0; iRow < iRowCount; iRow++)
{
for (int iCol = 0; iCol < iColCount;++iCol)
{
///> 通过列的数据类型读取数据
switch (filedType[iCol])
{
case FTString:
{
const char *val = DBFReadStringAttribute(pdbf, iRow, iCol);
int a = 0;
}
break;
case FTInteger:
{
int ival = DBFReadIntegerAttribute(pdbf, iRow, iCol);
int a = 0;
}
break;
case FTDouble:
{
double dval = DBFReadDoubleAttribute(pdbf, iRow, iCol);
int a = 0;
}
break;
case FTLogical:
{
const char *val = DBFReadLogicalAttribute(pdbf, iRow, iCol);
int a = 0;
}
break;
default:
break;
}
}
}
//> 使用完关闭DBF文件
DBFClose(pdbf);
return TRUE;
}
return FALSE;
}