Suppose I have a feature class in a GDB here: C:\MyDir\MyGDB.gdb\my_dataset\my_feature. I want to export this feature class to a geopackage here: C:\MyDir\MyGPKP.gpkg using the gdal vector tool ogr2ogr. Since I am working outside of an ESRI environment and only need to read from my GDB, I assume I can use the format -f OpenFileGDB. My confusion is how to set up the command line syntax to achieve this. Assuming I am working in my ...\OSGEO4W\bin directory, this is what I have tried:

ogr2ogr -f "GPKG" "C:\MyDir\MyGPKP.gpkg\new_feature" "C:\MyDir\MyGDB.gdb" -lco FEATURE_DATASET=my_dataset my_feature

I am getting errors about the Failure to open datasource with the following driver: I think I do not understand how to properly format my command and cannot seem to find an example of how to do this in the gdal documentation. Any suggestions?


1 Answer 1


-lco is a layer creation option. Just pass the featureclass name and ignore the feature dataset:

ogr2ogr -f GPKG "C:\MyDir\MyGPKP.gpkg" "C:\MyDir\MyGDB.gdb" my_feature

And if you want to rename the new gpkg layer, use the -nln argument:

ogr2ogr -f GPKG "C:\MyDir\MyGPKP.gpkg" -nln newlayername "C:\MyDir\MyGDB.gdb" my_feature
  • I believe this is the right solution, but....apparently I have some null values that are causing a failed to execute insert: NOT NULL constraint failed. I need those nulls. I know there is a tag to either force or remove the default null constraint (-forceNullable & -unsetDefault). Where would I add them to ogr2ogr -f "GPKG" "C:\MyDir\MyGPKP.gpkg" "C:\MyDir\MyGDB.gdb" "my_feature" ?
    – gwydion93
    Commented Oct 20, 2022 at 23:23
  • 2
    I think that needs to be a separate question gis.stackexchange.com/questions/ask
    – user2856
    Commented Oct 20, 2022 at 23:30
  • Will do. Thanks for the assist.
    – gwydion93
    Commented Oct 20, 2022 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.