The S2 Geometry Library is a spherical geometry library originally made by Google, released under the Apache License (Version 2.0), which is very useful for manipulating regions on the sphere (commonly on Earth) and indexing geographic data. I use it in several of my personal toy projects, both on desktop and on Android.

Use the Fork, Luke

Sadly, it is/was hosted on Google Code, but Google Code is closing. The project has had no activity since 2011 and looks abandoned, so I had little hope to see it migrate somewhere else. Too bad for such a useful project!

But the beauty of Free and Open Source Software is that anyone is free to fork the code to fit his needs. And that’s what I did.

I’ve put the sources on Github, who hopefully won’t close in the near future. I have changed the build system to use Gradle instead of Ant, but the core of the library hasn’t changed.

The continuous integration is provided by Travis CI.

The binaries are published on Bintray, so using them in your Gradle or Maven build is dead easy.

For Gradle, add the following repository in your build.gradle:

repositories {
  maven {
    url "http://dl.bintray.com/jnegre/maven"
  }
}

Then reference the artifact you need:

dependencies {
  compile 'org.jnegre.google:s2-geometry:1.2'
}

If you’re using Maven, add the repository in your settings.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>bintray-jnegre-maven</id>
          <name>bintray</name>
          <url>http://dl.bintray.com/jnegre/maven</url>
        </repository>
      </repositories>
      <id>bintray</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>bintray</activeProfile>
  </activeProfiles>
</settings>

Then add the dependency in your pom.xml:

<dependency>
  <groupId>org.jnegre.google</groupId>
  <artifactId>s2-geometry</artifactId>
  <version>1.2</version>
  <type>jar</type>
</dependency>

(I suspect the Maven developers are paid by the hard disk manufacturers to have such verbose file formats.)

Did I mention the fact that this library works perfectly well on Android? Because it does.

Gosh, I love Open Source!