[GIS] Opening .shx files

shapefileSpecification

I want to see the contents of an .shx file to see how the index information is stored in these files so that I can get some help in writing my own shapefiles.

How can I open and use the .shx files?

Best Answer

The .shx file is binary, so you need a hex editor to look inside.

The format is described in http://en.wikipedia.org/wiki/Shapefile:

The shapefile index contains the same 100-byte header as the .shp file, followed by any number of 8-byte fixed-length records which consist of the following two fields:
Bytes   Type    Endianness  Usage
0–3     int32   big     Record offset (in 16-bit words)
4–7     int32   big     Record length (in 16-bit words)

Using this index, it is possible to seek backwards in the shapefile by, first, seeking backwards in the shape index (which is possible because it uses fixed-length records), then reading the record offset, and using that offset to seek to the correct position in the .shp file. It is also possible to seek forwards an arbitrary number of records using the same method.

You will find further links at the bottom of the wiki page.