(click here to online demonstration for Desktop Firefox or Chrome)
Space-filling curves (SFCs) can be used to index discrete grids, including the Geospatial ones. Each cell in the grid is associated with an index, which can be produced by an SFC. In this project, we are particularly interested in hierarchical grids with a recurring partition of quadrilateral cells in 4 regions:
Therefore, we are interested in any SFC that is valid for indexing hierarchical grid of refinement-ratio-4 quadrilateral cells, abbreviated SFC-4q, or Sfc4q as adopted in the project's name and classes names.
In this project we are also interested in geocodes obtained by labeling the SFC indexes, expressing it in human-readable hierarchical codes. The hierarchy of the code is illustrated above as the commom prefix (e.g. 2
in 20
and 23
) that emerges in with the base4 representation.
The framework can be used as simple standard interface for a set of SFC algorithms, like Hilbert, Morton or other.
The algorithms themselves are "concrete classes". But the standardization of basic methods, such as endode() and decode(), is not the issue, there are a lot of generic and reusable methods, so the best way is to extend a generic class with these reusable methods, and implement the concrete algorithm as specialization. This project is a set of abstract and concrete classes.
Other important issue for SFC-4q is the generalization for "half levels" described in this PDF article. It is also independent of the concrete algorithms. The illustration bellou is hou these classes uas implemented:
-
GSfc4q: the "Generalized Sfc4q" class.
-
GSfc4qLbl: a generaliation of GSfc4q, to translate key, bkey and cell identifiers (cell IDs) into human-readable labels (lbl). To preserve hierarchy, this translation uses the concept of Natural Codes, implemented in Javascript by the class SizedBigInt (of the project osm-codes/NaturalCodes and old SizedBigInt).
-
GSfc4qLbl_Hilbert: the "concrete class" that implements the Hilbert curve.
-
GSfc4qLbl_Morton:the "concrete class" that implements the Morton curve (also Z-order curve).
-
SizedBigInt: it is a complementar tool for use BigInt (mainly 64 bits unsigned integers) as hierarchical indexes and obtain its string representations, and an implementation of the Natural Codes.
Content, data and algorithms: CC0 1.0, Public Domain Dedication.