id summary reporter owner description type status priority milestone component version severity resolution keywords cc 7007 ogr2ogr: FID index attribute not preserved hansw warmerdam "== Prerequisites Windows x64, GDAL version: 2.3.0 dev, trunk revision r39844, build from [http://www.gisinternals.com/query.html?content=filelist&file=release-1800-x64-gdal-mapserver.zip gisinternals.com]. I used GeoPackage v1.0 [http://www.geopackage.org/data/gdal_sample.gpkg GDAL Technology Test Data Set] and the [http://www.geopackage.org/data/sample1_0.gpkg Esri Sample Data Set]. Both from the official GeoPackage site. The same behavior occurs with GeoPackage v1.2 files. == Overview My aim is to automagically copy certain GeoPackage layers into a Spatialite database, as complete as possible. During testing I encountered inconsistent behaviour of ogr2ogr while copying the Index-attributes. == Detailed attribute behaviour Copy behaviour of ""GDAL Technology Test Data Set"" Layer **""linestring2d""** attributes: ||= original (GeoPackage) =||= created target (Spatialite) =|| || - || OGC_FID ''[only index attribute]'' || || fid ''[only index attribute]'' || - || || geom ''[Geometry]'' || the_geom ''[Geometry]'' || Copy behaviour of ""Esri Sample Data Set"" Layer **""counties""** attributes: ||= original (GeoPackage) =||= created target (Spatialite) =|| || - || OGC_FID ''[only index attribute]'' || || OBJECTID ''[only index attribute]'' || OBJECTID ''[no index]'' || || NAME || NAME || || STATE_NAME || STATE_NAME || || STATE_FIPS || STATE_FIPS || || ... || ... || || Shape ''[Geometry]'' || the_geom ''[Geometry]'' || == Detailed description When I set the ""-unsetFid"" command line option I understood that the if a ""fid""-Index attribute exists in the original layer it will not be used as a index attribute in the target layer. So ogr2ogr will create a new Index attribute in the target layer. In the case of the SQLite/Spatialite driver I can conveniently name the new index with the -lco ""FID=XXX"" command line option.[[BR]][[BR]] But for the sake of completeness the original Index attributes (e.g. ""fid"" or, ""OBJECTID"") should still be preserved as ""normal"" attributes. In the case of the ""Esri Sample Data"" it keeps the ""OBJECTID""-Index as a ""normal"" (non-index) attribute just as expected. But in the ""GDAL Technology Test Data Set"" the ""fid""-Index attribute is just not copied. As consistent behaviour I expected the original ""fid""-Index attribute to be copied as non-Index attribute. **In my situation this can lead to data loss as indices can be important.** == Used command line arguments For the ""GDAL Technology Test Data Set"": {{{ ogr2ogr.exe -f ""SQLite"" ""C:\Temp\gdal_sample_v1.0.sqlite"" ""C:\Temp\gdal_sample.gpkg"" -nln ""import1"" -lco ""SPATIAL_INDEX=YES"" -lco ""FORMAT=SPATIALITE"" -lco ""LAUNDER=NO"" -sql ""SELECT * FROM \""linestring2d\"""" -lco ""GEOMETRY_NAME=the_geom"" -dsco ""SPATIALITE=YES"" -unsetFid }}} For the ""Esri Sample Data"": {{{ ogr2ogr.exe -f ""SQLite"" ""C:\Temp\esri_sample_v1.0.sqlite"" ""C:\Temp\sample1_0.gpkg"" -nln ""import1"" -lco ""SPATIAL_INDEX=YES"" -lco ""FORMAT=SPATIALITE"" -lco ""LAUNDER=NO"" -sql ""SELECT * FROM \""counties\"""" -lco ""GEOMETRY_NAME=the_geom"" -dsco ""SPATIALITE=YES"" -unsetFid }}} " defect closed normal default svn-trunk normal fixed ogr2ogr GeoPackage Spatialite Index tamas