Friday, 9 September 2016

How is attribute data in DBF file tied to shapefile location data in SHP file?


I opened a DBF file in Excel and I'm looking at attribute data from a shapefile export.


How is the row of attribute data in the DBF file connected to it's corresponding locational data in the SHP file?


I don't see anything that looks like a key.



Answer



As documented in the shapefile specification (p. 25), only record number links the SHP/SHX pair to the DBF :



The record order must be the same as the order of shape features in the main (*.shp) file.




There is a popular myth that the SHX file serves as a lookup to the dBase file, but this is not true. The SHX is only a fixed width complement to the SHP file, allowing direct access by record number into the variable record width SHP file.


Both the SHP and SHX have 100 byte fixed headers, and the DBF has a 32-byte fixed header and one additional 32-byte header per field. Once you know the byte position for the first record, both the SHX and DBF are fixed width, while the SHP is variable width by vertex count (point SHP files are also fixed width, so the illustration below would be for multipoint, polyline, polygon, or multipatch).


shapefile layout


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...