2

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?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Jun 21, 2022 at 17:26
2
  • dBase has a 4000 byte record limit, which you'd overwhelm with 16 254-width string fields. Commented Jun 21, 2022 at 17:48
  • consider checking the length of the longest string in each column with a query like select max(LENGTH(my_column)) from my_table ; Commented Jun 21, 2022 at 18:27

1 Answer 1

2

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
answered Jun 21, 2022 at 19:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.