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,77 @@ 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
+ void *pScaledData = GDALCreateScaledProgress (
186
+ static_cast <double >(iLayer) / poDS->GetLayerCount (),
187
+ static_cast <double >(iLayer + 1 ) / poDS->GetLayerCount (),
188
+ pfnProgress, pProgressData);
189
+ const bool bRet = poLayer->Repack (
190
+ pScaledData ? GDALScaledProgress : nullptr , pScaledData);
191
+ GDALDestroyScaledProgress (pScaledData);
192
+ if (!bRet)
193
+ {
194
+ ReportError (CE_Failure, CPLE_AppDefined,
195
+ " Repack of layer %s failed" , poLayer->GetName ());
196
+ bSuccess = false ;
197
+ }
198
+ ++iLayer;
199
+ }
200
+ return bSuccess;
201
+ }
202
+
203
+ private:
204
+ GDALArgDatasetValue m_dataset{};
205
+ };
206
+
207
+ /* ***********************************************************************/
208
+ /* OGROpenFileGDBInstantiateAlgorithm() */
209
+ /* ***********************************************************************/
210
+
211
+ static GDALAlgorithm *
212
+ OGROpenFileGDBInstantiateAlgorithm (const std::vector<std::string> &aosPath)
213
+ {
214
+ if (aosPath.size () == 1 && aosPath[0 ] == " repack" )
215
+ {
216
+ return std::make_unique<OpenFileGDBRepackAlgorithm>().release ();
217
+ }
218
+ else
219
+ {
220
+ return nullptr ;
221
+ }
222
+ }
223
+
152
224
/* **********************************************************************/
153
225
/* RegisterOGROpenFileGDB() */
154
226
/* **********************************************************************/
@@ -168,6 +240,7 @@ void RegisterOGROpenFileGDB()
168
240
poDriver->pfnOpen = OGROpenFileGDBDriverOpen;
169
241
poDriver->pfnCreate = OGROpenFileGDBDriverCreate;
170
242
poDriver->pfnDelete = OGROpenFileGDBDriverDelete;
243
+ poDriver->pfnInstantiateAlgorithm = OGROpenFileGDBInstantiateAlgorithm;
171
244
172
245
GetGDALDriverManager ()->RegisterDriver (poDriver);
173
246
}
0 commit comments