[gdal-dev] ogr2ogr changes field length

Rahkonen Jukka (MML) jukka.rahkonen at maanmittauslaitos.fi
Thu Oct 7 23:51:20 PDT 2021


Hi,

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?

-Jukka Rahkonen-

-----Alkuperäinen viesti-----
Lähettäjä: gdal-dev <gdal-dev-bounces at lists.osgeo.org> Puolesta matteo
Lähetetty: perjantai 8. lokakuuta 2021 9.11
Vastaanottaja: Even Rouault <even.rouault at spatialys.com>; gdal-dev at lists.osgeo.org
Aihe: Re: [gdal-dev] ogr2ogr changes field length

Hi Even,

> If you add -lco RESIZE=YES fields will be resized to their minimum size. 
> See 
> https://gdal.org/drivers/vector/shapefile.html#layer-creation-options

yep I see. I also read

* String fields without an assigned width are treated as 80 characters

does it mean that if a field is set as TEXT in PG (without length
definition) the conversion to shapefile is automatically set to 80 and what we can do is to resize the field length only to have less characters?

Cheers!

Matteo
_______________________________________________
gdal-dev mailing list
gdal-dev at lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list