21
21
#include " cpl_vsi.h"
22
22
#include " gdal.h"
23
23
#include " gdal_priv.h"
24
+ #include " gdalalgorithm.h"
24
25
#include " ogr_core.h"
25
26
26
27
// g++ -O2 -Wall -Wextra -g -shared -fPIC ogr/ogrsf_frmts/openfilegdb/*.cpp
@@ -149,6 +150,74 @@ static CPLErr OGROpenFileGDBDriverDelete(const char *pszFilename)
149
150
return CE_None;
150
151
}
151
152
153
+ /* ***********************************************************************/
154
+ /* OpenFileGDBRepackAlgorithm */
155
+ /* ***********************************************************************/
156
+
157
+ class OpenFileGDBRepackAlgorithm final : public GDALAlgorithm
158
+ {
159
+ public:
160
+ OpenFileGDBRepackAlgorithm ()
161
+ : GDALAlgorithm(" repack" , std::string(" Repack a FileGDB dataset" ),
162
+ " /drivers/vector/openfilegdb.html" )
163
+ {
164
+ AddProgressArg ();
165
+ AddInputDatasetArg (&m_dataset,
166
+ GDAL_OF_RASTER | GDAL_OF_VECTOR | GDAL_OF_UPDATE);
167
+ }
168
+
169
+ protected:
170
+ bool RunImpl (GDALProgressFunc pfnProgress, void *pProgressData) override
171
+ {
172
+ auto poDS =
173
+ dynamic_cast <OGROpenFileGDBDataSource *>(m_dataset.GetDatasetRef ());
174
+ if (!poDS)
175
+ {
176
+ ReportError (CE_Failure, CPLE_AppDefined,
177
+ " %s is not a FileGeoDatabase" ,
178
+ m_dataset.GetName ().c_str ());
179
+ return false ;
180
+ }
181
+ bool bSuccess = true ;
182
+ int iLayer = 0 ;
183
+ for (auto &poLayer : poDS->GetLayers ())
184
+ {
185
+ if (!poLayer->Repack ())
186
+ {
187
+ ReportError (CE_Failure, CPLE_AppDefined,
188
+ " Repack of layer %s failed" , poLayer->GetName ());
189
+ bSuccess = false ;
190
+ }
191
+ ++iLayer;
192
+ if (pfnProgress && !pfnProgress (static_cast <double >(iLayer) /
193
+ poDS->GetLayerCount (),
194
+ " " , pProgressData))
195
+ return false ;
196
+ }
197
+ return bSuccess;
198
+ }
199
+
200
+ private:
201
+ GDALArgDatasetValue m_dataset{};
202
+ };
203
+
204
+ /* ***********************************************************************/
205
+ /* OGROpenFileGDBInstantiateAlgorithm() */
206
+ /* ***********************************************************************/
207
+
208
+ static GDALAlgorithm *
209
+ OGROpenFileGDBInstantiateAlgorithm (const std::vector<std::string> &aosPath)
210
+ {
211
+ if (aosPath.size () == 1 && aosPath[0 ] == " repack" )
212
+ {
213
+ return std::make_unique<OpenFileGDBRepackAlgorithm>().release ();
214
+ }
215
+ else
216
+ {
217
+ return nullptr ;
218
+ }
219
+ }
220
+
152
221
/* **********************************************************************/
153
222
/* RegisterOGROpenFileGDB() */
154
223
/* **********************************************************************/
@@ -168,6 +237,7 @@ void RegisterOGROpenFileGDB()
168
237
poDriver->pfnOpen = OGROpenFileGDBDriverOpen;
169
238
poDriver->pfnCreate = OGROpenFileGDBDriverCreate;
170
239
poDriver->pfnDelete = OGROpenFileGDBDriverDelete;
240
+ poDriver->pfnInstantiateAlgorithm = OGROpenFileGDBInstantiateAlgorithm;
171
241
172
242
GetGDALDriverManager ()->RegisterDriver (poDriver);
173
243
}
0 commit comments