[gdal-dev] ogr2ogr changes field length

Rahkonen Jukka (MML) jukka.rahkonen at maanmittauslaitos.fi
Fri Oct 8 01:45:04 PDT 2021


Hi,

The best I can suggest to do by using just GDAL utilities is to run this kind of ogrinfo command for each text field that you have in the shapefile schema:

ogrinfo my_shape.shp -sql "alter table my_shape alter column STRING_1 TYPE character(254)"

(right, the max length is 254).

-Jukka Rahkonen-
 
-----Alkuperäinen viesti-----
Lähettäjä: matteo <matteo.ghetta at gmail.com> 
Lähetetty: perjantai 8. lokakuuta 2021 11.20
Vastaanottaja: Rahkonen Jukka (MML) <jukka.rahkonen at maanmittauslaitos.fi>; Even Rouault <even.rouault at spatialys.com>; gdal-dev at lists.osgeo.org
Aihe: Re: [gdal-dev] ogr2ogr changes field length

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