• 大小: 68.28MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2022-12-02
  • 语言: C/C++
  • 标签: GDAL  GIS  shp  

资源简介

使用C++并利用GDAL库实现对GIS中shp数据的读取和显示。该版本没有放缩功能,有简陋版放缩功能的版本,如有需要可以下载后评论可获取。

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “DataAdd.h“



DataAdd*DataAdd::m_pInstance = NULL;


IMPLEMENT_DYNAMIC(DataAdd CWnd)

DataAdd::DataAdd()
{
OGRGeometry*poGeomtry = NULL;
}


DataAdd::~DataAdd()
{
}





OGRlayer* DataAdd::ShpDataAdd(CString FilePathName)
{

Instance();


//OGRDataSource *poDS = NULL;
//poDS = OGRSFDriverRegistrar::Open(FilePathName FALSE);
const char* filename = FilePathName.GetBuffer(sizeof(FilePathName));
GDALDataset*poDS = (GDALDataset*)GDALOpenEx(filename GDAL_OF_VECTOR NULL NULL NULL);

//Draw(poDS);
if (poDS == NULL)
{
printf(“数据源打开失败\n“);
}

/*if (poDS->GetlayerCount()<0)
{
printf(“当前图层无效!\n“);
}*/

OGRlayer*polayer = NULL;
polayer = poDS->Getlayer(0);


return polayer;
}

OGRlayer*DataAdd::FromPath(const string&strFilePath)
{
Instance();
//新版本修改的去除了OGRDataSource类
GDALDataset*poDS = (GDALDataset*)GDALOpenEx(strFilePath.c_str() GDAL_OF_VECTOR NULL NULL NULL);

if (poDS == NULL)
{
printf(“数据源打开失败\n“);
return NULL;
}
if (poDS->GetlayerCount() < 0)
{
printf(“当前图层无效!\n“);
return NULL;
}

OGRlayer* polayer = NULL;
polayer = poDS->Getlayer(0);


DestoryInstance();
return polayer;

}

void DataAdd::DestoryInstance()
{
if (NULL != m_pInstance)
{
delete m_pInstance;
m_pInstance = NULL;
}
}


DataAdd*DataAdd::Instance()
{
if (NULL == m_pInstance)
{
m_pInstance = new DataAdd();
}
return m_pInstance;
}



void DataAdd::getView(CView *View)
{
pView = View;
}



OGRGeometry* DataAdd::getOGRGeometry()
{
return poGeometry;
}

OGRwkbGeometryType DataAdd::getOGRwkbGeometryType()
{
return eGeometryType;
}


void DataAdd::Draw(OGRlayer* poDS)
{
CClientDC dc(pView);

OGRlayer* polayer = poDS;
OGRFeature *pFeature = NULL;
OGREnvelope *poEnvelope = new OGREnvelope();

polayer->GetExtent(poEnvelope);

CRect rect;
pView->GetClientRect(&rect);

IMapRender *pMapRender = new IMapRender();
pMapRender->GetScale(poEnvelope rect);

polayer->ResetReading();
while ((pFeature = polayer->GetNextFeature()) != NULL)
{
poGeometry = pFeature->GetGeometryRef();
eGeometryType = poGeometry->getGeometryType();

switch (eGeometryType)
{
//处理点
case wkbPoint25D:
case wkbPoint:
{
 OGRPoint* poPoint = NULL;
 poPoint = (OGRPoint*)poGeometry;

 double centerx = poPoint->getX();
 double centery = poPoint->getY();
 pMapRender->WorldToClinet(centerx centery);

 CRect pp(centerx - 3 centery - 3 centerx + 3 centery + 3);
 CBrush brush;
 brush.CreateSolidBrush(RGB(255 0 0));
 dc.Selectobject(brush);
 dc.Ellipse(pp);
}
break;
//处理线
case wkbLineString:
case wkbLineString25D:
{
 OGRLineString* poLineString = NULL;
 poLineString = (OGRLineString*)poGeometry;

 int nLinePoints = poLineString->getNumPoints();

 OGRPoi

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-07-24 08:22  GDAL\
     目录           0  2017-07-24 17:34  GDAL\ReadShp\
     目录           0  2017-07-24 15:38  GDAL\ReadShp\Debug\
     文件      476160  2017-07-24 17:25  GDAL\ReadShp\Debug\ReadShp.exe
     文件      133147  2017-07-24 15:38  GDAL\ReadShp\Debug\ReadShp.exp
     文件     3469744  2017-07-24 17:25  GDAL\ReadShp\Debug\ReadShp.ilk
     文件      220084  2017-07-24 15:38  GDAL\ReadShp\Debug\ReadShp.lib
     文件     8899584  2017-07-24 17:25  GDAL\ReadShp\Debug\ReadShp.pdb
     目录           0  2017-07-24 08:26  GDAL\ReadShp\ipch\
     目录           0  2017-07-24 15:30  GDAL\ReadShp\ipch\readshp-ca4c9107\
     文件    94109696  2017-07-24 15:30  GDAL\ReadShp\ipch\readshp-ca4c9107\readshp-41d29033.ipch
     目录           0  2017-07-24 17:25  GDAL\ReadShp\ReadShp\
     文件    93126656  2017-07-24 17:34  GDAL\ReadShp\ReadShp.sdf
     文件         967  2017-07-24 08:22  GDAL\ReadShp\ReadShp.sln
     文件       27136  2017-07-24 17:34  GDAL\ReadShp\ReadShp.v12.suo
     文件        8048  2017-07-24 15:30  GDAL\ReadShp\ReadShp\DataAdd.cpp
     文件        1013  2017-07-24 15:39  GDAL\ReadShp\ReadShp\DataAdd.h
     目录           0  2017-07-24 17:25  GDAL\ReadShp\ReadShp\Debug\
     文件     1153963  2017-07-24 15:39  GDAL\ReadShp\ReadShp\Debug\DataAdd.obj
     文件       46150  2017-07-24 15:30  GDAL\ReadShp\ReadShp\Debug\MainFrm.obj
     文件     1204764  2017-07-24 15:38  GDAL\ReadShp\ReadShp\Debug\MapRender.obj
     文件         712  2017-07-24 14:57  GDAL\ReadShp\ReadShp\Debug\ReadShp.Build.CppClean.log
     文件        1592  2017-07-24 17:25  GDAL\ReadShp\ReadShp\Debug\ReadShp.log
     文件       52993  2017-07-24 17:25  GDAL\ReadShp\ReadShp\Debug\ReadShp.obj
     文件    49872896  2017-07-24 15:30  GDAL\ReadShp\ReadShp\Debug\ReadShp.pch
     文件       78188  2017-07-24 15:30  GDAL\ReadShp\ReadShp\Debug\ReadShp.res
     目录           0  2017-07-24 17:25  GDAL\ReadShp\ReadShp\Debug\ReadShp.tlog\
     文件        4920  2017-07-24 17:25  GDAL\ReadShp\ReadShp\Debug\ReadShp.tlog\cl.command.1.tlog
     文件       78460  2017-07-24 17:25  GDAL\ReadShp\ReadShp\Debug\ReadShp.tlog\CL.read.1.tlog
     文件        6280  2017-07-24 17:25  GDAL\ReadShp\ReadShp\Debug\ReadShp.tlog\CL.write.1.tlog
     文件        2096  2017-07-24 17:25  GDAL\ReadShp\ReadShp\Debug\ReadShp.tlog\link.command.1.tlog
............此处省略139个文件信息

评论

共有 条评论