SHX 文件如何工作?

发布于 2024-07-12 05:59:41 字数 205 浏览 4 评论 0原文

如果您有以 ESRI 形状存储的地理数据,则至少有三个文件:一个以 .shp 结尾的文件包含矢量数据,一个以 .dbf 结尾的文件包含属性,以及一个以 .shx 结尾的文件包含索引。

我对 shx 文件感兴趣。 它是如何工作的? 它是否包含完整的映射,例如每个几何图形的“第一个几何图形映射到 dbf 中的第三行,第二个几何图形映射到第一行”? 还是工作原理不同?

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

I'm interested in the shx-file. How does it work? Does it contain a complete mapping, like 'first geometry maps to third row in the dbf and second geometry maps to the first row' for every geometry? Or does it work different?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尐偏执 2024-07-19 05:59:41

根据 spec shx 包含一个 100 字节的标头,后跟一个序列8 字节记录。 每个记录存储主 .shp 数据文件中记录的 4 字节偏移量和 4 字节内容长度。

+-----------------------------------------------+
| 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) | 
+-----------------+------------------+
| ....                               | 
+-----------------+------------------+

请注意,偏移量以 16 位字指定,因此第一个记录的偏移量为 50(因为 .shp 标头为 100 字节或 50 个字长)。 内容长度也以 16 位字指定。

因此,您可以从 (index_file_length-100)/8 中计算出记录数,并使用索引随机或按顺序访问 .shp 文件中的特定形状记录。

According to the spec the shx contains a 100 byte header followed by a sequence of 8 byte records. Each record stores a 4 byte offset and a 4 byte content length for a record 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) | 
+-----------------+------------------+
| ....                               | 
+-----------------+------------------+

Note that the offset is specified in 16 bit words, so the offset for the first record is 50 (as the .shp header is 100 bytes, or 50 words, long). The content length is also specified in 16 bit words.

So, you can figure out the number of records from (index_file_length-100)/8, and use the index to access a particular shape record in the .shp file at random or in sequence.

旧话新听 2024-07-19 05:59:41

保罗·迪克森的回答很好。

虽然我想知道你打算用它做什么! 如果您要编写代码来读取或写入 SHP 文件,我强烈建议您使用库 - 有一些很好的免费开源库,例如 GDAL,还有一些不错的商业广告。

Fine answer by Paul Dixon.

Though I was wondering what you are going to do with it! If you're going to write code to read or write SHP files I would strongly suggest using a library instead - there are some good free open source ones like GDAL, also some good commercial ones.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文