According to spec, shx contains a 100-byte header followed by a sequence of 8-byte entries. Each record stores an offset of 4 bytes and a content length of 4 bytes for recording in the main .shp data file.
+-----------------------------------------------+
| header (100 bytes) |
+-----------------+------------------+----------+
| offset(4 bytes) | length (4 bytes) |
+-----------------+------------------+
| offset(4 bytes) | length (4 bytes) |
+-----------------+------------------+
| offset(4 bytes) | length (4 bytes) |
+-----------------+------------------+
| offset(4 bytes) | length (4 bytes) |
+-----------------+------------------+
| .... |
+-----------------+------------------+
Please note that the offset is indicated in 16-bit words, so the offset for the first record is 50 (since the .shp header is 100 bytes or 50 words long). The length of the content is also indicated in 16-bit words.
So, you can determine the number of records from (index_file_length-100)/8
and use the index to access a specific form record in the .shp file randomly or sequentially.
source
share