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; // }
--------------------------------------------------------------------------------------------------