README.md 5.58 KB
Newer Older
Jesse Rosenstock's avatar
Jesse Rosenstock committed
1
# S2 Geometry Library
Jesse Rosenstock's avatar
Jesse Rosenstock committed
2

3
4
[![Build Status](https://travis-ci.org/google/s2geometry.svg?branch=master)](https://travis-ci.org/google/s2geometry)

Jesse Rosenstock's avatar
Jesse Rosenstock committed
5
## Overview
Jesse Rosenstock's avatar
Jesse Rosenstock committed
6

Jesse Rosenstock's avatar
Jesse Rosenstock committed
7
8
9
10
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.
Jesse Rosenstock's avatar
Jesse Rosenstock committed
11

Jesse Rosenstock's avatar
Jesse Rosenstock committed
12
If you want to learn more about the library, start by reading the
Jesse Rosenstock's avatar
Jesse Rosenstock committed
13
14
15
16
17
[overview](http://s2geometry.io/about/overview) and [quick start
document](http://s2geometry.io/devguide/cpp/quickstart), then read the
introduction to the [basic types](http://s2geometry.io/devguide/basic_types).

S2 documentation can be found on [s2geometry.io](http://s2geometry.io).
Jesse Rosenstock's avatar
Jesse Rosenstock committed
18

Jesse Rosenstock's avatar
Jesse Rosenstock committed
19
## Requirements for End Users
Jesse Rosenstock's avatar
Jesse Rosenstock committed
20
21

* [CMake](http://www.cmake.org/)
Jesse Rosenstock's avatar
Jesse Rosenstock committed
22
* A C++ compiler with C++11 support, such as [g++ >= 4.7](https://gcc.gnu.org/)
23
* [Abseil](https://github.com/abseil/abseil-cpp) (standard library extensions)
Jesse Rosenstock's avatar
Jesse Rosenstock committed
24
* [OpenSSL](https://github.com/openssl/openssl) (for its bignum library)
25
26
* [gflags command line flags](https://github.com/gflags/gflags), optional
* [glog logging module](https://github.com/google/glog), optional
Jesse Rosenstock's avatar
Jesse Rosenstock committed
27
* [googletest testing framework](https://github.com/google/googletest)
Jesse Rosenstock's avatar
Jesse Rosenstock committed
28
  (to build tests and example programs, optional)
Jesse Rosenstock's avatar
Jesse Rosenstock committed
29

30
On Ubuntu, all of these other than abseil can be installed via apt-get:
Jesse Rosenstock's avatar
Jesse Rosenstock committed
31

Jesse Rosenstock's avatar
Jesse Rosenstock committed
32
```
33
sudo apt-get install cmake libgflags-dev libgoogle-glog-dev libgtest-dev libssl-dev
Jesse Rosenstock's avatar
Jesse Rosenstock committed
34
```
Jesse Rosenstock's avatar
Jesse Rosenstock committed
35

Jesse Rosenstock's avatar
Jesse Rosenstock committed
36
Otherwise, you may need to install some from source.
Jesse Rosenstock's avatar
Jesse Rosenstock committed
37

38
39
40
41
Currently, Abseil must always be installed from source.  See the use of
`-DCMAKE_PREFIX_PATH` in the [build instructions below](#building).
This is likely to change.

Jesse Rosenstock's avatar
Jesse Rosenstock committed
42
43
On macOS, use [MacPorts](http://www.macports.org/) or
[Homebrew](http://brew.sh/).  For MacPorts:
Jesse Rosenstock's avatar
Jesse Rosenstock committed
44
45
46
47
48
49

```
sudo port install cmake gflags google-glog openssl
```

Do not install `gtest` from MacPorts; instead download [release
Jesse Rosenstock's avatar
Jesse Rosenstock committed
50
1.8.0](https://github.com/google/googletest/releases/tag/release-1.8.0), unpack,
Jesse Rosenstock's avatar
Jesse Rosenstock committed
51
52
53
54
55
56
57
and substitute

```
cmake -DGTEST_ROOT=/...absolute path to.../googletest-release-1.8.0/googletest ..
```

in the build instructions below.
Jesse Rosenstock's avatar
Jesse Rosenstock committed
58
59

Thorough testing has only been done on Ubuntu 14.04.3 and macOS 10.12.
Jesse Rosenstock's avatar
Jesse Rosenstock committed
60

Jesse Rosenstock's avatar
Jesse Rosenstock committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
## Build and Install

You may either download the source as a ZIP archive, or [clone the git
repository](https://help.github.com/articles/cloning-a-repository/).

### Via ZIP archive

Download [ZIP file](https://github.com/google/s2geometry/archive/master.zip)

```
cd [parent of directory where you want to put S2]
unzip [path to ZIP file]/s2geometry-master.zip
cd s2geometry-master
```

### Via `git clone`

```
cd [parent of directory where you want to put S2]
git clone https://github.com/google/s2geometry.git
cd s2geometry
```

### Building

86
First, [install Abseil](https://github.com/abseil/abseil-cpp/blob/master/CMake/README.md#traditional-cmake-set-up).
87
It must be configured with `-DCMAKE_POSITION_INDEPENDENT_CODE=ON`.
Jesse Rosenstock's avatar
Jesse Rosenstock committed
88
89
90
91
s2geometry must be configured to use the came C++ version that
abseil uses.  The easiest way to achieve this is to pass
`-DCMAKE_CXX_STANDARD=11` (or `-DCMAKE_CXX_STANDARD=17`) to `cmake`
when compiling both abseil and s2geometry.
92

Jesse Rosenstock's avatar
Jesse Rosenstock committed
93
From the appropriate directory depending on how you got the source:
Jesse Rosenstock's avatar
Jesse Rosenstock committed
94
95
96
97

```
mkdir build
cd build
Jesse Rosenstock's avatar
Jesse Rosenstock committed
98
# You can omit -DGTEST_ROOT to skip tests; see above for macOS.
Jesse Rosenstock's avatar
Jesse Rosenstock committed
99
100
# Use the same CMAKE_CXX_STANDARD value that was used with absl.
cmake -DGTEST_ROOT=/usr/src/gtest -DCMAKE_PREFIX_PATH=/path/to/absl/install -DCMAKE_CXX_STANDARD=11 ..
101
102
make -j $(nproc)
make test ARGS="-j$(nproc)"  # If GTEST_ROOT specified above.
Jesse Rosenstock's avatar
Jesse Rosenstock committed
103
104
105
sudo make install
```

106
107
On macOS, `sysctl -n hw.logicalcpu` is the equivalent of `nproc`.

108
109
Enable gflags and glog with `cmake -DWITH_GFLAGS=ON -DWITH_GLOG=ON ...`.

110
111
Disable building of shared libraries with `-DBUILD_SHARED_LIBS=OFF`.

112
113
Enable the python interface with `-DWITH_PYTHON=ON`.

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
## Installing

From `build` subdirectory:

```
make install
```

Prefix it with `sudo` if needed:

```
sudo make install
```

_NOTE_: There is not `uninstall` target but `install_manifest.txt` may be helpfull.

All files will be installed at location specified in `CMAKE_INSTALL_PREFIX` variable.

Several suffix variables used for some file groups:

Variable | Default | Description
-------- | ------- | -----------
`CMAKE_INSTALL_INCLUDEDIR` | `include` | For header files
`CMAKE_INSTALL_BINDIR`     | `bin`     | For executables and `*.dll` files on `DLL`-based platforms
`CMAKE_INSTALL_LIBDIR`     | `lib`     | For library files (`*.so`, `*.a`, `*.lib` etc)

If needed set this variables on command line as `cmake` arguments with `-D` prefix or edit from `build` subdirectory:

```
make edit_cache
```

For more info read: [The CMake Cache](https://cmake.org/cmake/help/latest/guide/user-interaction/index.html#the-cmake-cache).

Jesse Rosenstock's avatar
Jesse Rosenstock committed
148
149
## Python

150
151
If you want the Python interface, you need to run cmake using
`-DWITH_PYTHON=ON`. You will also need to install the following dependencies:
Jesse Rosenstock's avatar
Jesse Rosenstock committed
152

Jesse Rosenstock's avatar
Jesse Rosenstock committed
153
* [SWIG 4](https://github.com/swig/swig) (for Python support, optional)
154
* python3-dev (for Python support, optional)
Jesse Rosenstock's avatar
Jesse Rosenstock committed
155
156
157
158

which can be installed via

```
159
sudo apt-get install swig python3-dev
Jesse Rosenstock's avatar
Jesse Rosenstock committed
160
161
162
163
164
165
166
```

or on macOS:

```
sudo port install swig
```
Jesse Rosenstock's avatar
Jesse Rosenstock committed
167
168
Version 4.0 is required, but it should be easy to make it work 3.0 or probably
even 2.0.
Jesse Rosenstock's avatar
Jesse Rosenstock committed
169

Jesse Rosenstock's avatar
Jesse Rosenstock committed
170
171
Python 3 is required.

172
173
174
## Other S2 implementations

* [Go](https://github.com/golang/geo) (Approximately 40% complete.)
eengle's avatar
eengle committed
175
176
* [Java](https://github.com/google/s2-geometry-library-java) (Some newer C++ features are missing;
  last updated in 2021.)
177
* [Kotlin](https://github.com/Enovea/s2-geometry-kotlin) (Complete except binary serialization)
178

Jesse Rosenstock's avatar
Jesse Rosenstock committed
179
180
## Disclaimer

Jesse Rosenstock's avatar
Jesse Rosenstock committed
181
This is not an official Google product.