Skip to content

Commit

Permalink
FlatGeoBuf: implement OGRLayer::GetDataset() (refs OSGeo#9568)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 27, 2024
1 parent c54fd13 commit e7c34fa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
11 changes: 9 additions & 2 deletions ogr/ogrsf_frmts/flatgeobuf/ogr_flatgeobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class OGRFlatGeobufLayer final : public OGRLayer,
bool m_ignoreAttributeFilter = false;

// creation
GDALDataset *m_poDS = nullptr; // parent dataset to get metadata from it
bool m_create = false;
std::deque<FeatureItem> m_featureItems; // feature item description used to
// create spatial index
Expand Down Expand Up @@ -142,7 +143,8 @@ class OGRFlatGeobufLayer final : public OGRLayer,
OGRFlatGeobufLayer(const FlatGeobuf::Header *, GByte *headerBuf,
const char *pszFilename, VSILFILE *poFp,
uint64_t offset);
OGRFlatGeobufLayer(const char *pszLayerName, const char *pszFilename,
OGRFlatGeobufLayer(GDALDataset *poDS, const char *pszLayerName,
const char *pszFilename,
const OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType,
bool bCreateSpatialIndexAtClose, VSILFILE *poFpWrite,
Expand All @@ -163,7 +165,7 @@ class OGRFlatGeobufLayer final : public OGRLayer,
static OGRFlatGeobufLayer *Open(const char *pszFilename, VSILFILE *fp,
bool bVerifyBuffers);
static OGRFlatGeobufLayer *
Create(const char *pszLayerName, const char *pszFilename,
Create(GDALDataset *poDS, const char *pszLayerName, const char *pszFilename,
const OGRSpatialReference *poSpatialRef, OGRwkbGeometryType eGType,
bool bCreateSpatialIndexAtClose, char **papszOptions);

Expand Down Expand Up @@ -192,6 +194,11 @@ class OGRFlatGeobufLayer final : public OGRLayer,
m_bVerifyBuffers = CPL_TO_BOOL(bFlag);
}

GDALDataset *GetDataset() override
{
return m_poDS;
}

const std::string &GetFilename() const override
{
return m_osFilename;
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/flatgeobuf/ogrflatgeobufdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ OGRLayer *OGRFlatGeobufDataset::ICreateLayer(

auto poLayer =
std::unique_ptr<OGRFlatGeobufLayer>(OGRFlatGeobufLayer::Create(
pszLayerName, osFilename, poSpatialRef, eGType,
this, pszLayerName, osFilename, poSpatialRef, eGType,
bCreateSpatialIndexAtClose, papszOptions));
if (poLayer == nullptr)
return nullptr;
Expand Down
5 changes: 3 additions & 2 deletions ogr/ogrsf_frmts/flatgeobuf/ogrflatgeobufeditablelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ OGRErr OGRFlatGeobufEditableLayerSynchronizer::EditableSyncToDisk(
auto createIndex = m_poFlatGeobufLayer->GetIndexNodeSize() > 0;

OGRFlatGeobufLayer *poFlatGeobufTmpLayer = OGRFlatGeobufLayer::Create(
osLayerName.c_str(), osTmpFilename.c_str(), spatialRef, gType,
createIndex, m_papszOpenOptions);
m_poFlatGeobufLayer->GetDataset(), osLayerName.c_str(),
osTmpFilename.c_str(), spatialRef, gType, createIndex,
m_papszOpenOptions);
if (poFlatGeobufTmpLayer == nullptr)
return OGRERR_FAILURE;

Expand Down
25 changes: 11 additions & 14 deletions ogr/ogrsf_frmts/flatgeobuf/ogrflatgeobuflayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,12 @@ OGRFlatGeobufLayer::OGRFlatGeobufLayer(const Header *poHeader, GByte *headerBuf,
m_poFeatureDefn->Reference();
}

OGRFlatGeobufLayer::OGRFlatGeobufLayer(const char *pszLayerName,
const char *pszFilename,
const OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType,
bool bCreateSpatialIndexAtClose,
VSILFILE *poFpWrite,
std::string &osTempFile)
: m_eGType(eGType),
OGRFlatGeobufLayer::OGRFlatGeobufLayer(
GDALDataset *poDS, const char *pszLayerName, const char *pszFilename,
const OGRSpatialReference *poSpatialRef, OGRwkbGeometryType eGType,
bool bCreateSpatialIndexAtClose, VSILFILE *poFpWrite,
std::string &osTempFile)
: m_eGType(eGType), m_poDS(poDS),
m_bCreateSpatialIndexAtClose(bCreateSpatialIndexAtClose),
m_poFpWrite(poFpWrite), m_osTempFile(osTempFile)
{
Expand Down Expand Up @@ -2409,19 +2407,18 @@ VSILFILE *OGRFlatGeobufLayer::CreateOutputFile(const CPLString &osFilename,
return poFpWrite;
}

OGRFlatGeobufLayer *
OGRFlatGeobufLayer::Create(const char *pszLayerName, const char *pszFilename,
const OGRSpatialReference *poSpatialRef,
OGRwkbGeometryType eGType,
bool bCreateSpatialIndexAtClose, char **papszOptions)
OGRFlatGeobufLayer *OGRFlatGeobufLayer::Create(
GDALDataset *poDS, const char *pszLayerName, const char *pszFilename,
const OGRSpatialReference *poSpatialRef, OGRwkbGeometryType eGType,
bool bCreateSpatialIndexAtClose, char **papszOptions)
{
std::string osTempFile = GetTempFilePath(pszFilename, papszOptions);
VSILFILE *poFpWrite =
CreateOutputFile(pszFilename, papszOptions, bCreateSpatialIndexAtClose);
if (poFpWrite == nullptr)
return nullptr;
OGRFlatGeobufLayer *layer = new OGRFlatGeobufLayer(
pszLayerName, pszFilename, poSpatialRef, eGType,
poDS, pszLayerName, pszFilename, poSpatialRef, eGType,
bCreateSpatialIndexAtClose, poFpWrite, osTempFile);
return layer;
}
Expand Down

0 comments on commit e7c34fa

Please sign in to comment.