Home

Awesome

S2 Geometry Library

Overview

This is a package for manipulating geometric shapes. Unlike many geometry libraries, S2 is primarily designed to work with spherical geometry, i.e., shapes drawn on a sphere rather than on a planar 2D map. This makes it especially suitable for working with geographic data.

If you want to learn more about the library, start by reading the overview and quick start document, then read the introduction to the basic types.

S2 documentation can be found on s2geometry.io.

Build and Install

You may either download the source as a ZIP archive, or clone the git repository. The Java packages are built and tested using Maven.

In the directory containing the pom.xml file, use Maven to compile the package, run tests, and install the package. For example:

mvn clean
mvn compile
mvn test
mvn package
mvn install

Benchmarks

After building packages, a "benchmarks.jar" file may be found in benchmarks/target/. Benchmarks can then be run with the command java -jar benchmarks/target/benchmarks.jar Parameters for the benchmarks can be passed on the command line. For example, to run just the S2Loop benchmarks, java -jar benchmarks/target/benchmarks.jar S2Loop

S2 implementations

The S2 library has implementations in several languages. In addition to this Java implementation, Google provides:

We (the S2 developers) aim to provide similar classes and APIs across all implementations, while adapting to language idioms where that makes sense, and changing APIs where required for good performance. The implementations have varying degrees of completeness and maturity. This Java implementation is heavily used within Google and is generally mature, aside from the newest features, but is not as complete as C++.

2022 Q4 Release Highlights

Many improvements have been made to the Java implementation of S2 since the last release in September 2021. Some highlights:

Breaking API changes:

Disclaimer

This is not an official Google product.