Skip to content

Commit

Permalink
PDF: remove use of OGRDataSourceH
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Sep 19, 2024
1 parent 25e5386 commit 79d3f20
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions frmts/pdf/pdfcreatecopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2178,13 +2178,15 @@ bool GDALPDFWriter::WriteOGRDataSource(const char *pszOGRDataSource,
const char *pszOGRLinkField,
int bWriteOGRAttributes)
{
OGRDataSourceH hDS = OGROpen(pszOGRDataSource, 0, nullptr);
GDALDatasetH hDS =
GDALOpenEx(pszOGRDataSource, GDAL_OF_VECTOR | GDAL_OF_VERBOSE_ERROR,
nullptr, nullptr, nullptr);
if (hDS == nullptr)
return false;

int iObj = 0;

int nLayers = OGR_DS_GetLayerCount(hDS);
int nLayers = GDALDatasetGetLayerCount(hDS);

char **papszLayerNames =
CSLTokenizeString2(pszOGRDisplayLayerNames, ",", 0);
Expand All @@ -2193,15 +2195,15 @@ bool GDALPDFWriter::WriteOGRDataSource(const char *pszOGRDataSource,
{
CPLString osLayerName;
if (CSLCount(papszLayerNames) < nLayers)
osLayerName = OGR_L_GetName(OGR_DS_GetLayer(hDS, iLayer));
osLayerName = OGR_L_GetName(GDALDatasetGetLayer(hDS, iLayer));
else
osLayerName = papszLayerNames[iLayer];

WriteOGRLayer(hDS, iLayer, pszOGRDisplayField, pszOGRLinkField,
osLayerName, bWriteOGRAttributes, iObj);
}

OGRReleaseDataSource(hDS);
GDALClose(hDS);

CSLDestroy(papszLayerNames);

Expand Down Expand Up @@ -2286,7 +2288,7 @@ int GDALPDFWriter::WriteOGRLayer(OGRDataSourceH hDS, int iLayer,

GDALPDFLayerDesc osVectorDesc =
StartOGRLayer(osLayerName, bWriteOGRAttributes);
OGRLayerH hLyr = OGR_DS_GetLayer(hDS, iLayer);
OGRLayerH hLyr = GDALDatasetGetLayer(hDS, iLayer);

const auto poLayerDefn = OGRLayer::FromHandle(hLyr)->GetLayerDefn();
for (int i = 0; i < poLayerDefn->GetFieldCount(); i++)
Expand Down
2 changes: 1 addition & 1 deletion frmts/pdf/pdfcreatecopy.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class GDALPDFWriter final : public GDALPDFBaseWriter
int bWriteOGRAttributes);
void EndOGRLayer(GDALPDFLayerDesc &osVectorDesc);

int WriteOGRLayer(OGRDataSourceH hDS, int iLayer,
int WriteOGRLayer(GDALDatasetH hDS, int iLayer,
const char *pszOGRDisplayField,
const char *pszOGRLinkField,
const std::string &osLayerName, int bWriteOGRAttributes,
Expand Down
6 changes: 3 additions & 3 deletions frmts/pdf/pdfwritabledataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ OGRErr PDFWritableVectorDataset::SyncToDisk()
else
osLayerName = papszLayerNames[i];

oWriter.WriteOGRLayer((OGRDataSourceH)this, i, pszOGRDisplayField,
pszOGRLinkField, osLayerName, bWriteOGRAttributes,
iObj);
oWriter.WriteOGRLayer(GDALDataset::ToHandle(this), i,
pszOGRDisplayField, pszOGRLinkField, osLayerName,
bWriteOGRAttributes, iObj);
}

CSLDestroy(papszLayerNames);
Expand Down

0 comments on commit 79d3f20

Please sign in to comment.