0

I am trying to convert gpkg to shapefile using ogr2ogr command with python. After running this line of code I got a message saying:

ogr2ogr.main(["", "-f", "ESRI Shapefile", "out6.shp", "kucni_broj.gpkg"])

Warning 1: Value '20А' of field out6.kucni_broj parsed incompletely to integer 20.

Then I added ENCODING parameter and converted it again using:

ogr2ogr.main(["", "-f", "ESRI Shapefile", "out6.shp", "kucni_broj.gpkg", "-lco", "ENCODING=UTF8"])

After that I got message:

ERROR 1: Failed to create field name 'kucni_broj_id': cannot convert to UTF8

Is there any way I can fix this issue?

2

The problem is not in encoding.

The problem is in the data because it seems that in some row of your table there is a value "20A" in a field that it defined to be of type integer. GDAL is telling that it can't save string '20A' as integer into shapefile so it saves just the number part "20".

GeoPackage is a SQLite database and for SQLite it is not a problem to store strings in a field that is created as integer.

You must fix your data. If the value 20A is right for the field out6.kucni_broj then you must either do some operations in the GeoPackage database for changing the SQL Create field in sqlite_master table to show that kucni_broj is a text field. An easier option may be to make a cast during the conversion. The command should look about like this

ogr2ogr -f "ESRI Shapefile" -sql "select geometry, CAST(kucni_broj AS TEXT) as kucni_broj from kucni_broj" kucni_broj.gpkg
|improve this answer|||||
  • Thanks, I should pay more attention to data model in the future. – DrJacoby Mar 2 at 17:53
0

Use UTF-8 instead of UTF8 :

ogr2ogr.main(["", "-f", "ESRI Shapefile", "out6.shp", "kucni_broj.gpkg", "-lco", "ENCODING=UTF-8"])

|improve this answer|||||
  • Then I get Warning 1: Value '20А' of field out6.kucni_broj parsed incompletely to integer 20. Just like in the first case. – DrJacoby Feb 21 at 14:07

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.