1# Overview
2
3S2 is a library for spherical geometry that aims to have the same robustness,
4flexibility, and performance as the best planar geometry libraries.
5
6This is a library for manipulating geometric shapes. Unlike many geometry
7libraries, S2 is primarily designed to work with *spherical geometry*, i.e.,
8shapes drawn on a sphere rather than on a planar 2D map. (In fact, the name S2
9is derived from the mathematical notation for the unit sphere *Sยฒ*.) This makes
10it especially suitable for working with geographic data.
11
12More details about S2 in general are available on the S2 Geometry Website
13[s2geometry.io](https://s2geometry.io/).
14
15## Scope
16
17The library provides the following:
18
19* Representations of angles, intervals, latitude-longitude points, unit
20 vectors, and so on, and various operations on these types.
21
22* Geometric shapes over the unit sphere, such as spherical caps ("discs"),
23 latitude-longitude rectangles, polylines, and polygons. These are
24 collectively known as "regions".
25
26* A hierarchical decomposition of the sphere into regions called "cells". The
27 hierarchy starts with the six faces of a projected cube and recursively
28 subdivides them in a quadtree-like fashion.
29
30* Robust constructive operations (e.g., union) and boolean predicates (e.g.,
31 containment) for arbitrary collections of points, polylines, and polygons.
32
33* Fast in-memory indexing of collections of points, polylines, and polygons.
34
35* Algorithms for measuring distances and finding nearby objects.
36
37* Robust algorithms for snapping and simplifying geometry (with accuracy and
38 topology guarantees).
39
40* A collection of efficient yet exact mathematical predicates for testing
41 relationships among geometric objects.
42
43* Support for spatial indexing, including the ability to approximate regions
44 as collections of discrete "S2 cells". This feature makes it easy to build
45 large distributed spatial indexes.
46
47On the other hand, the following are outside the scope of S2:
48
49* Planar geometry.
50
51* Conversions to/from common GIS formats.
52
53### Robustness
54
55What do we mean by "robust"?
56
57In the S2 library, the core operations are designed to be 100% robust. This
58means that each operation makes strict mathematical guarantees about its output,
59and is implemented in such a way that it meets those guarantees for all possible
60valid inputs. For example, if you compute the intersection of two polygons, not
61only is the output guaranteed to be topologically correct (up to the creation of
62degeneracies), but it is also guaranteed that the boundary of the output stays
63within a user-specified tolerance of true, mathematically exact result.
64
65Robustness is very important when building higher-level algorithms, since
66unexpected results from low-level operations can be very difficult to handle. S2
67achieves this goal using a combination of techniques from computational
68geometry, including *conservative error bounds*, *exact geometric predicates*,
69and *snap rounding*.
70
71The implementation attempts to be precise both in terms of mathematical
72definitions (e.g. whether regions include their boundaries, and how degeneracies
73are handled) and numerical accuracy (e.g. minimizing cancellation error).
74
75Note that the intent of this library is to represent geometry as a mathematical
76abstraction. For example, although the unit sphere is obviously a useful
77approximation for the Earth's surface, functions that are specifically related
78to geography are not part of the core library (e.g. easting/northing
79conversions, ellipsoid approximations, geodetic vs. geocentric coordinates,
80etc).
81
82See http://godoc.org/github.com/golang/geo for specific package documentation.
83
84For an analogous library in C++, see https://github.com/google/s2geometry, in
85Java, see https://github.com/google/s2-geometry-library-java, and Python, see
86https://github.com/google/s2geometry/tree/master/src/python
87
88# Status of the Go Library
89
90This library is principally a port of the
91[C++ S2 library](https://github.com/google/s2geometry), adapting to Go idioms
92where it makes sense. We detail the progress of this port below relative to that
93C++ library.
94
95Legend:
96
97* โ
- Feature Complete
98* ๐ก - Mostly Complete
99* โ - Not available
100
101## [โยน](https://godoc.org/github.com/golang/geo/r1) - One-dimensional Cartesian coordinates
102
103C++ Type | Go
104:--------- | ---
105R1Interval | โ
106
107## [โยฒ](https://godoc.org/github.com/golang/geo/r2) - Two-dimensional Cartesian coordinates
108
109C++ Type | Go
110:------- | ---
111R2Point | โ
112R2Rect | โ
113
114## [โยณ](https://godoc.org/github.com/golang/geo/r3) - Three-dimensional Cartesian coordinates
115
116C++ Type | Go
117:------------ | ---
118R3Vector | โ
119R3ExactVector | โ
120Matrix3x3 | โ
121
122## [Sยน](https://godoc.org/github.com/golang/geo/s1) - Circular Geometry
123
124C++ Type | Go
125:----------- | ---
126S1Angle | โ
127S1ChordAngle | โ
128S1Interval | โ
129
130## [Sยฒ](https://godoc.org/github.com/golang/geo/s2) - Spherical Geometry
131
132### Basic Types
133
134C++ Type | Go
135:------------------- | ---
136S2Cap | โ
137S2Cell | โ
138S2CellId | โ
139S2CellIdVector | โ
140S2CellIndex | ๐ก
141S2CellUnion | โ
142S2Coords | โ
143S2DensityTree | โ
144S2DistanceTarget | โ
145S2EdgeVector | โ
146S2LatLng | โ
147S2LatLngRect | โ
148S2LaxLoop | ๐ก
149S2LaxPolygon | ๐ก
150S2LaxPolyline | ๐ก
151S2Loop | โ
152S2PaddedCell | โ
153S2Point | โ
154S2PointIndex | โ
155S2PointSpan | โ
156S2PointRegion | โ
157S2PointVector | โ
158S2Polygon | ๐ก
159S2Polyline | โ
160S2R2Rect | โ
161S2Region | โ
162S2RegionCoverer | โ
163S2RegionIntersection | โ
164S2RegionUnion | โ
165S2Shape | โ
166S2ShapeIndex | โ
167S2ShapeIndexRegion | โ
168EncodedLaxPolygon | โ
169EncodedLaxPolyline | โ
170EncodedShapeIndex | โ
171EncodedStringVector | โ
172EncodedUintVector | โ
173IdSetLexicon | โ
174ValueSetLexicon | โ
175SequenceLexicon | โ
176LaxClosedPolyline | โ
177VertexIDLaxLoop | โ
178
179### Query Types
180
181C++ Type | Go
182:------------------- | ---
183S2ChainInterpolation | โ
184S2ClosestCell | โ
185S2FurthestCell | โ
186S2ClosestEdge | โ
187S2FurthestEdge | โ
188S2ClosestPoint | โ
189S2FurthestPoint | โ
190S2ContainsPoint | โ
191S2ContainsVertex | โ
192S2ConvexHull | โ
193S2CrossingEdge | โ
194S2HausdorffDistance | โ
195S2ShapeNesting | โ
196
197### Supporting Types
198
199C++ Type | Go
200:------------------------------- | ---
201S2BooleanOperation | โ
202S2BufferOperation | โ
203S2Builder | โ
204S2BuilderClosedSetNormalizer | โ
205S2BuilderFindPolygonDegeneracies | โ
206S2BuilderGraph | โ
207S2BuilderLayers | โ
208S2BuilderSnapFunctions | โ
209S2BuilderTesting | โ
210S2Builderutil\* | โ
211S2Coder | โ
212S2EdgeClipping | โ
213S2EdgeCrosser | โ
214S2EdgeCrossings | โ
215S2EdgeDistances | โ
216S2EdgeTessellator | โ
217S2LoopMeasures | โ
218S2Measures | โ
219S2MemoryTracker | โ
220S2Metrics | โ
221S2PointUtil | ๐ก
222S2PolygonBuilder | โ
223S2PolylineAlignment | โ
224S2PolylineMeasures | โ
225S2PolylineSimplifier | โ
226S2Predicates | โ
227S2Projections | โ
228S2rectBounder | โ
229S2RegionTermIndexer | โ
230S2ShapeIndexMeasures | โ
231S2ShapeIndexUtil\* | ๐ก
232S2ShapeMeasures | โ
233S2ShapeUtil\* | ๐ก
234S2Stats | โ
235S2Testing | โ
236S2TextFormat | โ
237S2WedgeRelations | โ
238S2WindingOperation | โ
239
240### Encode/Decode
241
242Encoding and decoding of S2 types is fully implemented and interoperable with
243C++ and Java.
View as plain text