[gdal-dev] ogr2ogr changes field length

matteo matteo.ghetta at gmail.com
Fri Oct 8 01:20:18 PDT 2021


Hi Jukka,

> The strings fields are created by default with width 80. If there are longer strings in the data the width is automatically extended up till 255 characters that is the maximum that dBase format supports. If strings are shorter than 80 charaters it is possible to use RESIZE and shrink the width to match the longest string used in that field.
> 
> If you need better control on field widths I suppose you must create an empty shapefile for ogr2ogr to append by your own code.
> 
> # Add a new field.
>      field_defn = ogr.FieldDefn('NEWFLD', ogr.OFTString)
>      field_defn.SetWidth(12)
> 
> Do you have some concrete problem with field widths that you want to resolve?

I'm "dumping" empty tables of a schema to shapefile and actually yes, I 
need that the fields with unlimited text set up in PG should be the 
maximum (so 254) in the final shapefiles.

All the tables are empty so I guess this is the "problem" I have

Cheers and thanks

Matteo


More information about the gdal-dev mailing list