GDAL读取Shapefile


--------------------------------------------------------------------------------------

#include <gdal_priv.h>
#include <ogrsf_frmts.h>

GDALAllRegister();
OGRDataSource* poDS;
const char* pszDriverName = "ESRI Shapefile";
//
GDALDriverManager* pDriverManager = GetGDALDriverManager(); //new GDALDriverManager();
GDALDriver* pDriver = pDriverManager->GetDriverByName(pszDriverName);
if (pDriver == nullptr)
{
  qDebug() << pszDriverName << " driver not available.";            
  return;
}
//
const char* filePathChar1 = "D:\\data";
OGRSFDriver* pSFDriver = static_cast<OGRSFDriver*>(pDriver);
OGRDataSource* pDataSource = pSFDriver->Open(filePathChar, FALSE);

/*
OGRSFDriverRegistrar* pDriverRegistrar = OGRSFDriverRegistrar::GetRegistrar();
OGRSFDriver* pSFDriver = (OGRSFDriver*)pDriverRegistrar->GetDriverByName(pszDriverName);
OGRDataSource* pDataSource = pSFDriver->Open(filePathChar, FALSE);
*/

------------------------------------------------------------------------------------------------


OGRLayer* pLayer = pDataSource->GetLayerByName(baseNameChar);
/*const char* geometryColumnName = pLayer->GetGeometryColumn();
int fieldIndex = pLayer->FindFieldIndex(geometryColumnName, TRUE);*/
// pEnvelopeDisplay
if (pLayerList.size() == 0) {
  OGREnvelope* pEnvelope = new OGREnvelope();
  pLayer->GetExtent(pEnvelope, TRUE);
  double centerX = (pEnvelope->MinX + pEnvelope->MaxX) / 2;
  double centerY = (pEnvelope->MinY + pEnvelope->MaxY) / 2;
  double distanceX = pEnvelope->MaxX - pEnvelope->MinX;
  double distanceY = pEnvelope->MaxY - pEnvelope->MinY;
  //
}


--------------------------------------------------------------------------------------------------

posted @ 2019-05-19 18:33  ParamousGIS  阅读(1497)  评论(0编辑  收藏  举报