How does the SHX file work?

If you have geographic data stored in ESRI forms, you have at least three files: one ends with .shp containing vector data, one ends with .dbf containing attributes, and a file ending with .shx containing the index.

I'm interested in shx file. How it works? Does it contain a full comparison, for example, "the first geometry map in the third row in dbf and the second geometry map in the first row" for each geometry? Or does it work differently?

+3
source share
2 answers

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)/8and use the index to access a specific form record in the .shp file randomly or sequentially.

+6
source

Good answer is Paul Dixon.

, ! SHP , - , GDAL, .

+2

Source: https://habr.com/ru/post/1702296/


All Articles