views:

656

answers:

3

Hi there,

I worked with ESRI shapefile format right now and i have some problem with changing/editing database field size. I created a field with 200 length/size and now i want it to only 80 length/size (space & other improvement).

However i can't edit field size anymore :( can somebody point out how to change the field size?

Btw i have tried utilities such as DBF Explorer which can edit field size, but when i change field size on char/text field, data on float/numeric field get deleted :(
DBF Explorer

PS: ESRI database use .dbf extension, which i think it was DBASE III plus or DBASE IV format

+1  A: 

Its DBASE III (sort of).

The dbf file both contain the meta data (like field size and type) and the data. They are all stored fixed size.

I can't remember if there are tools to change the fieldsize, but you can create a new table and copy the data. But the format is not that hard.

Gamecat
if i create a new table, how about Fid, Shapetype, etc information that hidden but linked to .shp file?
Dels
The order and other inoformation must be the same.
Gamecat
Just a minor correction. Shapefiles use DBASE4 not DBASE3 version for the .dbf files
dev
+1  A: 

You can edit the header of the file to change it with any hexadecimal editor.

byte 10-11: represents the lenth of a record (least significant byte first)

starting at byte 48 a repeated structure (48 bytes each) describing the field. The byte 33 of this structure represent the length.

Fabian Vilers
hex editor sounds nice, hope it will not ruin data that already inside, i'll try it, thanks :D
Dels
just curious, did it corrupt the table?
Avery Payne
+2  A: 

Do NOT edit the header, the data is aligned by fixed offset, and changing the size of the field to something that doesn't match the physical length of the record WILL corrupt your table.

You'll need something that can read/write DBFs to effectively do this. An old install of DBase will work, although you would be better off with Visual FoxPro (the FoxPro command would be MODI STRU which is short for "MODIFY STRUCTURE"). I would also look at other tools to push/pull the data into other formats. If you have access to Access (pardon the pun), you could always import the data in to Access as an Access table, restructure the table, then export it out, although starting with Access 2007, native DBF/FoxPro support has been more or less removed, requiring ODBC. Other (more time consuming) measures would be to:

  • look at using Excel (provided the data has very few rows, older versions can only handle 32k or 64k rows total)
  • use some Python to read/write data (do a search on SO for this info)
  • a variant of the above in Perl/Ruby/{insert favorite scripting language with a DBF library}
  • use ODBC + {insert cheapo database here} + {insert cheapo admin tool for cheapo database that can modify a table here} + export from {cheapo database}
Avery Payne