Skip to content

Commit

Permalink
GDALDataset::ICreateLayer(): now takes a const OGRSpatialReference* i…
Browse files Browse the repository at this point in the history
…nstead of a OGRSpatialReference*. Affects out-of-tree drivers (fixes OSGeo#8493)
  • Loading branch information
rouault committed Sep 29, 2023
1 parent c095015 commit 4b10700
Show file tree
Hide file tree
Showing 121 changed files with 345 additions and 336 deletions.
8 changes: 8 additions & 0 deletions MIGRATION_GUIDE.TXT
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
MIGRATION GUIDE FROM GDAL 3.7 to GDAL 3.8
-----------------------------------------

- Out-of-tree vector drivers:
* GDALDataset::ICreateLayer() now takes a const OGRSpatialReference* instead
of a OGRSpatialReference*. Drivers should clone the passed SRS if they need
to keep it.

MIGRATION GUIDE FROM GDAL 3.6 to GDAL 3.7
-----------------------------------------

Expand Down
5 changes: 3 additions & 2 deletions frmts/fits/fitsdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class FITSDataset final : public GDALPamDataset
}
OGRLayer *GetLayer(int) override;

OGRLayer *ICreateLayer(const char *pszName, OGRSpatialReference *poSRS,
OGRLayer *ICreateLayer(const char *pszName,
const OGRSpatialReference *poSRS,
OGRwkbGeometryType eGType,
char **papszOptions) override;
int TestCapability(const char *pszCap) override;
Expand Down Expand Up @@ -2315,7 +2316,7 @@ OGRLayer *FITSDataset::GetLayer(int idx)
/************************************************************************/

OGRLayer *FITSDataset::ICreateLayer(const char *pszName,
OGRSpatialReference * /* poSRS */,
const OGRSpatialReference * /* poSRS */,
OGRwkbGeometryType eGType,
char **papszOptions)
{
Expand Down
8 changes: 4 additions & 4 deletions frmts/netcdf/netcdfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7651,7 +7651,7 @@ OGRLayer *netCDFDataset::GetLayer(int nIdx)
/************************************************************************/

OGRLayer *netCDFDataset::ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef,
const OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType,
char **papszOptions)
{
Expand Down Expand Up @@ -7719,10 +7719,10 @@ OGRLayer *netCDFDataset::ICreateLayer(const char *pszName,

// Make a clone to workaround a bug in released MapServer versions
// that destroys the passed SRS instead of releasing it .
OGRSpatialReference *poSRS = poSpatialRef;
if (poSRS != nullptr)
OGRSpatialReference *poSRS = nullptr;
if (poSpatialRef)
{
poSRS = poSRS->Clone();
poSRS = poSpatialRef->Clone();
poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
}
std::shared_ptr<netCDFLayer> poLayer(
Expand Down
2 changes: 1 addition & 1 deletion frmts/netcdf/netcdfdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ class netCDFDataset final : public GDALPamDataset
CPLXMLNode *SerializeToXML(const char *pszVRTPath) override;

virtual OGRLayer *ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef,
const OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType,
char **papszOptions) override;

Expand Down
16 changes: 8 additions & 8 deletions frmts/null/nulldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GDALNullDataset final : public GDALDataset
virtual OGRLayer *GetLayer(int) override;

virtual OGRLayer *ICreateLayer(const char *pszLayerName,
OGRSpatialReference *poSRS,
const OGRSpatialReference *poSRS,
OGRwkbGeometryType eType,
char **papszOptions) override;

Expand Down Expand Up @@ -93,10 +93,10 @@ class GDALNullRasterBand final : public GDALRasterBand
class GDALNullLayer final : public OGRLayer
{
OGRFeatureDefn *poFeatureDefn;
OGRSpatialReference *poSRS;
OGRSpatialReference *poSRS = nullptr;

public:
GDALNullLayer(const char *pszLayerName, OGRSpatialReference *poSRS,
GDALNullLayer(const char *pszLayerName, const OGRSpatialReference *poSRS,
OGRwkbGeometryType eType);
virtual ~GDALNullLayer();

Expand Down Expand Up @@ -222,7 +222,7 @@ GDALNullDataset::~GDALNullDataset()
/************************************************************************/

OGRLayer *GDALNullDataset::ICreateLayer(const char *pszLayerName,
OGRSpatialReference *poSRS,
const OGRSpatialReference *poSRS,
OGRwkbGeometryType eType, char **)
{
m_papoLayers = static_cast<OGRLayer **>(
Expand Down Expand Up @@ -329,16 +329,16 @@ GDALDataset *GDALNullDataset::Create(const char *, int nXSize, int nYSize,
/************************************************************************/

GDALNullLayer::GDALNullLayer(const char *pszLayerName,
OGRSpatialReference *poSRSIn,
const OGRSpatialReference *poSRSIn,
OGRwkbGeometryType eType)
: poFeatureDefn(new OGRFeatureDefn(pszLayerName)), poSRS(poSRSIn)
: poFeatureDefn(new OGRFeatureDefn(pszLayerName))
{
SetDescription(poFeatureDefn->GetName());
poFeatureDefn->SetGeomType(eType);
poFeatureDefn->Reference();

if (poSRS)
poSRS->Reference();
if (poSRSIn)
poSRS = poSRSIn->Clone();
}

/************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion frmts/pcidsk/pcidskdataset2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2106,7 +2106,7 @@ OGRLayer *PCIDSK2Dataset::GetLayer(int iLayer)
/************************************************************************/

OGRLayer *PCIDSK2Dataset::ICreateLayer(const char *pszLayerName,
OGRSpatialReference *poSRS,
const OGRSpatialReference *poSRS,
OGRwkbGeometryType eType,
CPL_UNUSED char **papszOptions)
{
Expand Down
2 changes: 1 addition & 1 deletion frmts/pcidsk/pcidskdataset2.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class PCIDSK2Dataset final : public GDALPamDataset

virtual int TestCapability(const char *) override;

virtual OGRLayer *ICreateLayer(const char *, OGRSpatialReference *,
virtual OGRLayer *ICreateLayer(const char *, const OGRSpatialReference *,
OGRwkbGeometryType, char **) override;
};

Expand Down
2 changes: 1 addition & 1 deletion frmts/pdf/gdal_pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ class PDFWritableVectorDataset final : public GDALDataset
virtual ~PDFWritableVectorDataset();

virtual OGRLayer *ICreateLayer(const char *pszLayerName,
OGRSpatialReference *poSRS,
const OGRSpatialReference *poSRS,
OGRwkbGeometryType eType,
char **papszOptions) override;

Expand Down
14 changes: 7 additions & 7 deletions frmts/pdf/pdfwritabledataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ GDALDataset *PDFWritableVectorDataset::Create(const char *pszName, int nXSize,
/* ICreateLayer() */
/************************************************************************/

OGRLayer *PDFWritableVectorDataset::ICreateLayer(const char *pszLayerName,
OGRSpatialReference *poSRS,
OGRwkbGeometryType eType,
char **)
OGRLayer *
PDFWritableVectorDataset::ICreateLayer(const char *pszLayerName,
const OGRSpatialReference *poSRS,
OGRwkbGeometryType eType, char **)
{
/* -------------------------------------------------------------------- */
/* Create the layer object. */
/* -------------------------------------------------------------------- */
auto poSRSClone = poSRS;
if (poSRSClone)
OGRSpatialReference *poSRSClone = nullptr;
if (poSRS)
{
poSRSClone = poSRSClone->Clone();
poSRSClone = poSRS->Clone();
poSRSClone->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
}
OGRLayer *poLayer =
Expand Down
2 changes: 1 addition & 1 deletion frmts/pds/pds4dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4160,7 +4160,7 @@ void PDS4Dataset::WriteHeader()
/************************************************************************/

OGRLayer *PDS4Dataset::ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef,
const OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType,
char **papszOptions)
{
Expand Down
10 changes: 5 additions & 5 deletions frmts/pds/pds4dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class PDS4FixedWidthTable CPL_NON_FINAL : public PDS4TableBaseLayer

bool ReadTableDef(const CPLXMLNode *psTable);

bool InitializeNewLayer(OGRSpatialReference *poSRS, bool bForceGeographic,
OGRwkbGeometryType eGType,
bool InitializeNewLayer(const OGRSpatialReference *poSRS,
bool bForceGeographic, OGRwkbGeometryType eGType,
const char *const *papszOptions);

virtual PDS4FixedWidthTable *NewLayer(PDS4Dataset *poDS,
Expand Down Expand Up @@ -276,8 +276,8 @@ class PDS4DelimitedTable CPL_NON_FINAL : public PDS4TableBaseLayer

bool ReadTableDef(const CPLXMLNode *psTable);

bool InitializeNewLayer(OGRSpatialReference *poSRS, bool bForceGeographic,
OGRwkbGeometryType eGType,
bool InitializeNewLayer(const OGRSpatialReference *poSRS,
bool bForceGeographic, OGRwkbGeometryType eGType,
const char *const *papszOptions);

void RefreshFileAreaObservational(CPLXMLNode *psFAO) override;
Expand Down Expand Up @@ -409,7 +409,7 @@ class PDS4Dataset final : public RawDataset
OGRLayer *GetLayer(int) override;

OGRLayer *ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef,
const OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType,
char **papszOptions) override;
int TestCapability(const char *pszCap) override;
Expand Down
4 changes: 2 additions & 2 deletions frmts/pds/pds4vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ OGRErr PDS4FixedWidthTable::CreateField(OGRFieldDefn *poFieldIn, int)
/* InitializeNewLayer() */
/************************************************************************/

bool PDS4FixedWidthTable::InitializeNewLayer(OGRSpatialReference *poSRS,
bool PDS4FixedWidthTable::InitializeNewLayer(const OGRSpatialReference *poSRS,
bool bForceGeographic,
OGRwkbGeometryType eGType,
const char *const *papszOptions)
Expand Down Expand Up @@ -2485,7 +2485,7 @@ char **PDS4DelimitedTable::GetFileList() const
/* InitializeNewLayer() */
/************************************************************************/

bool PDS4DelimitedTable::InitializeNewLayer(OGRSpatialReference *poSRS,
bool PDS4DelimitedTable::InitializeNewLayer(const OGRSpatialReference *poSRS,
bool bForceGeographic,
OGRwkbGeometryType eGType,
const char *const *papszOptions)
Expand Down
2 changes: 1 addition & 1 deletion frmts/tiledb/tiledbheaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class OGRTileDBDataset final : public TileDBDataset
}
int TestCapability(const char *) override;
OGRLayer *ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef = nullptr,
const OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown,
char **papszOptions = nullptr) override;
static GDALDataset *Open(GDALOpenInfo *, tiledb::Object::Type objectType);
Expand Down
8 changes: 4 additions & 4 deletions frmts/tiledb/tiledbsparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ OGRLayer *OGRTileDBDataset::ExecuteSQL(const char *pszSQLCommand,
/***********************************************************************/
/* ICreateLayer() */
/***********************************************************************/
OGRLayer *OGRTileDBDataset::ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType,
char **papszOptions)
OGRLayer *
OGRTileDBDataset::ICreateLayer(const char *pszName,
const OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType, char **papszOptions)
{
if (eAccess != GA_Update)
{
Expand Down
14 changes: 6 additions & 8 deletions gcore/gdal_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,9 @@ class CPL_DLL GDALDataset : public GDALMajorObject
UpdateRelationship(std::unique_ptr<GDALRelationship> &&relationship,
std::string &failureReason);

virtual OGRLayer *CreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown,
char **papszOptions = nullptr);
virtual OGRLayer *CreateLayer(
const char *pszName, const OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown, char **papszOptions = nullptr);
virtual OGRLayer *CopyLayer(OGRLayer *poSrcLayer, const char *pszNewName,
char **papszOptions = nullptr);

Expand Down Expand Up @@ -922,10 +921,9 @@ class CPL_DLL GDALDataset : public GDALMajorObject
//! @endcond

protected:
virtual OGRLayer *ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown,
char **papszOptions = nullptr);
virtual OGRLayer *ICreateLayer(
const char *pszName, const OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown, char **papszOptions = nullptr);

//! @cond Doxygen_Suppress
OGRErr ProcessSQLCreateIndex(const char *);
Expand Down
14 changes: 4 additions & 10 deletions gcore/gdaldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4726,10 +4726,7 @@ deprecated OGR_DS_CreateLayer().
@param pszName the name for the new layer. This should ideally not
match any existing layer on the datasource.
@param poSpatialRef the coordinate system to use for the new layer, or NULL if
no coordinate system is available. The driver might only increase
the reference counter of the object to take ownership, and not make a full copy,
so do not use OSRDestroySpatialReference(), but OSRRelease() instead when you
are done with the object.
no coordinate system is available.
@param eGType the geometry type for the layer. Use wkbUnknown if there
are no constraints on the types geometry to be written.
@param papszOptions a StringList of name=value options. Options are driver
Expand All @@ -4740,7 +4737,7 @@ specific.
*/

OGRLayer *GDALDataset::CreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef,
const OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType,
char **papszOptions)

Expand Down Expand Up @@ -4818,10 +4815,7 @@ This method is the same as the C++ method GDALDataset::CreateLayer().
@param pszName the name for the new layer. This should ideally not
match any existing layer on the datasource.
@param hSpatialRef the coordinate system to use for the new layer, or NULL if
no coordinate system is available. The driver might only increase
the reference counter of the object to take ownership, and not make a full copy,
so do not use OSRDestroySpatialReference(), but OSRRelease() instead when you
are done with the object.
no coordinate system is available.
@param eGType the geometry type for the layer. Use wkbUnknown if there
are no constraints on the types geometry to be written.
@param papszOptions a StringList of name=value options. Options are driver
Expand Down Expand Up @@ -5198,7 +5192,7 @@ int GDALDataset::GetSummaryRefCount() const

OGRLayer *
GDALDataset::ICreateLayer(CPL_UNUSED const char *pszName,
CPL_UNUSED OGRSpatialReference *poSpatialRef,
CPL_UNUSED const OGRSpatialReference *poSpatialRef,
CPL_UNUSED OGRwkbGeometryType eGType,
CPL_UNUSED char **papszOptions)

Expand Down
9 changes: 5 additions & 4 deletions gnm/gnm_frmts/db/gnmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ class GNMDatabaseNetwork : public GNMGenericNetwork
char **papszOptions) override;

protected:
virtual OGRLayer *ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown,
char **papszOptions = nullptr) override;
virtual OGRLayer *
ICreateLayer(const char *pszName,
const OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown,
char **papszOptions = nullptr) override;
virtual int CheckNetworkExist(const char *pszFilename,
char **papszOptions) override;

Expand Down
2 changes: 1 addition & 1 deletion gnm/gnm_frmts/db/gnmdbnetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ OGRErr GNMDatabaseNetwork::DeleteLayer(int nIndex)

OGRLayer *
GNMDatabaseNetwork::ICreateLayer(const char *pszName,
OGRSpatialReference * /*poSpatialRef*/,
const OGRSpatialReference * /*poSpatialRef*/,
OGRwkbGeometryType eGType, char **papszOptions)
{
// check if layer with such name exist
Expand Down
9 changes: 5 additions & 4 deletions gnm/gnm_frmts/file/gnmfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ class GNMFileNetwork : public GNMGenericNetwork
char **papszOptions) override;

protected:
virtual OGRLayer *ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown,
char **papszOptions = nullptr) override;
virtual OGRLayer *
ICreateLayer(const char *pszName,
const OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown,
char **papszOptions = nullptr) override;
virtual int CheckNetworkExist(const char *pszFilename,
char **papszOptions) override;

Expand Down
8 changes: 4 additions & 4 deletions gnm/gnm_frmts/file/gnmfilenetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ OGRErr GNMFileNetwork::DeleteLayer(int nIndex)
return GNMGenericNetwork::DeleteLayer(nIndex);
}

OGRLayer *GNMFileNetwork::ICreateLayer(const char *pszName,
OGRSpatialReference * /* poSpatialRef */,
OGRwkbGeometryType eGType,
char **papszOptions)
OGRLayer *
GNMFileNetwork::ICreateLayer(const char *pszName,
const OGRSpatialReference * /* poSpatialRef */,
OGRwkbGeometryType eGType, char **papszOptions)
{
if (nullptr == m_poLayerDriver)
{
Expand Down
9 changes: 5 additions & 4 deletions ogr/ogrsf_frmts/amigocloud/ogr_amigocloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,11 @@ class OGRAmigoCloudDataSource final : public OGRDataSource

virtual int TestCapability(const char *) override;

virtual OGRLayer *ICreateLayer(const char *pszName,
OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown,
char **papszOptions = nullptr) override;
virtual OGRLayer *
ICreateLayer(const char *pszName,
const OGRSpatialReference *poSpatialRef = nullptr,
OGRwkbGeometryType eGType = wkbUnknown,
char **papszOptions = nullptr) override;
virtual OGRErr DeleteLayer(int) override;

virtual OGRLayer *ExecuteSQL(const char *pszSQLCommand,
Expand Down
Loading

0 comments on commit 4b10700

Please sign in to comment.