資源簡介
用MFC實現(xiàn)對SHAPFILE文件的讀取和現(xiàn)實,主要調(diào)用GDAL庫文件。在這兒將主要的代碼粘貼下來。
代碼片段和文件信息
#include?“stdafx.h“
#include?“MyShapFile.h“
#define?MaxFileNameSize?255
#define?MaxPointsNumber?3000
#define?MAX_WEIGHT?6
CMyShapFile::CMyShapFile()
:?//Filepath(NULL)
?m_filepath(NULL)
?PointNum(0)
{
}
CMyShapFile::~CMyShapFile()
{
}
//?讀取文件
bool?CMyShapFile::ReadFile()
{
//this->m_filepath?=?Path;
OGRRegisterAll();
OGRDataSource?*poDS?=?OGRSFDriverRegistrar::Open(this->m_filepath?FALSE);
if?(NULL?==?poDS)
{
//AfxMessageBox();
AfxMessageBox(_T(“讀取失敗“));
CString?str;
str?=?this->m_filepath;
AfxMessageBox(str);
//cout<<“ReadFile?Failed!“< return?false;
}
OGRlayer?*polayer?=?poDS->Getlayer(0);
OGRFeature?*poFeature?=?polayer->GetNextFeature();
while?(NULL?!=?poFeature)
{
//讀取屬性數(shù)據(jù)
//OGRFeatureDefn?int?iField
//讀取幾何數(shù)據(jù)
OGRGeometry?*?poGeometry?=?poFeature->GetGeometryRef();
if?(NULL?!=?poGeometry?&&?wkbFlatten(poGeome
評論
共有 條評論