When I am converting my geopackage file in shapefile, the unique ID field is not exported. I could duplicate it before exportation, but I wanted to know if it could be done in one step, in order not to modify my geopackage. I am using ogr2ogr to make the conversion.

  • 1
    If you run ogrinfo your_geopackage.gpkg -al -so, what is the name of the FID column, and is that the unique ID field that you want to save into shapefile? – user30184 Jan 3 at 12:55
  • Indeed, the FID column is the attribute field NewID (FID Column = NewID) that I would like to save in the shapefile, in addition to the other attribute fields. – Philippe Malcorps Jan 3 at 13:01

This should work

ogr2ogr -f "ESRI Shapefile" -dialect SQLite -sql "select NewID as source_id,* from your_layer" exported_layer.shp your_geopackage.gpkg

It may not be necessary to rename NewID, or it may work if you rename it with an original name select NewID as NewID.... I had a test with GeoPackage using field "fid" as FID and then I had to rename it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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