I have a PostGIS database created from an old AutoCAD system. Because of this, every column is type varchar(254), even though actual data lengths are small. I need to export tables as shapefiles, and would like to minimize the extra space created in the shapefile due to the large column fields, in order to reduce the overall size of the .dbf file. Is there any way to reduce the size of fields when utilizing ogr2ogr to convert PostgreSQL data to Esri shapefiles?
1 Answer
You can shrink the shapefile that ogr2ogr has created. Read https://gdal.org/drivers/vector/shapefile.html#field-sizes
It is also possible to force a resize of the fields to the optimal width by issuing a SQL ‘RESIZE ’ via the datasource ExecuteSQL() method. This is convenient in situations where the default column width (80 characters for a string field) is bigger than necessary.
Usage example with ogrinfo
ogrinfo -sql "RESIZE test" test.shp
select max(LENGTH(my_column)) from my_table ;