Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting a GeoPackage to Shapefile wrongly changes the field types #27534

Closed
qgib opened this issue Aug 27, 2018 · 4 comments
Closed

Exporting a GeoPackage to Shapefile wrongly changes the field types #27534

qgib opened this issue Aug 27, 2018 · 4 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers

Comments

@qgib
Copy link
Contributor

qgib commented Aug 27, 2018

Author Name: Jérôme Guélat (Jérôme Guélat)
Original Redmine Issue: 19709
Affected QGIS version: 3.2.2
Redmine category:data_provider/ogr


Some steps to reproduce the bug:

  1. Add the layer contained in the attached GeoPackage. It has 2 fields: the fid (type qlonglong) and another one (type: int)
  2. Export the layer as a Shapefile (right-click on the layer -> Export -> Save Features As...)
  3. The field types were changed: the fid is now a real (instead of qlonglong), and the other field is now a qlonglong (instead of int)

@qgib
Copy link
Contributor Author

qgib commented Aug 29, 2018

Author Name: Giovanni Manghi (@gioman)


In straight conversion with ogr2ogr the "att" field of your attachment results in an "int" field as expected.

What about 2.18, worked as expected?


  • crashes_corrupts_data was changed from 1 to 0
  • operating_system was changed from Windows 7 to
  • status_id was changed from Open to Feedback

@qgib
Copy link
Contributor Author

qgib commented Aug 30, 2018

Author Name: Jérôme Guélat (Jérôme Guélat)


Indeed, a conversion with ogr2ogr works as expected... This is a QGIS problem.

The bug also occurs with QGIS 2.18.


  • status_id was changed from Feedback to Open

@qgib
Copy link
Contributor Author

qgib commented Sep 21, 2018

Author Name: Even Rouault (@rouault)


Closing as wontfix.
The fundamental problem is that GeoPackage uses binary encoding (int32, int64, float64) whereas Shapefile/DBF uses text encoding. OGR and QGIS have slightly different ways of mapping to DBF field types. For example OGR will map a Int as a Decimal(9) and QGIS as a Decimal(10), and OGR will map a Int64 as a Decimal(18) and QGIS as a Decimal(20).
On reading if a Decimal field has:
<=9 characters, OGR will interpret it as a Int

=10 and <=18 characters, OGR will interpret it as a Int64
=19 characters, OGR will interpret it as a Double

QGIS choice of using Decimal(10) for Int and Decimal(20) for Int64 is actually more correct than ogr/ogr2ogr choice since number likes -1234567890 fit on a Int32 but requires 10 characters.
Perfect round-tripping is impossible given the mismatching between formats


  • resolution was changed from to wontfix

@qgib
Copy link
Contributor Author

qgib commented Oct 5, 2018

Author Name: Even Rouault (@rouault)


  • status_id was changed from Open to Closed

@qgib qgib closed this as completed Oct 5, 2018
@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers
Projects
None yet
Development

No branches or pull requests

1 participant