A5 v1.0
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
A5 v1.0
It has been 18 months since the first announcement of A5. What started off as an experiment in visualization (and an obsession with pentagons) has grown into a useful tool, with a wealth of libraries, tools and software building on top. Today I’m excited to announce that the v1.0 version of A5 is out, bringing a powerful set of features and performance improvements as well as crystallizing the grid and index definition for the future.
自 A5 首次发布以来已经过去了 18 个月。最初它只是一个可视化实验(以及对五边形的痴迷),如今已成长为一个实用的工具,并拥有大量基于其构建的库、工具和软件。今天,我很高兴地宣布 A5 v1.0 版本正式发布,它带来了一系列强大的功能和性能改进,并为未来的网格和索引定义奠定了基础。
If you’re new to A5, in a nutshell it is a grid system that allows the representation of any position, line or polygon region on the globe as a pentagonal cell (or collection of cells), each represented as a compact 64-bit integer. The industry term for this is a Discrete Global Grid System (DGGS), and there are already a number of other systems out there which are powering some of the world’s largest companies and data analytics pipelines. For a concrete example of an application leveraging A5, take a look at the FIRMS Explorer which uses A5 to aggregate 631 million fire detections worldwide since 2000.
如果您是 A5 的新用户,简而言之,它是一个网格系统,允许将地球上的任何位置、线条或多边形区域表示为五边形单元(或单元集合),每个单元都表示为一个紧凑的 64 位整数。该领域的专业术语是离散全球网格系统(DGGS),目前已经有许多其他系统正在为全球一些最大的公司和数据分析管道提供支持。关于利用 A5 的应用程序的具体示例,您可以查看 FIRMS Explorer,它使用 A5 汇总了自 2000 年以来全球 6.31 亿次火灾探测数据。
Stable platform for the future With v1.0 we are committing to keeping the grid layout and the cell IDs frozen going forward. While the system will evolve and grow, for example by adding more utility functions, the fundamentals will stay fixed so applications, databases and workflows will be able to rely on an A5 cell representing a specific geographic location into the future.
面向未来的稳定平台:随着 v1.0 的发布,我们承诺在未来保持网格布局和单元 ID 不变。虽然系统会不断演进和发展(例如增加更多的实用功能),但基础部分将保持固定,以便应用程序、数据库和工作流在未来能够依赖 A5 单元来表示特定的地理位置。
The community around the project has grown, in particular with the DuckDB and R implementations, whose beautiful sites arguably even put the official A5 site to shame! As such, going forward, the documentation on the A5 website will present code snippets and API documentation in these languages, as well as the officially supported TypeScript, Rust and Python libraries.
围绕该项目的社区已经壮大,特别是 DuckDB 和 R 的实现,它们精美的网站甚至让官方 A5 网站都相形见绌!因此,未来 A5 网站上的文档将提供这些语言的代码片段和 API 文档,以及官方支持的 TypeScript、Rust 和 Python 库。
What’s new Compacted data processing New in v1.0 is a whole new set of functions for working with collections of cells, known as coverings. When working with coverings, you can now use set operations: union, intersect and difference, predicates: contains and overlaps and measuring functions: count and area. By using compacted data and these operations, it is possible to process billions of cells efficiently without having to uncompact the data, as was necessary before.
新功能:压缩数据处理。v1.0 的新功能是一套全新的用于处理单元集合的函数,称为“覆盖”(coverings)。在处理覆盖时,您现在可以使用集合运算:并集、交集和差集;谓词:包含和重叠;以及测量函数:计数和面积。通过使用压缩数据和这些操作,可以高效地处理数十亿个单元,而无需像以前那样必须先解压数据。
An example workflow might be to union several coverings from database queries, intersect with a polygon or spherical cap and then filter a collection of points against the resulting covering. See the example workflow.
一个工作流示例可能是:合并来自数据库查询的多个覆盖,与多边形或球冠求交,然后根据生成的覆盖过滤点集合。请参阅示例工作流。
Spatial hierarchy functions Geometrically, it is impossible to split an A5 pentagon into more pentagons in such a manner that the result exactly overlaps; the same is true of hexagons - unlike quadrilaterals and triangles, which can be split exactly. The A5 hierarchy is thus logical, and only approximately spatial. In order to support resampling and other operations, a new function cellToSubcells has been added. While this is slower than the cellToChildren API, it produces a correct covering (by centroid) of the cell. The inverse, cellToSupercell, is also available.
空间层级函数:从几何学上讲,不可能将一个 A5 五边形分割成更多的五边形并使结果完全重叠;六边形也是如此——这与可以精确分割的四边形和三角形不同。因此,A5 的层级是逻辑上的,仅近似于空间上的。为了支持重采样和其他操作,新增了一个函数 cellToSubcells。虽然它比 cellToChildren API 慢,但它能产生单元的正确覆盖(按质心)。其逆运算 cellToSupercell 也已提供。
Equal area One of the key strengths of A5 has always been the guarantee that every cell is exactly the same area at a given resolution, which means that any analysis run using the system is free of bias due to unequal cell sizes. New in v1.0, all the cells at all resolutions have the same pentagonal topology. This is in contrast to hexagonal DGGSs, which must include 12 pentagonal cells that complicate the topology and break the pure equal-area guarantee.
等面积:A5 的主要优势之一始终是保证在给定分辨率下每个单元的面积完全相同,这意味着使用该系统进行的任何分析都不会因单元大小不均而产生偏差。v1.0 的新特性是,所有分辨率下的所有单元都具有相同的五边形拓扑结构。这与六边形 DGGS 形成了对比,后者必须包含 12 个五边形单元,这会使拓扑结构复杂化并破坏纯粹的等面积保证。
Vibrant ecosystem One of the important characteristics of a grid system is its support across a range of tools and software, both in industry and academia. By standardizing on a definition of the grid and cell identifiers, it is easy to move data between systems and applications. For example, the FIRMS Explorer above was built using: Geoparquet.io to aggregate the data: gpio add a5 input.parquet output.parquet —resolution 5 Portolan to host a5-js and the A5Layer in deck.gl to visualize. Along with a raft of implementations in popular systems, such as DuckDB, R, QGIS and more, it is easier to build and experiment with A5 than ever. If you would like to get involved, or just have a question - feel free to join the Slack channel!
充满活力的生态系统:网格系统的一个重要特征是它在工业界和学术界的各种工具和软件中得到支持。通过标准化网格和单元标识符的定义,可以轻松地在系统和应用程序之间移动数据。例如,上述 FIRMS Explorer 是使用以下工具构建的:Geoparquet.io 用于汇总数据:gpio add a5 input.parquet output.parquet —resolution 5;Portolan 用于托管 a5-js;以及 deck.gl 中的 A5Layer 用于可视化。随着 DuckDB、R、QGIS 等流行系统中大量实现的出现,构建和试验 A5 比以往任何时候都更容易。如果您想参与其中,或者有任何疑问,请随时加入 Slack 频道!
Under the hood Over the past 18 months, both A5’s internals and its APIs have been refined. Teohedral space-filling curve The key change that the majority of the other improvements flow from is the implementation (and, well, discovery!) of a new teohedral space-filling curve, which defines the order in which the cells are indexed. The new curve passes around the whole world, without ever intersecting itself, while also grouping cells such that they form an (approximate) spatial hierarchy.
底层机制:在过去的 18 个月中,A5 的内部结构和 API 都得到了改进。Teohedral 空间填充曲线:大多数其他改进所源于的关键变化是实现(以及发现!)了一种新的 Teohedral 空间填充曲线,它定义了单元的索引顺序。这条新曲线环绕全球,且从不自交,同时将单元分组,使它们形成(近似的)空间层级。
The fact that it doesn’t self-intersect is crucial to some of the algorithms that can be built on top. For example, when filling a polygon with cells we can immediately deduce which cells are on the interior of the region without having to perform a costly flood fill. This works due to the boundary acting as a set of cutting points along the global space-filling curve - if we know these, then we can trivially fill in the cells in between.
它不自交的事实对于构建在其之上的某些算法至关重要。例如,当用单元填充多边形时,我们可以立即推断出哪些单元位于区域内部,而无需执行昂贵的泛洪填充。这是因为边界充当了沿全局空间填充曲线的一组切割点——如果我们知道这些点,就可以轻松填充中间的单元。
The benchmarks below are instructive: How these were measured: each point is one call filling a country outline (UK, France, Brazil, USA and Australia, from the A5 test fixtures) at one resolution, timed with the native libraries: A5 1.0.0 and 0.10.1 (Rust crates, rustc 1.87), H3 4.5.0 (the C library, via h3-py’s NumPy API) and S2 (the C++ library, via the s2geometry 0.14.0 Python bindings; S2RegionCoverer with no cell limit, so it returns a compacted covering at the target level). Times are the fastest of repeated runs, or a single run for calls over 2 seconds, on an Apple M1 Pro. Each library was stopped once a call took longer than a minute (6 seconds for A5), or past a billion cells. Prior to v1, A5 polygon fills became impractically slow beyond a million cells.
以下基准测试具有指导意义:测量方法如下:每个点都是一次调用,以一种分辨率填充国家轮廓(来自 A5 测试装置的英国、法国、巴西、美国和澳大利亚),并使用原生库进行计时:A5 1.0.0 和 0.10.1(Rust crates, rustc 1.87)、H3 4.5.0(C 库,通过 h3-py 的 NumPy API)和 S2(C++ 库,通过 s2geometry 0.14.0 Python 绑定;S2RegionCoverer 无单元限制,因此它返回目标级别的压缩覆盖)。时间是重复运行中最快的结果,或者对于超过 2 秒的调用是单次运行的结果,测试环境为 Apple M1 Pro。一旦调用时间超过一分钟(A5 为 6 秒)或超过十亿个单元,每个库的测试就会停止。在 v1 之前,A5 多边形填充在超过一百万个单元后变得慢得不切实际。