[gdal-dev] Primary keys are ignored in ogr2ogr when converting from Sqlite databases
César Martínez
cmartinez at scolab.es
Thu Dec 8 15:21:49 PST 2016
Hi, I am using ogr2ogr to export data from Spatialite to other formats
(such as PostGIS or a new Spatialite db).
The layers have an integer primary key, but this field is ignored in
the output table, as an OGC_FID field is created which uses
consecutive numbers, ignoring the real values of the primary key in
the original field.
This is quite inconvenient, as the layer is quite useless after loosing the PK.
I'll provide one example to make it clearer.
- Input data:
CREATE TABLE test
(id INTEGER NOT NULL PRIMARY KEY,
name TEXT NOT NULL);
SELECT AddGeometryColumn('test', 'the_geom', 4326, 'POINT', 'XY');
INSERT INTO 'test' (id, name, the_geom) VALUES (1, "row1",
GeomFromText('POINT(1.01 2.02)', 4326));
INSERT INTO 'test' (id, name, the_geom) VALUES (3, "row3",
GeomFromText('POINT(3.03 4.04)', 4326));
Now we export the table using ogr2ogr:
ogr2ogr -f "SQLite" db2.sqlite db.sqlite test -dsco SPATIALITE=YES
Now compare both layers:
$ ogrinfo -q db.sqlite test
Layer name: test
OGRFeature(test):1
name (String) = row1
POINT (1.01 2.02)
OGRFeature(test):3
name (String) = row3
POINT (3.03 4.04)
$ ogrinfo -q db2.sqlite test
Layer name: test
OGRFeature(test):1
name (String) = row1
POINT (1.01 2.02)
OGRFeature(test):2
name (String) = row3
POINT (3.03 4.04)
Is this a bug or is an intended behaviour? Is there any way to workaround it?
I am using GDAL version 1.11.3. It also happens when exporting to a
different format such as PostGIS.
Greetings,
César Martinez
--
SCOLAB
http://scolab.es
More information about the gdal-dev
mailing list