[gdal-dev] Primary keys are ignored in ogr2ogr when converting from Sqlite databases
Bo Victor Thomsen
bo.victor.thomsen at gmail.com
Fri Dec 9 00:36:08 PST 2016
Have you tried to use the *-preserve_fid *qualifier*??
*
ex.
ogr2ogr -preserve_fid -f "SQLite" db2.sqlite db.sqlite test -dsco SPATIALITE=YES
Regards
Bo Victor Thomsen
AestasGIS
Den 09-12-2016 kl. 00:21 skrev César Martínez:
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20161209/0be8548f/attachment.html>
More information about the gdal-dev
mailing list